Backport to Emacs 25: avoid (setf (alist-get ... 'equal))
We would need to use `'equal` for comparison, but Emacs 25 only allows `'eq`. Using `advice-add` to override `alist-get` does not work, because `setf` has special handling for `alist-get`. `repl.el`: Switch to a hash table which already supports multiple comparison functions, and changing of elements even in Emacs 25. `eshell/autoload/settings.el`: use conditional set-or-push. Drop `doom*alist-get`, it is unused now. Thanks to @hlissner for the reimplementation.
This commit is contained in:
parent
9d445c8a1f
commit
b9c966ec54
3 changed files with 15 additions and 29 deletions
|
@ -10,24 +10,7 @@
|
|||
;; if-let and when-let are deprecated in Emacs 26+ in favor of their
|
||||
;; if-let* variants, so we alias them for 25 users.
|
||||
(defalias 'if-let* #'if-let)
|
||||
(defalias 'when-let* #'when-let)
|
||||
|
||||
;; `alist-get' doesn't have its 5th argument before Emacs 26
|
||||
(defun doom*alist-get (key alist &optional default remove testfn)
|
||||
"Return the value associated with KEY in ALIST.
|
||||
If KEY is not found in ALIST, return DEFAULT.
|
||||
Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'.
|
||||
|
||||
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) ;;Silence byte-compiler.
|
||||
(let ((x (cond ((null testfn) (assq key alist))
|
||||
((eq testfn #'equal) (assoc key alist))
|
||||
((cl-find key alist :key #'car :test testfn)))))
|
||||
(if x (cdr x) default)))
|
||||
(advice-add #'alist-get :override #'doom*alist-get))))
|
||||
|
||||
(defalias 'when-let* #'when-let))))
|
||||
|
||||
;;
|
||||
;; Helpers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue