aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-21 20:14:54 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-21 20:39:04 +0100
commite53184c187631dcd2e784dbd4db541c63f028832 (patch)
tree315d931babdf9d733f7e9a956d42c7e21e8399bc
parent5910cb96723ab554004463d0f946816434f58748 (diff)
compat-macs: Strict checking of :explicit
-rw-r--r--compat-26.el16
-rw-r--r--compat-27.el18
-rw-r--r--compat-macs.el12
-rw-r--r--compat-tests.el6
4 files changed, 29 insertions, 23 deletions
diff --git a/compat-26.el b/compat-26.el
index a06229d..ce23d9c 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -101,7 +101,7 @@ If you just want to check `major-mode', use `derived-mode-p'."
(compat-defun alist-get (key alist &optional default remove testfn) ;; <compat-tests:alist-get>
"Handle optional argument TESTFN."
- :explicit t
+ :explicit "25.1"
(ignore remove)
(let ((x (if (not testfn)
(assq key alist)
@@ -358,20 +358,6 @@ The returned file name can be used directly as argument of
`process-file', `start-file-process', or `shell-command'."
(or (file-remote-p file 'localname) file))
-(compat-defun file-name-quoted-p (name &optional top) ;; <compat-tests:file-name-quoted-p>
- "Handle optional argument TOP."
- :explicit t
- (let ((file-name-handler-alist (unless top file-name-handler-alist)))
- (string-prefix-p "/:" (file-local-name name))))
-
-(compat-defun file-name-quote (name &optional top) ;; <compat-tests:file-name-quote>
- "Handle optional argument TOP."
- :explicit t
- (let ((file-name-handler-alist (unless top file-name-handler-alist)))
- (if (string-prefix-p "/:" (file-local-name name))
- name
- (concat (file-remote-p name) "/:" (file-local-name name)))))
-
(compat-defun temporary-file-directory () ;; <compat-tests:temporary-file-directory>
"The directory for writing temporary files.
In case of a remote `default-directory', this is a directory for
diff --git a/compat-27.el b/compat-27.el
index ee7f89e..eebd951 100644
--- a/compat-27.el
+++ b/compat-27.el
@@ -211,7 +211,7 @@ return nil."
(compat-defun assoc-delete-all (key alist &optional test) ;; <compat-tests:assoc-delete-all>
"Handle optional argument TEST."
- :explicit t
+ :explicit "26.2"
(unless test (setq test #'equal))
(while (and (consp (car alist))
(funcall test (caar alist) key))
@@ -306,7 +306,7 @@ the minibuffer was activated, and execute the forms."
(compat-defun image--set-property (image property value) ;; <compat-tests:image-property>
"Set PROPERTY in IMAGE to VALUE.
Internal use only."
- :explicit t
+ :explicit "26.1"
:feature image
(if (null value)
(while (cdr image)
@@ -327,6 +327,20 @@ Internal use only."
;;;; Defined in files.el
+(compat-defun file-name-quoted-p (name &optional top) ;; <compat-tests:file-name-quoted-p>
+ "Handle optional argument TOP."
+ :explicit "26.1"
+ (let ((file-name-handler-alist (unless top file-name-handler-alist)))
+ (string-prefix-p "/:" (file-local-name name))))
+
+(compat-defun file-name-quote (name &optional top) ;; <compat-tests:file-name-quote>
+ "Handle optional argument TOP."
+ :explicit "26.1"
+ (let ((file-name-handler-alist (unless top file-name-handler-alist)))
+ (if (string-prefix-p "/:" (file-local-name name))
+ name
+ (concat (file-remote-p name) "/:" (file-local-name name)))))
+
(compat-defun file-size-human-readable (file-size &optional flavor space unit) ;; <compat-tests:file-size-human-readable>
"Handle the optional arguments SPACE and UNIT.
diff --git a/compat-macs.el b/compat-macs.el
index bf836cd..40c4f7c 100644
--- a/compat-macs.el
+++ b/compat-macs.el
@@ -105,12 +105,14 @@ a plist of predicates for arguments which are passed to FUN."
(defun compat--guard-defun (type name arglist docstring rest)
"Define function NAME of TYPE with ARGLIST and DOCSTRING.
REST are attributes and the function BODY."
- (compat--guard rest `(:explicit booleanp
+ (compat--guard rest `(:explicit ,(lambda (x) (or (booleanp x) (version-to-list x)))
:obsolete ,(lambda (x) (or (booleanp x) (stringp x)))
:body t)
(lambda (explicit obsolete body)
- (compat--strict (or explicit (not (fboundp name)))
- "Non-explicit %s %s already defined" type name)
+ (when (stringp explicit)
+ (setq explicit (version<= explicit emacs-version)))
+ (compat--strict (eq explicit (fboundp name))
+ "Wrong :explicit flag for %s %s" type name)
;; Remove unsupported declares. It might be possible to set these
;; properties otherwise. That should be looked into and implemented
;; if it is the case.
@@ -198,7 +200,9 @@ specify the conditions under which the definition is generated.
invocation via `compat-call'. :explicit should be used for
functions which extend already existing functions, e.g.,
functions which changed their calling convention or their
- behavior.
+ behavior. The value can also be a version string, which
+ specifies for which Emacs version and newer an explicit
+ definition will be created.
- :obsolete :: Mark the function as obsolete if t, can be a
string describing the obsoletion.
diff --git a/compat-tests.el b/compat-tests.el
index 74e5bec..58aa635 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1564,7 +1564,8 @@
(should-equal ":/bar/foo" (file-local-name "/ssh:::/bar/foo")))
(ert-deftest file-name-quoted-p ()
- ;; TODO test TOP argument
+ (should-not (compat-call file-name-quoted-p "" t)) ;; top argument
+ (should (compat-call file-name-quoted-p "/:" t)) ;; top argument
(should-not (file-name-quoted-p ""))
(should (file-name-quoted-p "/:"))
(should-not (file-name-quoted-p "//:"))
@@ -1578,7 +1579,8 @@
(should-not (file-name-quoted-p "/ssh:/:a"))))
(ert-deftest file-name-quote ()
- ;; TODO test TOP argument
+ (should-equal "/:" (compat-call file-name-quote "" t)) ;; top argument
+ (should-equal "/::"(compat-call file-name-quote ":" t)) ;; top argument
(should-equal "/:" (file-name-quote ""))
(should-equal "/::"(file-name-quote ":"))
(should-equal "/:/" (file-name-quote "/"))