Spacemacs for ns-3 development

This blog post details my Spacemacs setup for editing ns-3 projects.


For both autocompletion and syntax checking I use rtags.

To let rtags know of the compile_commands.json compilation database, symlink it:

cd /path/to/ns-3
ln -s build/compile_commands.json compile_commands.json

Style check on file save

Automatically apply ns-3's style check script upon save.

(defun ns-3-format ()
    "Format current buffer according to ns-3 standards"
    (set 'scriptpath "/path/to/ns-3/utils/")
    (concat scriptpath " -i -f " (buffer-file-name)))
    (revert-buffer nil t)

To use the function, a customization of the project's .dir-locals.el is needed:

((nil. ())
    (c++-mode (eval add-hook 'after-save-hook #'ns-3-format nil t)))

Default compilation and testing commands

Default project compilation and testing commands can also be specified in the dir-locals.el file:

((nil . ((projectile-project-compilation-cmd . "./waf build")
        (projectile-project-test-cmd . "./ -s lorawan") )))