branch: externals/diff-hl
commit 75dfbe8ccd3662cb63d8136424ba4fb76e4896b8
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
Fix compiler warnings about project symbols properly
It is not appropriate to declare that a function exists, when we
very well know that it does in fact not exist (anymore). That was
the approach taken in #254. If we revert that, we are back to:
diff-hl.el:1677:19: Warning: the function ‘project-buffers’ is not known
to be define
diff-hl.el:1668:9: Warning: the function ‘project-roots’ is not known to
be defined.
diff-hl.el:1654:17: Warning: the function ‘project-name’ is not known to
be defined.
Once we add:
(eval-when-compile (require 'project))
we are left with
diff-hl.el:414:16: Warning: ‘revert-buffer-in-progress-p’ is an
obsolete variable (as of 31.1); use ‘revert-buffer-in-progress’ instead.
which we deal with using `static-if'. Unfortunately that macro was
only added in Emacs 30.1. To get our hands on it earlier, we have
two options. Either we start depending on the Compat package, which
provides this macro, or we define it ourselves.
I went with the latter approach, assuming that you wouldn't want to
add an additional dependency just for this. But surely it is not okay
to (re-)define a macro that is usually defined in (later versions of)
Emacs?! Glad you asked! The implementation in "subr.el" is
prefixed with:
;; Note: `static-if' can be copied into a package to enable it to be
;; used in Emacsen older than Emacs 30.1. If the package is used in
;; very old Emacsen or XEmacs (in which `eval' takes exactly one
;; argument) the copy will need amending.
---
diff-hl.el | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/diff-hl.el b/diff-hl.el
index edb99c2312..eab7371d6e 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -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)
@@ -1666,9 +1675,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)))