@@ -146,7 +146,7 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding."
146146 (lambda (byte &optional _quality _coding-system )
147147 (byte-to-position (1+ byte)))))
148148
149- (defun clang-format--git-diffs -match-diff-line (line )
149+ (defun clang-format--vc-diff -match-diff-line (line )
150150 ; ; Matching something like:
151151 ; ; "@@ -80 +80 @@" or "@@ -80,2 +80,2 @@"
152152 ; ; Return as "<LineStart>:<LineEnd>"
@@ -160,7 +160,7 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding."
160160 (string-to-number (match-string 3 line)))))
161161 (concat (match-string 1 line) " :" (match-string 1 line)))))
162162
163- (defun clang-format--git-diffs -get-diff-lines (file-orig file-new )
163+ (defun clang-format--vc-diff -get-diff-lines (file-orig file-new )
164164 " Return all line regions that contain diffs between FILE-ORIG and
165165FILE-NEW. If there is no diff 'nil' is returned. Otherwise the
166166return is a 'list' of lines in the format '--lines=<start>:<end>'
@@ -194,7 +194,7 @@ which can be passed directly to 'clang-format'"
194194 ; ; lines in current buffer that have a diff.
195195 (goto-char (point-min ))
196196 (while (not (eobp ))
197- (let ((diff-line (clang-format--git-diffs -match-diff-line
197+ (let ((diff-line (clang-format--vc-diff -match-diff-line
198198 (buffer-substring-no-properties
199199 (line-beginning-position )
200200 (line-end-position )))))
@@ -208,14 +208,15 @@ which can be passed directly to 'clang-format'"
208208 (t
209209 (error " (diff returned unsuccessfully %s%s ) " status stderr))))))
210210
211- (defun clang-format--git-diffs-get-git-head-file (tmpfile-git-head )
212- " Returns a temporary file with the content of 'buffer-file-name' at
213- git revision HEAD. If the current buffer is either not a file or not
214- in a git repo, this results in an error"
211+ (defun clang-format--vc-diff-get-vc-head-file (tmpfile-vc-head )
212+ " Stores the contents of 'buffer-file-name' at vc revision HEAD into
213+ 'tmpfile-vc-head'. If the current buffer is either not a file or not
214+ in a vc repo, this results in an error. Currently git is the only
215+ supported vc."
215216 ; ; Needs current buffer to be a file
216217 (unless (buffer-file-name )
217218 (error " Buffer is not visiting a file " ))
218- ; ; Need version control to in fact be git
219+ ; ; Only version control currently supported is Git
219220 (unless (string-equal (vc-backend (buffer-file-name )) " Git" )
220221 (error " Not using git " ))
221222
@@ -226,31 +227,31 @@ in a git repo, this results in an error"
226227
227228
228229 ; ; Get filename relative to git root
229- (let ((git -file-name (substring
230+ (let ((vc -file-name (substring
230231 (expand-file-name (buffer-file-name ))
231232 (string-width (expand-file-name base-dir))
232233 nil )))
233234 (let ((status (call-process
234235 " git"
235236 nil
236- `(:file , tmpfile-git -head)
237+ `(:file , tmpfile-vc -head)
237238 nil
238- " show" (concat " HEAD:" git -file-name)))
239+ " show" (concat " HEAD:" vc -file-name)))
239240 (stderr (with-temp-buffer
240- (unless (zerop (cadr (insert-file-contents tmpfile-git -head)))
241+ (unless (zerop (cadr (insert-file-contents tmpfile-vc -head)))
241242 (insert " : " ))
242243 (buffer-substring-no-properties
243244 (point-min ) (line-end-position )))))
244245 (when (stringp status)
245246 (error " (git show HEAD:%s killed by signal %s%s ) "
246- git -file-name status stderr))
247+ vc -file-name status stderr))
247248 (unless (zerop status)
248249 (error " (git show HEAD:%s returned unsuccessfully %s%s ) "
249- git -file-name status stderr))))))
250+ vc -file-name status stderr))))))
250251
251252(defun clang-format--region-impl (start end &optional style assume-file-name lines )
252253 " Common implementation for 'clang-format-buffer',
253- 'clang-format-region', and 'clang-format-git-diffs '. START and END
254+ 'clang-format-region', and 'clang-format-vc-diff '. START and END
254255refer to the region to be formatter. STYLE and ASSUME-FILE-NAME are
255256used for configuring the clang-format. And LINES is used to pass
256257specific locations for reformatting (i.e diff locations)."
@@ -321,30 +322,30 @@ specific locations for reformatting (i.e diff locations)."
321322
322323
323324;;;### autoload
324- (defun clang-format-git-diffs (&optional style assume-file-name )
325- " The same as 'clang-format-buffer' but only operates on the git
325+ (defun clang-format-vc-diff (&optional style assume-file-name )
326+ " The same as 'clang-format-buffer' but only operates on the vc
326327diffs from HEAD in the buffer. If no STYLE is given uses
327328`clang-format-style' . Use ASSUME-FILE-NAME to locate a style config
328329file. If no ASSUME-FILE-NAME is given uses the function
329330`buffer-file-name' ."
330331 (interactive )
331- (let ((tmpfile-git -head nil )
332+ (let ((tmpfile-vc -head nil )
332333 (tmpfile-curbuf nil ))
333334 (unwind-protect
334335 (progn
335- (setq tmpfile-git -head
336- (make-temp-file " clang-format-git -tmp-head-content" ))
337- (clang-format--git-diffs -get-git -head-file tmpfile-git -head)
336+ (setq tmpfile-vc -head
337+ (make-temp-file " clang-format-vc -tmp-head-content" ))
338+ (clang-format--vc-diff -get-vc -head-file tmpfile-vc -head)
338339 ; ; Move current buffer to a temporary file to take a
339340 ; ; diff. Even if current-buffer is backed by a file, we
340341 ; ; want to diff the buffer contents which might not be
341342 ; ; saved.
342- (setq tmpfile-curbuf (make-temp-file " clang-format-git -tmp" ))
343+ (setq tmpfile-curbuf (make-temp-file " clang-format-vc -tmp" ))
343344 (write-region nil nil tmpfile-curbuf nil 'nomessage )
344- ; ; Git list of lines with a diff.
345+ ; ; Get list of lines with a diff.
345346 (let ((diff-lines
346- (clang-format--git-diffs -get-diff-lines
347- tmpfile-git -head tmpfile-curbuf)))
347+ (clang-format--vc-diff -get-diff-lines
348+ tmpfile-vc -head tmpfile-curbuf)))
348349 ; ; If we have any diffs, format them.
349350 (when diff-lines
350351 (clang-format--region-impl
@@ -355,7 +356,7 @@ file. If no ASSUME-FILE-NAME is given uses the function
355356 diff-lines))))
356357 (progn
357358 ; ; Cleanup temporary files
358- (when tmpfile-git -head (delete-file tmpfile-git -head))
359+ (when tmpfile-vc -head (delete-file tmpfile-vc -head))
359360 (when tmpfile-curbuf (delete-file tmpfile-curbuf))))))
360361
361362
0 commit comments