Skip to content

mayfieldrobotics/roscpp_code_format

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

Mayfield roscpp Clang Format

This fork contains Mayfield-specific changes to the ROS clang-format file. Changes are:

  • Short functions are formatted to a single line.
  • Tab and indent widths are set to 4
  • Braces do not break after control statements or exception statements

The easiest way to use this is to check the repo out somewhere, then symlink the .clang-format file to the top level of the repo you want to use it in.

The contents of the original readme are below.

roscpp Code Format

Why waste your valuable development time formatting code manually when we are trying to build amazing robots?

The repo contains an auto formatting script for the ROS C++ Style Guidelines.

Note: this style is in beta format, please submit suggestions or fixes!

Setup

  • Install clang_format:

    sudo apt-get install -y clang-format-3.6

  • Then symlink or copy in the root of your catkin workspace the file .clang-format, located in this repo. You can save this file from this link. For example, place it on your computer here:

    ~/catkin_ws/.clang-format

  • If you are interested in improving this configuration file, we recommend you checkout the git repo and symlink, e.g.:

    ln -s ~/roscpp_code_format/.clang-format ~/catkin_ws/.clang-format

  • Now any file inside your catkin workspace will be formatted with the ROS style guidelines described in this config file

Usage

You can run clang_format in several ways:

Command Line

Format single file:

clang-format-3.6 -i -style=file MY_ROS_NODE.cpp

Format entire directory recursively including subfolders:

find . -name '*.h' -or -name '*.hpp' -or -name '*.cpp' | xargs clang-format-3.6 -i -style=file $1

Emacs Editor Configuration

In your ~/.emacs config file, add the following:

Format your source code if its in some directory such as the catkin_ws (feel free to change keywords catkin_ws):

(defun run-ros-clang-format ()
  "Runs clang-format on cpp,h files in catkin_ws/ and reverts buffer."
  (interactive)
  (and
   (string-match "/catkin_ws/.*\\.\\(h\\|cpp\\)$" buffer-file-name)
   (save-some-buffers 'no-confirm)
   (shell-command (concat "clang-format-3.6 -style=file -i " buffer-file-name))
   (message (concat "Saved and ran clang-format on " buffer-file-name))
   (revert-buffer t t t)
))

Set a keyboard shortcut to run, such as F12

(global-set-key [f12] 'run-ros-clang-format)

Atom Editor Configuration

Install the clang-format package via the Atom package manager or apm install clang-format.

In the package settings set clang-format-3.6 as your executable and point 'Style' to your .clang_format file.

About

Auto formatting script for ROS C++ Style Guidelines

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published