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

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

[elpa] externals/compat 86fb58f 64/99: Move compat--alist-get-full-elisp


From: ELPA Syncer
Subject: [elpa] externals/compat 86fb58f 64/99: Move compat--alist-get-full-elisp to emacs-25.1
Date: Sun, 17 Oct 2021 05:57:58 -0400 (EDT)

branch: externals/compat
commit 86fb58fd0a4f295c2284821350b8b391bae0aad5
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Move compat--alist-get-full-elisp to emacs-25.1
---
 compat-25.1.el | 20 ++++++++++++++++++++
 compat-26.1.el | 14 --------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/compat-25.1.el b/compat-25.1.el
index 350f917..5a4183e 100644
--- a/compat-25.1.el
+++ b/compat-25.1.el
@@ -90,6 +90,26 @@ MODES is as for `set-default-file-modes'."
              ,@body)
          (set-default-file-modes ,umask)))))
 
+(compat-defun alist-get (key alist &optional default remove testfn)
+  "Find the first element of ALIST whose `car' equals KEY and return its `cdr'.
+If KEY is not found in ALIST, return DEFAULT.
+Equality with KEY is tested by TESTFN, defaulting to `eq'."
+  :max-version "24.5"
+  :realname compat--alist-get-full-elisp
+  (ignore remove)
+  (let (entry)
+    (cond
+     ((or (null testfn) (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))))
+        default)))
+    (if entry (cdr entry) default)))
+
 ;;;; Defined in subr-x.el
 
 (compat-defmacro if-let* (varlist then &rest else)
diff --git a/compat-26.1.el b/compat-26.1.el
index 99adce64..9415652 100644
--- a/compat-26.1.el
+++ b/compat-26.1.el
@@ -89,20 +89,6 @@ from the absolute start of the buffer, disregarding the 
narrowing."
         default)
     (funcall oldfun key alist default remove testfn)))
 
-(compat-defun alist-get (key alist &optional default remove testfn)
-  "Find the first element of ALIST whose `car' equals KEY and return its `cdr'.
-If KEY is not found in ALIST, return DEFAULT.
-Equality with KEY is tested by TESTFN, defaulting to `eq'."
-  :max-version "24.5"
-  :realname compat--alist-get-full-elisp
-  (ignore remove)
-  (unless testfn (setq testfn #'eq))
-  (catch 'found
-    (dolist (ent alist)
-      (when (and (consp ent) (funcall testfn (car ent) key))
-        (throw 'found (cdr ent))))
-    default))
-
 (compat-defun string-trim-left (string &optional regexp)
   "Trim STRING of leading string matching REGEXP.
 



reply via email to

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