diff options
author | Daniel Jasper <djasper@google.com> | 2013-04-12 10:12:01 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-04-12 10:12:01 +0000 |
commit | c6d82ca9b28c39a988afd06a6359e09df033b846 (patch) | |
tree | a794ba27f78340bd8faa27f23338e8ebe5f9b179 /tools | |
parent | 6026df1e5d518a958aef342d55a9e5d0fbdb85ca (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@179372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/clang-format/clang-format.el | 46 |
1 files changed, 13 insertions, 33 deletions
diff --git a/tools/clang-format/clang-format.el b/tools/clang-format/clang-format.el index c63c62ee55..1277885996 100644 --- a/tools/clang-format/clang-format.el +++ b/tools/clang-format/clang-format.el @@ -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))) |