r179676 - Small improvements to clang-format documentation and integration

Daniel Jasper djasper at google.com
Wed Apr 17 00:55:02 PDT 2013


Author: djasper
Date: Wed Apr 17 02:55:02 2013
New Revision: 179676

URL: http://llvm.org/viewvc/llvm-project?rev=179676&view=rev
Log:
Small improvements to clang-format documentation and integration
scripts.

Modified:
    cfe/trunk/docs/ClangFormat.rst
    cfe/trunk/tools/clang-format/clang-format-diff.py
    cfe/trunk/tools/clang-format/clang-format.el

Modified: cfe/trunk/docs/ClangFormat.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=179676&r1=179675&r2=179676&view=diff
==============================================================================
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Wed Apr 17 02:55:02 2013
@@ -18,7 +18,6 @@ to format C/C++/Obj-C code.
   $ clang-format --help
   OVERVIEW: A tool to format C/C++/Obj-C code.
 
-  Currently supports LLVM and Google style guides.
   If no arguments are specified, it formats the code from standard input
   and writes the result to the standard output.
   If <file> is given, it reformats the file. If -i is specified together
@@ -66,6 +65,22 @@ It operates on the current, potentially
 or save any files. To revert a formatting, just undo.
 
 
+Emacs Integration
+=================
+
+Similar to the integration for :program:`vim`, there is an integration for
+:program:`emacs`. It can be found at `clang/tools/clang-format/clang-format.el`
+and used by adding this to your `.emacs`:
+
+.. code-block:: common-lisp
+
+  (load "<path-to-clang>/tools/clang-format/clang-format.el")
+  (global-set-key [C-M-tab] 'clang-format-region)
+
+This binds the function `clang-format-region` to C-M-tab, which then formats the
+current line or selected region.
+
+
 Script for patch reformatting
 =============================
 
@@ -81,7 +96,7 @@ a unified diff and reformats all contain
   optional arguments:
     -h, --help    show this help message and exit
     -p P          strip the smallest prefix containing P slashes
-    -style STYLE  formatting style to apply (LLVM, Google)
+    -style STYLE  formatting style to apply (LLVM, Google, Chromium)
 
 So to reformat all the lines in the latest :program:`git` commit, just do:
 

Modified: cfe/trunk/tools/clang-format/clang-format-diff.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format-diff.py?rev=179676&r1=179675&r2=179676&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format-diff.py (original)
+++ cfe/trunk/tools/clang-format/clang-format-diff.py Wed Apr 17 02:55:02 2013
@@ -85,7 +85,8 @@ def main():
                                    'Reformat changed lines in diff')
   parser.add_argument('-p', default=1,
                       help='strip the smallest prefix containing P slashes')
-  parser.add_argument('-style', help='formatting style to apply (LLVM, Google)')
+  parser.add_argument('-style',
+                      help='formatting style to apply (LLVM, Google, Chromium)')
   args = parser.parse_args()
 
   filename = None

Modified: cfe/trunk/tools/clang-format/clang-format.el
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.el?rev=179676&r1=179675&r2=179676&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format.el (original)
+++ cfe/trunk/tools/clang-format/clang-format.el Wed Apr 17 02:55:02 2013
@@ -3,7 +3,7 @@
 ;; This defines a function clang-format-region that you can bind to a key.
 ;; A minimal .emacs would contain:
 ;;
-;;   (load "<path-to-clang>/tools/clang/clang-format/clang-format.el")
+;;   (load "<path-to-clang>/tools/clang-format/clang-format.el")
 ;;   (global-set-key [C-M-tab] 'clang-format-region)
 ;;
 ;; Depending on your configuration and coding style, you might need to modify
@@ -15,12 +15,12 @@
         (binary "clang-format")
         (style "LLVM"))
     (if mark-active
-        (setq beg (1- (region-beginning))
-              end (1- (region-end)))
-      (setq beg (1- (line-beginning-position))
-            end (1- (line-end-position))))
-    (call-process-region (point-min) (point-max) "clang-format" t t nil
-                         "-offset" (number-to-string beg)
+        (setq beg (region-beginning)
+              end (region-end))
+      (setq beg (line-beginning-position)
+            end (line-end-position)))
+    (call-process-region (point-min) (point-max) binary t t nil
+                         "-offset" (number-to-string (1- beg))
                          "-length" (number-to-string (- end beg))
                          "-style" style)
     (goto-char orig-point)





More information about the cfe-commits mailing list