emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 5910cb9672 5/5: Simplify alist-get compatibility


From: ELPA Syncer
Subject: [elpa] externals/compat 5910cb9672 5/5: Simplify alist-get compatibility
Date: Sat, 21 Jan 2023 13:57:31 -0500 (EST)

branch: externals/compat
commit 5910cb96723ab554004463d0f946816434f58748
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Simplify alist-get compatibility
---
 compat-25.el | 10 ----------
 compat-26.el | 38 +++++++++++++++-----------------------
 2 files changed, 15 insertions(+), 33 deletions(-)

diff --git a/compat-25.el b/compat-25.el
index 305f94f4db..8f216e8b16 100644
--- a/compat-25.el
+++ b/compat-25.el
@@ -123,16 +123,6 @@ MODES is as for `set-default-file-modes'."
              ,@body)
          (set-default-file-modes ,umask)))))
 
-(compat-defun alist-get (key alist &optional default remove) ;; 
<compat-tests:alist-get>
-  "Return the value associated with KEY in ALIST, using `assq'.
-If KEY is not found in ALIST, return DEFAULT.
-This is a generalized variable suitable for use with `setf'.
-When using it to set a value, optional argument REMOVE non-nil
-means to remove KEY from ALIST if the new value is `eql' to DEFAULT."
-  (ignore remove)
-  (let ((x (assq key alist)))
-    (if x (cdr x) default)))
-
 (compat-defmacro if-let (spec then &rest else) ;; <compat-tests:if-let>
   "Bind variables according to SPEC and evaluate THEN or ELSE.
 Evaluate each binding in turn, as in `let*', stopping if a
diff --git a/compat-26.el b/compat-26.el
index ad080f5f84..a06229d573 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -43,16 +43,6 @@ It should not be used for anything security-related.  See
        (widen)
        (sha1 (current-buffer) (point-min) (point-max)))))
 
-(compat-defun assoc (key alist &optional testfn) ;; <compat-tests:assoc>
-  "Handle the optional TESTFN."
-  :explicit t
-  (if testfn
-      (catch 'found
-        (dolist (ent alist)
-          (when (funcall testfn (car ent) key)
-            (throw 'found ent))))
-    (assoc key alist)))
-
 (compat-defun mapcan (func sequence) ;; <compat-tests:mapcan>
   "Apply FUNC to each element of SEQUENCE.
 Concatenate the results by altering them (using `nconc').
@@ -99,22 +89,24 @@ If you just want to check `major-mode', use 
`derived-mode-p'."
          (setq mode (if (and parentfn (symbolp parentfn)) parentfn parent)))))
   mode)
 
+(compat-defun assoc (key alist &optional testfn) ;; <compat-tests:assoc>
+  "Handle the optional TESTFN."
+  :explicit t
+  (if testfn
+      (catch 'found
+        (dolist (ent alist)
+          (when (funcall testfn (car ent) key)
+            (throw 'found ent))))
+    (assoc key alist)))
+
 (compat-defun alist-get (key alist &optional default remove testfn) ;; 
<compat-tests:alist-get>
   "Handle optional argument TESTFN."
   :explicit t
-  (if testfn
-      (let (entry)
-        (cond
-         ((eq testfn 'eq)
-          (setq entry (assq key alist)))
-         ((eq testfn 'equal)
-          (setq entry (assoc key alist)))
-         ((catch 'found
-            (dolist (ent alist)
-              (when (and (consp ent) (funcall testfn (car ent) key))
-                (throw 'found (setq entry ent)))))))
-        (if entry (cdr entry) default))
-    (alist-get key alist default remove)))
+  (ignore remove)
+  (let ((x (if (not testfn)
+               (assq key alist)
+             (compat--assoc key alist testfn))))
+    (if x (cdr x) default)))
 
 (compat-guard t
   (gv-define-expander compat--alist-get ;; <compat-tests:alist-get-gv>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]