[PATCH] D37903: Fix assume-filename handling in clang-format.el
Micah Werbitt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 25 14:00:03 PDT 2017
werbitt updated this revision to Diff 116605.
werbitt added a comment.
Cleanup Docs
- The first line of of an emacs docstring should be a complete sentence.
-Specify that "-assume-filname" is a clang-format option
https://reviews.llvm.org/D37903
Files:
tools/clang-format/clang-format.el
Index: tools/clang-format/clang-format.el
===================================================================
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -119,12 +119,10 @@
(byte-to-position (1+ byte)))))
;;;###autoload
-(defun clang-format-region (start end &optional style assume-file-name)
- "Use clang-format to format the code between START and END according to STYLE
-using ASSUME-FILE-NAME to locate a style config file. If called interactively
-uses the region or the current statement if there is no active region. If no
-style is given uses `clang-format-style'. If no assume-file-name is given uses
-`buffer-file-name'."
+(defun clang-format-region (start end &optional style)
+ "Use clang-format to format the code between START and END according to STYLE.
+If called interactively uses the region or the current statement if there
+is no active region. If no style is given uses `clang-format-style'."
(interactive
(if (use-region-p)
(list (region-beginning) (region-end))
@@ -133,9 +131,6 @@
(unless style
(setq style clang-format-style))
- (unless assume-file-name
- (setq assume-file-name buffer-file-name))
-
(let ((file-start (clang-format--bufferpos-to-filepos start 'approximate
'utf-8-unix))
(file-end (clang-format--bufferpos-to-filepos end 'approximate
@@ -149,20 +144,16 @@
;; always use ‘utf-8-unix’ and ignore the buffer coding system.
(default-process-coding-system '(utf-8-unix . utf-8-unix)))
(unwind-protect
- (let ((status (apply #'call-process-region
- nil nil clang-format-executable
- nil `(,temp-buffer ,temp-file) nil
- `("-output-replacements-xml"
- ;; Gaurd against a nil assume-file-name.
- ;; If -assume-filename is given a blank string
- ;; it will crash as per the following bug report
- ;; https://bugs.llvm.org/show_bug.cgi?id=34667
- ,@(and assume-file-name
- (list "-assume-filename" assume-file-name))
- "-style" ,style
- "-offset" ,(number-to-string file-start)
- "-length" ,(number-to-string (- file-end file-start))
- "-cursor" ,(number-to-string cursor))))
+ (let ((status (call-process-region
+ nil nil clang-format-executable
+ nil `(,temp-buffer ,temp-file) nil
+
+ "-output-replacements-xml"
+ "-assume-filename" (or (buffer-file-name) "")
+ "-style" style
+ "-offset" (number-to-string file-start)
+ "-length" (number-to-string (- file-end file-start))
+ "-cursor" (number-to-string cursor)))
(stderr (with-temp-buffer
(unless (zerop (cadr (insert-file-contents temp-file)))
(insert ": "))
@@ -190,12 +181,10 @@
(when (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
;;;###autoload
-(defun clang-format-buffer (&optional style assume-file-name)
- "Use clang-format to format the current buffer according to STYLE using
-ASSUME-FILE-NAME to locate a style config file. If no style is given uses
-`clang-format-style'. If no assume-file-name is given uses `buffer-file-name'."
+(defun clang-format-buffer (&optional style)
+ "Use clang-format to format the current buffer according to STYLE."
(interactive)
- (clang-format-region (point-min) (point-max) style assume-file-name))
+ (clang-format-region (point-min) (point-max) style))
;;;###autoload
(defalias 'clang-format 'clang-format-region)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37903.116605.patch
Type: text/x-patch
Size: 4000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170925/afe25f16/attachment.bin>
More information about the cfe-commits
mailing list