@@ -160,9 +160,9 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding."
160160
161161(defun clang-format--vc-diff-get-diff-lines (file-orig file-new )
162162 " Return all line regions that contain diffs between FILE-ORIG and
163- FILE-NEW. If there is no diff ‘nil’ is returned. Otherwise the
164- return is a ‘list’ of lines in the format ‘--lines=<start>:<end>’
165- which can be passed directly to ‘clang-format’. "
163+ FILE-NEW. If there is no diff ‘nil’ is returned. Otherwise the return
164+ is a ‘list’ of line ranges to format. The list of line ranges can be
165+ passed to ‘clang-format--region-impl’ "
166166 ; ; Use temporary buffer for output of diff.
167167 (with-temp-buffer
168168 ; ; We could use diff.el:diff-no-select here. The reason we don't
@@ -186,7 +186,7 @@ which can be passed directly to ‘clang-format’."
186186 (diff-lines '()))
187187 (cond
188188 ((stringp status)
189- (error " (diff killed by signal %s%s ) " status stderr))
189+ (error " clang-format: (diff killed by signal %s%s )" status stderr))
190190 ; ; Return of 0 indicates no diff.
191191 ((= status 0 ) nil )
192192 ; ; Return of 1 indicates found diffs and no error.
@@ -205,15 +205,11 @@ which can be passed directly to ‘clang-format’."
205205 (if match3_or_nil
206206 (string-to-number match3_or_nil)
207207 nil ))))
208- (push (format
209- " --lines=%d:%d"
210- match1
211- (if match3 (+ match1 match3) match1))
212- diff-lines)))
208+ (push (cons match1 (if match3 (+ match1 match3) match1)) diff-lines)))
213209 (nreverse diff-lines))
214210 ; ; Any return != 0 && != 1 indicates some level of error.
215211 (t
216- (error " (diff returned unsuccessfully %s%s ) " status stderr))))))
212+ (error " clang-format: (diff returned unsuccessfully %s%s )" status stderr))))))
217213
218214(defun clang-format--vc-diff-get-vc-head-file (tmpfile-vc-head )
219215 " Stores the contents of ‘buffer-file-name’ at vc revision HEAD into
@@ -222,13 +218,13 @@ in a vc repo, this results in an error. Currently git is the only
222218supported vc."
223219 ; ; We need the current buffer to be a file.
224220 (unless (buffer-file-name )
225- (error " Buffer is not visiting a file " ))
221+ (error " clang-format: Buffer is not visiting a file" ))
226222
227223 (let ((base-dir (vc-root-dir ))
228224 (backend (vc-backend (buffer-file-name ))))
229225 ; ; We need to be able to find version control (git) root.
230226 (unless base-dir
231- (error " File not known to git " ))
227+ (error " clang-format: File not known to git" ))
232228 (cond
233229 ((string-equal backend " Git" )
234230 ; ; Get the filename relative to git root.
@@ -248,10 +244,10 @@ supported vc."
248244 (buffer-substring-no-properties
249245 (point-min ) (line-end-position )))))
250246 (when (stringp status)
251- (error " (git show HEAD:%s killed by signal %s%s ) "
247+ (error " clang-format: (git show HEAD:%s killed by signal %s%s )"
252248 vc-file-name status stderr))
253249 (unless (zerop status)
254- (error " (git show HEAD:%s returned unsuccessfully %s%s ) "
250+ (error " clang-format: (git show HEAD:%s returned unsuccessfully %s%s )"
255251 vc-file-name status stderr)))))
256252 (t
257253 (error
@@ -271,6 +267,12 @@ specific locations for reformatting (i.e diff locations)."
271267 (unless assume-file-name
272268 (setq assume-file-name (buffer-file-name (buffer-base-buffer ))))
273269
270+ ; ; Convert list of line ranges to list command for ‘clang-format’ executable.
271+ (when lines
272+ (setq lines (mapcar (lambda (range )
273+ (format " --lines=%d :%d " (car range) (cdr range)))
274+ lines)))
275+
274276 (let ((file-start (clang-format--bufferpos-to-filepos start 'approximate
275277 'utf-8-unix ))
276278 (file-end (clang-format--bufferpos-to-filepos end 'approximate
@@ -327,7 +329,9 @@ specific locations for reformatting (i.e diff locations)."
327329 (if incomplete-format
328330 (message " (clang-format: incomplete (syntax errors)%s ) " stderr)
329331 (message " (clang-format: success%s ) " stderr))))
330- (ignore-errors (delete-file temp-file))
332+ (with-demoted-errors
333+ " clang-format: Failed to delete temporary file: %S"
334+ (delete-file temp-file))
331335 (when (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
332336
333337
0 commit comments