Install atom on your workstation

  • Ubuntu:
sudo add-apt-repository ppa:webupd8team/atom && sudo apt update && sudo apt install atom
  • Archlinux: needs to be compiled from source (AUR)
yaourt -S atom-editor-bin ()

Atom recommanded packages for C++/CMake/Git

Here are the package that are really useful when using atom for PID.

  • atom-beautify: Code formatting
  • autocomplete-clang: Code completion (C++)
  • autocomplete-cmake: Code completion (cmake)
  • build: Base package for other build- packages (F7: select target, F8: show output, F9: run target)
  • build-cmake: Build code based cmake
  • build-make: Build code based on makefiles
  • busy: Needed by some packages
  • git-plus: Do git things within Atom
  • git-time-machine: Make a diff between commits
  • highlight-selected: Highlight every occurrence of the current selection
  • language-cmake: Support for cmake (syntax definition)
  • linter: Base package for other linter- packages
  • linter-clang: C++ linter (shows errors/warnings in the code)
  • local-settings: Allow a local setting file to override the global one
  • platformio-ide-terminal: A terminal inside Atom
  • project-manager: To quickly switch between projects
  • split-diff: Diff files
  • todo-show: List all the TODOs mentionned in the comments
  • Install them all:

Simply install them:

apm install atom-beautify autocomplete-clang autocomplete-cmake build build-cmake build-make busy git-plus git-time-machine highlight-selected language-cmake linter linter-clang local-settings platformio-ide-terminal project-manager split-diff todo-show

Start atom for first time

When first started, atom will probably ask you to install dependencies for the packages you installed with previous command. Or it ùay ask you to update some of these packages.

Simply answer YES to these operations.

Configuration of atom

C++ snippets

Copy the following content into snippets (into Menu bar > Edit > snippets):

'.source.cpp':
  'For Loop - pre inc':
    'prefix': 'for'
    'body': 'for (size_t ${1:i} = 0; ${1:i} < ${2:count}; ${3:++}${1:i}) {\n\t${4:/* code */}\n}'

  'C++ Class':
    'prefix': 'class'
    'body': 'class $1 {\npublic:\n\t$1();\n\t~$1();\n};'

  'C++ Child Class':
    'prefix': 'child-class'
    'body': 'class $1 : public $2 {\npublic:\n\t$1();\n\t~$1();\n};'

  'const string reference':
    'prefix': 'cstring'
    'body': 'const std::string& $1'

  'Knowbotics World::enable()':
    'prefix': 'kb-world-enable'
    'body': """
  	try {
  		World::enable();
  	}
  	catch (kbot::PropertyLogicError& e) {
  		cout << e.what() << endl;
  		$1
  		exit(0);
  	}
    """

  'Deallocate pointer':
    'prefix': 'del_ptr'
    'body': """
  if($1 != nullptr) {
    delete $1;
    $1 = nullptr;
  }
  """

  'static_cast':
    'prefix': 'scast'
    'body': 'static_cast<$1>($2)'

  'dynamic_cast':
    'prefix': 'dcast'
    'body': 'dyanamic_cast<$1>($2)'

  'Header guards':
    'prefix': 'guards'
    'body': """
    #ifndef $1
    #define $1

    #endif /* $1 */
    """

  'Knowbotics processor header':
    'prefix': 'kb-processor-header'
    'body': """
    #ifndef $1
    #define $1

    #include <kbot/base.h>

    namespace kbot {

    class $2 : public $3 {
      DEF_KNOWLEDGE($2, $3)
    public:
      $2();
      ~$2();

    private:

    };

    }

    #endif /* $1 */
    """

  'Knowbotics processor source':
    'prefix': 'kb-processor-source'
    'body': """
    #include $1

    using namespace kbot;

    $2::$2() {

    }

    $2::~$2() {

    }

    """

C++ beautifying

This is used for C++ formatting.

  • Save the following content somewhere in to a file (call it uncrustify.cfg) and copy the path to this file.
 # Uncrustify 0.64

 #
 # General options
 #

 # The type of line endings
 newlines                                 = auto     # auto/lf/crlf/cr

 input_tab_size                           = 4        # number
 output_tab_size                          = 4        # number
 indent_columns                           = 4        # number

 indent_class                             = true     # false/true
 indent_class_colon                       = true     # false/true

 sp_angle_shift                           = ignore      # ignore/add/remove/force
 sp_permit_cpp11_shift                    = true
  • Configure the atom beautify package to use this configuration

Go to Edit > Preferences > Packages, search for atom beautify package and then click on settings button.

In the C and C++ sections, select Uncrustify as beautifier then paste the path to uncrustify.cfg you just save in the field Config Path.

Configure CMake based build

Go to Edit > Preferences > Packages, search for build-cmake package and then click on settings button.

In the field build location paste the text: $PROJECT_DIR/build

Unselect the parallel build option

Configure the clang linter

In order for the linter (autocompletion and fast error detection) to work you need to install clang.

sudo apt install clang

Enable PID plugins for atom

Some atom packages sometimes require additional user information to work, this is the case of the clang based linter.

Hopefully PID may be shipped with plugins that may be used to do the job.

PID plugins for atom: * atom_clang_complete, generates configuration files for the atom linter. This is really important plugin to have a good experience when using atom with PID !

To install a plugin:

cd <pid-workspace>/pid
ccmake ..
#put the option "PLUGIN_atom_clang_complete" to ON
# then type 'c' and then 'g'

That’s it the plugin will be used for any of the source packages contained in the workspace. Now the clang based linter is usable withing atom without more effort, PID generates all required configuration for you