Giter Club home page Giter Club logo

roscpp_code_format's Introduction

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 as its only been tested by Dave Coleman

Setup

  • Install clang_format:

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

  • Then put 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

  • 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

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,hpp files in catkin_ws/ and reverts buffer."
  (interactive)
  (and
   (string-match "/catkin_ws/.*\\.\\(h\\|cpp\\)$" buffer-file-name)
   (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] 'maybe-run-ros-clang-format)

Atom

Install the clang-format package via 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.

roscpp_code_format's People

Contributors

bennyre avatar davetcoleman avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.