Atom editor and C++

With recent update of the Atom editor from GitHub, developing C++ application just started to be more pleasant. Enhancing the editor with packages which use clang tools enables features for easy and quick program writing, good for creating proof of concept applications.

Installation

On homepage for Atom, atom.io, there are precompiled packages to download as well as the source code. I use Linux Mint, which is based on Ubuntu and uses apt package manager, so below instructions add an apt source for easy updates.

Add atom ppa repository

sudo add-apt-repository ppa:webupd8team/atom

Update apt package db and install atom

sudo apt update && sudo apt install atom

Enhancing Atom with packages

Installing packages is very easy in Atom. For C++ development I use packages which use clang and clang tools, those need to be installed separately, check apt source for clang.

List of packages

autocomplete-clang
autocomplete-cmake
autocomplete-python
autocomplete-xml
hightlight-line
highlight-selected
language-cmake
language-cpp14
linter-clang
switch-header-source
terminal-plus

The autocomplete packages are very helpful when using STL components. Linter helps quickly discover mistakes, potential bugs when typing.

I use CMake to generate the appropriate build files, so that I can just type ‘make’ and rebuild the application. Autocomplete for cmake helps a lot when adding new instructions, which sometimes are long.

Snippets

For quicker program writing, I like to use snippets. I added two for now to help me quickly setup a new program folder. One with main function and one with CMake instructions.

Adding new snippets is easy. Edit -> Snippets…

'.source.cmake':
    'Minimum CMake File':
        'prefix': 'cmake'
        'body': '''
            cmake_minimum_required(VERSION 2.8.12)
            project(main)
            set(CMAKE_CXX_STANDARD 11)
            file(GLOB SRC *.cpp)
            add_executable(main ${SRC})
        '''

'.source.cpp':
    'Minimal C++ program':
        'prefix': 'cmin'
        'body': '''
            #include <iostream>

            using namespace std;

            int main(int argc, char *argv[])
            {
                $1

                return 0;
            }

        '''

To use above snippets simply type ‘cmin’ in a C++ file for the minimal C++ program and ‘cmake’ in CMakeLists.txt for minimal CMake instructions set needed to compile the project.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s