Search code examples
c++header-filesatom-editorauto-generateinclude-guards

generate c++ include header guards in atom?


I'm looking for an atom package that generates C++ include guards in .h/.hpp header files. The package should do something like taking an existing C++ header file and surround its contents with appropriate #ifndef #define #endif lines.

If the plugin offers some additional features, like auto-generating cpp and h files from a given class name, that would be great, too.

I'm suprised I couldn't find a sensible plugin by googling for it. Are there any plugins around that match this description?

Note: This is not a question seeking for opinions (/out-of-topic), but for material to base my further research for such a plugin on.


Solution

  • Create a snippet insted! Opent your .atom folders and in the snippets.cson file paste this snippet!:

    '.source.js':
      'guards':
        'prefix': 'hd'
        'body': '#ifndef "${1:*}"\n#define "${1:*}"\n${2}\n#endif'
      'console.error':
        'prefix': 'error'
        'body': 'console.error(${1:"crash"});$2'
    

    You will then type hd, press tab and start creating a safe header ;) You can change the prefix anytime by editing the snippet