r179372 - Provide better emacs integration.
Daniel Jasper
djasper at google.com
Fri Apr 12 03:12:01 PDT 2013
Author: djasper
Date: Fri Apr 12 05:12:01 2013
New Revision: 179372
URL: http://llvm.org/viewvc/llvm-project?rev=179372&view=rev
Log:
Provide better emacs integration.
The new emacs integration is simpler, does not save the current file
before reformatting and ensures that emacs does not scroll as a result
of formatting.
Also explicitly set the style in clang-format tests to make them more
robust.
Modified:
cfe/trunk/test/Format/basic.cpp
cfe/trunk/test/Format/ranges.cpp
cfe/trunk/tools/clang-format/clang-format.el
Modified: cfe/trunk/test/Format/basic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/basic.cpp?rev=179372&r1=179371&r2=179372&view=diff
==============================================================================
--- cfe/trunk/test/Format/basic.cpp (original)
+++ cfe/trunk/test/Format/basic.cpp Fri Apr 12 05:12:01 2013
@@ -1,5 +1,5 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-format -i %t.cpp
+// RUN: clang-format -style=LLVM -i %t.cpp
// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
// CHECK: {{^int\ \*i;}}
Modified: cfe/trunk/test/Format/ranges.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Format/ranges.cpp?rev=179372&r1=179371&r2=179372&view=diff
==============================================================================
--- cfe/trunk/test/Format/ranges.cpp (original)
+++ cfe/trunk/test/Format/ranges.cpp Fri Apr 12 05:12:01 2013
@@ -1,5 +1,5 @@
// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-format -offset=2 -length=0 -offset=28 -length=0 -i %t.cpp
+// RUN: clang-format -style=LLVM -offset=2 -length=0 -offset=28 -length=0 -i %t.cpp
// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s
// CHECK: {{^int\ \*i;$}}
int*i;
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=179372&r1=179371&r2=179372&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format.el (original)
+++ cfe/trunk/tools/clang-format/clang-format.el Fri Apr 12 05:12:01 2013
@@ -10,38 +10,18 @@
;; 'style' and 'binary' below.
(defun clang-format-region ()
(interactive)
- (let ((orig-file buffer-file-name)
+ (let ((orig-window-start (window-start))
(orig-point (point))
- (orig-mark (mark t))
- (orig-mark-active mark-active)
(binary "clang-format")
- (style "LLVM")
- replacement-text replaced beg end)
- (basic-save-buffer)
- (save-restriction
- (widen)
- (if mark-active
- (setq beg (1- (region-beginning))
- end (1- (region-end)))
- (setq beg (1- (line-beginning-position))
- end (1- (line-end-position))))
- (with-temp-buffer
- (call-process
- binary orig-file '(t nil) t
- "-offset" (number-to-string beg)
- "-length" (number-to-string (- end beg))
- "-style" style)
- (setq replacement-text
- (buffer-substring-no-properties (point-min) (point-max))))
- (unless (string= replacement-text
- (buffer-substring-no-properties (point-min) (point-max)))
- (delete-region (point-min) (point-max))
- (insert replacement-text)
- (setq replaced t)))
- (ignore-errors
- (when orig-mark
- (push-mark orig-mark)
- (when orig-mark-active
- (activate-mark)
- (setq deactivate-mark nil)))
- (goto-char orig-point))))
+ (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)
+ "-length" (number-to-string (- end beg))
+ "-style" style)
+ (goto-char orig-point)
+ (set-window-start (selected-window) orig-window-start)))
More information about the cfe-commits
mailing list