aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEivind Fonn <evfonn@gmail.com>2020-02-22 10:56:56 +0100
committerEivind Fonn <evfonn@gmail.com>2020-02-22 11:00:00 +0100
commit810eaf6c8221a6854b490b843864baa303fad32a (patch)
treefbb0106fc3f00a9aeb4546abee48ae793567a6bf
parenteff9194949c28c68e3742969ce0ceb4d0c2564dc (diff)
Deprecate evil-add-to-alist, which doesn't work with lexical
-rw-r--r--evil-common.el30
-rw-r--r--evil-core.el8
-rw-r--r--evil-ex.el8
3 files changed, 36 insertions, 10 deletions
diff --git a/evil-common.el b/evil-common.el
index f68c6d7..5d7770b 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -91,6 +91,28 @@ the buffer-local value of HOOK is modified."
;;; List functions
+(defmacro evil--add-to-alist (list-var &rest elements)
+ "Add the assocation of KEY and VAL to the value of LIST-VAR.
+If the list already contains an entry for KEY, update that entry;
+otherwise add at the end of the list.
+
+\(fn LIST-VAR KEY VAL &rest ELEMENTS)"
+ (when (eq (car-safe list-var) 'quote)
+ (setq list-var (cadr list-var)))
+ `(progn
+ ,@(if (version< emacs-version "26")
+ ;; TODO: Remove this path when support for Emacs 25 is dropped
+ (cl-loop for (key val) on elements by #'cddr
+ collect `(let* ((key ,key)
+ (val ,val)
+ (cell (assoc key ,list-var)))
+ (if cell
+ (setcdr cell val)
+ (push (cons key val) ,list-var))))
+ (cl-loop for (key val) on elements by #'cddr
+ collect `(setf (alist-get ,key ,list-var nil nil #'equal) ,val)))
+ ,list-var))
+
(defun evil-add-to-alist (list-var key val &rest elements)
"Add the assocation of KEY and VAL to the value of LIST-VAR.
If the list already contains an entry for KEY, update that entry;
@@ -106,6 +128,10 @@ otherwise add at the end of the list."
(apply #'evil-add-to-alist list-var elements)
(symbol-value list-var))))
+(make-obsolete 'evil-add-to-alist
+ "use `evil--add-to-alist' instead. You may need to recompile code with evil macros."
+ "1.13.1")
+
;; custom version of `delete-if'
(defun evil-filter-list (predicate list &optional pointer)
"Delete by side-effect all items satisfying PREDICATE in LIST.
@@ -1960,11 +1986,11 @@ otherwise, it stays behind."
((evil-global-marker-p char)
(setq alist (default-value 'evil-markers-alist)
marker (make-marker))
- (evil-add-to-alist 'alist char marker)
+ (evil--add-to-alist 'alist char marker)
(setq-default evil-markers-alist alist))
(t
(setq marker (make-marker))
- (evil-add-to-alist 'evil-markers-alist char marker))))
+ (evil--add-to-alist 'evil-markers-alist char marker))))
(add-hook 'kill-buffer-hook #'evil-swap-out-markers nil t)
(set-marker-insertion-type marker advance)
(set-marker marker (or pos (point))))))
diff --git a/evil-core.el b/evil-core.el
index af32779..406377b 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -569,11 +569,11 @@ may be specified before the body code:
,@(if local
`((make-variable-buffer-local ',keymap)
(put ',keymap 'permanent-local t)
- (evil-add-to-alist 'evil-local-keymaps-alist
+ (evil--add-to-alist 'evil-local-keymaps-alist
',mode ',keymap))
- `((evil-add-to-alist 'evil-global-keymaps-alist
+ `((evil--add-to-alist 'evil-global-keymaps-alist
',mode ',keymap)
- (evil-add-to-alist 'evil-mode-map-alist
+ (evil--add-to-alist 'evil-mode-map-alist
',mode ,keymap)))
,(when (or body func)
`(defun ,mode (&optional arg)
@@ -1347,7 +1347,7 @@ If ARG is nil, don't display a message in the echo area.%s" name doc)
input-method-deactivate-hook)
(evil-change-state nil)
(setq evil-state ',state)
- (evil-add-to-alist 'evil-previous-state-alist
+ (evil--add-to-alist 'evil-previous-state-alist
',state evil-previous-state)
(let ((evil-state ',state))
(evil-normalize-keymaps)
diff --git a/evil-ex.el b/evil-ex.el
index c4aeda9..aa23e28 100644
--- a/evil-ex.el
+++ b/evil-ex.el
@@ -499,9 +499,9 @@ in case of incomplete or unknown commands."
(if (string-match "^[^][]*\\(\\[\\(.*\\)\\]\\)[^][]*$" cmd)
(let ((abbrev (replace-match "" nil t cmd 1))
(full (replace-match "\\2" nil nil cmd 1)))
- (evil-add-to-alist 'evil-ex-commands full function)
- (evil-add-to-alist 'evil-ex-commands abbrev full))
- (evil-add-to-alist 'evil-ex-commands cmd function))))
+ (evil--add-to-alist 'evil-ex-commands full function)
+ (evil--add-to-alist 'evil-ex-commands abbrev full))
+ (evil--add-to-alist 'evil-ex-commands cmd function))))
(defun evil-ex-make-argument-handler (runner completer)
(list runner completer))
@@ -560,7 +560,7 @@ keywords and function:
((eq key :completion-at-point)
(setq completer (cons 'completion-at-point func))))))
`(eval-and-compile
- (evil-add-to-alist
+ (evil--add-to-alist
'evil-ex-argument-types
',arg-type
'(,runner ,completer)))))