branch: externals/compat commit 9fe496cee177e82c983c5fa1643125da00638426 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Use basic alist-get definition in 25 In compat-26 we provide the alist-get variant with the additional TESTFN argument. --- compat-25.el | 23 +++++++---------------- compat-26.el | 13 ++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/compat-25.el b/compat-25.el index 3febccb3f6..157fc31048 100644 --- a/compat-25.el +++ b/compat-25.el @@ -88,24 +88,15 @@ MODES is as for `set-default-file-modes'." ,@body) (set-default-file-modes ,umask))))) -(compat-defun alist-get (key alist &optional default remove testfn) ;; <OK> - "Find the first element of ALIST whose `car' equals KEY and return its `cdr'. +(compat-defun alist-get (key alist &optional default remove) ;; <OK> + "Return the value associated with KEY in ALIST, using `assq'. If KEY is not found in ALIST, return DEFAULT. -Equality with KEY is tested by TESTFN, defaulting to `eq'." - :realname compat--alist-get-full-elisp +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 (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))) + (let ((x (assq key alist))) + (if x (cdr x) default))) (compat-defmacro if-let (spec then &rest else) ;; <OK> "Bind variables according to SPEC and evaluate THEN or ELSE. diff --git a/compat-26.el b/compat-26.el index 54a3254732..bde9e8b8a6 100644 --- a/compat-26.el +++ b/compat-26.el @@ -69,7 +69,18 @@ from the absolute start of the buffer, disregarding the narrowing." "Handle TESTFN manually." :explicit t (if testfn - (compat--alist-get-full-elisp key alist default remove 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)))) + default))) + (if entry (cdr entry) default)) (alist-get key alist default remove))) (gv-define-expander compat--alist-get