Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions diff-hl.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,20 @@
(require 'vc-git)
(require 'vc-hg)
(require 'face-remap)
(declare-function project-buffers 'project)
(declare-function project-name 'project)
(declare-function project-roots 'project)
(require 'project)
(declare-function smartrep-define-key 'smartrep))

(defmacro static-if (condition then-form &rest else-forms) ; since Emacs 30.1
"A conditional compilation macro.
Evaluate CONDITION at macro-expansion time. If it is non-nil,
expand the macro to THEN-FORM. Otherwise expand it to ELSE-FORMS
enclosed in a `progn' form. ELSE-FORMS may be empty."
(declare (indent 2)
(debug (sexp sexp &rest sexp)))
(if (eval condition lexical-binding)
then-form
(cons 'progn else-forms)))

(defgroup diff-hl nil
"VC diff highlighting on the side of a window"
:group 'vc)
Expand Down Expand Up @@ -385,35 +394,37 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
(ignored 'diff-hl-bmp-i)
(t (intern (format "diff-hl-bmp-%s" type)))))

(defvar vc-svn-diff-switches)
(defvar vc-fossil-diff-switches)
(defvar vc-jj-diff-switches)

(defmacro diff-hl-with-diff-switches (body)
`(let ((vc-git-diff-switches
;; https://github.com/dgutov/diff-hl/issues/67
(cons "-U0"
;; https://github.com/dgutov/diff-hl/issues/9
(and (boundp 'vc-git-diff-switches)
(listp vc-git-diff-switches)
(cl-remove-if-not
(lambda (arg)
(member arg '("--histogram" "--patience" "--minimal" "--textconv")))
vc-git-diff-switches))))
(vc-hg-diff-switches nil)
(vc-svn-diff-switches nil)
(vc-fossil-diff-switches '("-c" "0"))
(vc-jj-diff-switches '("--git" "--context=0"))
(vc-diff-switches '("-U0"))
,@(when (boundp 'vc-disable-async-diff)
'((vc-disable-async-diff t))))
,body))
`(progn
(defvar vc-svn-diff-switches)
(defvar vc-fossil-diff-switches)
(defvar vc-jj-diff-switches)
(let ((vc-git-diff-switches
;; https://github.com/dgutov/diff-hl/issues/67
(cons "-U0"
;; https://github.com/dgutov/diff-hl/issues/9
(and (boundp 'vc-git-diff-switches)
(listp vc-git-diff-switches)
(cl-remove-if-not
(lambda (arg)
(member arg '("--histogram" "--patience" "--minimal" "--textconv")))
vc-git-diff-switches))))
(vc-hg-diff-switches nil)
(vc-svn-diff-switches nil)
(vc-fossil-diff-switches '("-c" "0"))
(vc-jj-diff-switches '("--git" "--context=0"))
(vc-diff-switches '("-U0"))
,@(when (boundp 'vc-disable-async-diff)
'((vc-disable-async-diff t))))
,body)))

(defun diff-hl-modified-p (state)
(or (memq state '(edited conflict))
(and (eq state 'up-to-date)
;; VC state is stale in after-revert-hook.
(or revert-buffer-in-progress-p
(or (static-if (>= emacs-major-version 31)
revert-buffer-in-progress
revert-buffer-in-progress-p)
;; Diffing against an older revision.
diff-hl-reference-revision))))

Expand Down Expand Up @@ -1666,9 +1677,9 @@ effect."

(defun diff-hl--project-root (proj)
;; Emacs 26 and 27 don't have `project-root'.
(expand-file-name
(or (and (fboundp 'project-root) (project-root proj))
(project-roots proj))))
(expand-file-name (static-if (>= emacs-major-version 28)
(project-root proj)
(project-roots proj))))

(defun diff-hl-set-reference-rev-in-project-internal (rev proj)
(let* ((root (diff-hl--project-root proj)))
Expand Down