[clang] [emacs][clang-format] Add elisp API for clang-format on git diffs (PR #112792)

via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 17 19:01:43 PST 2024


================
@@ -206,20 +191,30 @@ which can be passed directly to ‘clang-format’."
        ((= status 0) nil)
        ;; Return of 1 indicates found diffs and no error.
        ((= status 1)
-        ;; Iterate through all lines in diff buffer and collect all
-        ;; lines in current buffer that have a diff.
-        (goto-char (point-min))
-        (while (not (eobp))
-          (let ((diff-line (clang-format--vc-diff-match-diff-line
-                            (buffer-substring-no-properties
-                             (line-beginning-position)
-                             (line-end-position)))))
-            (when diff-line
-              ;; Create list line regions with diffs to pass to
-              ;; clang-format.
-              (push (concat "--lines=" diff-line) diff-lines)))
-          (forward-line 1))
-        (reverse diff-lines))
+        ;; Find and collect all diff lines.
+        ;; We are matching something like:
+        ;; "@@ -80 +80 @@" or "@@ -80,2 +80,2 @@"
+        (let ((diff-lines-re
+               "^@@\s-[0-9,]+\s\\+\\([0-9]+\\)\\(,\\([0-9]+\\)\\)?\s@@$")
+              (index 0)
+              (all-lines
+               (buffer-substring-no-properties (point-min) (point-max))))
----------------
goldsteinn wrote:

Fixed

https://github.com/llvm/llvm-project/pull/112792


More information about the cfe-commits mailing list