================ @@ -146,18 +146,104 @@ is a zero-based file offset, assuming ‘utf-8-unix’ coding." (lambda (byte &optional _quality _coding-system) (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. -If called interactively uses the region or the current statement if there is no -no active region. If no STYLE is given uses `clang-format-style'. Use -ASSUME-FILE-NAME to locate a style config file, if no ASSUME-FILE-NAME is given -uses the function `buffer-file-name'." - (interactive - (if (use-region-p) - (list (region-beginning) (region-end)) - (list (point) (point)))) +(defun clang-format--vc-diff-get-diff-lines (file-orig file-new) + "Return all line regions that contain diffs between FILE-ORIG and +FILE-NEW. If there is no diff ‘nil’ is returned. Otherwise the +return is a ‘list’ of lines in the format ‘--lines=<start>:<end>’ +which can be passed directly to ‘clang-format’." + ;; Use temporary buffer for output of diff. + (with-temp-buffer + ;; We could use diff.el:diff-no-select here. The reason we don't + ;; is diff-no-select requires extra copies on the buffers which + ;; induces noticeable slowdowns, especially on larger files. + (let ((status (call-process + diff-command + nil + (current-buffer) + nil + ;; Binary diff has different behaviors that we + ;; aren't interested in. + "-a" + ;; Print new lines in file-new formatted as + ;; "--lines=<StartDiff:EndDiff> " + "--changed-group-format=%(N=0?:--lines=%dF:%dM )" + ;; Don't print anything for unchanged lines + "--unchanged-group-format=" ---------------- lukel97 wrote:
Hey sorry for the delay, I'm not very well versed in elisp unfortunately. But this looks really useful and I would definitely use it. I tried this out locally though on macOS and it looks like BSD diff doesn't have `--unchanged-group-format`. Is this needed for the rest of it to work? This isn't a blocking comment btw, we can always tell people to just install diffutils. https://github.com/llvm/llvm-project/pull/112792 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits