branch: scratch/evil commit 49ba6e6fc5b9fb545b32fe48ae23f0179c57e75f Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Use lexical-binding everywhere Most of the code already used lexical-binding, but there were still a few of remnant of use of the old dynbound dialect. * evil-tests.el: Activate `lexical-binding`. (evil-test-change-state): Initialize the local vars immediately rather than as a separate step. Remove unused vars `keymap` and `local-keymap`. (evil-test-auxiliary-maps): Rename local var to `evil--map` and declare it dynbound since we need `evil-define-key` to have access to it. (evil-test-exclusive-type): Remove unused var `third`. (evil-test-text-object): Mark unused var `type`. (evil-with-both-search-modules): Move before first use. (evil-test-properties): Rename local var to `evil--alist` and declare it dynbound since we need `evil-put-property` to have access to it. * evil.el: Activate `lexical-binding`. * evil-ex.el (evil-ex-execute, evil-ex-update, evil-ex-repeat): * evil-types.el ("<addr>"): * evil-common.el (evil--eval-expr): * evil-commands.el (evil-ex-global): Tell `eval` to use the lexbind dialect of ELisp. --- evil-commands.el | 2 +- evil-common.el | 2 +- evil-ex.el | 11 ++++---- evil-tests.el | 83 +++++++++++++++++++++++++++++--------------------------- evil-types.el | 2 +- evil.el | 2 +- 6 files changed, 53 insertions(+), 49 deletions(-) diff --git a/evil-commands.el b/evil-commands.el index 347ba5c939..2dd09b47d2 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -4334,7 +4334,7 @@ Use `evil-flush-lines' if INVERT is nil, or `evil-keep-lines' if not." (setq evil--ex-global-active-p t) (dolist (marker markers) (goto-char marker) - (eval command-form))) + (eval command-form t))) (progn (setq evil--ex-global-active-p nil) ;; ensure that all markers are deleted afterwards, diff --git a/evil-common.el b/evil-common.el index 1613196ad2..81d7a00070 100644 --- a/evil-common.el +++ b/evil-common.el @@ -1951,7 +1951,7 @@ If INPUT starts with a number, +, -, or . use `calc-eval' instead." (result (if calcable-p (let ((calc-multiplication-has-precedence nil)) (calc-eval input)) - (eval (car (read-from-string input)))))) + (eval (car (read-from-string input)) t)))) (cond ((stringp result) result) ((or (numberp result) (symbolp result)) diff --git a/evil-ex.el b/evil-ex.el index 1a26a053c7..052fd995bf 100644 --- a/evil-ex.el +++ b/evil-ex.el @@ -396,7 +396,7 @@ is appended to the line." (evil-ex-update nil nil nil result) ;; execute command (unless (zerop (length result)) - (eval (or evil-ex-expression (user-error "Ex: syntax error"))))) + (eval (or evil-ex-expression (user-error "Ex: syntax error")) t))) (defun evil-ex-delete-backward-char () "Close the minibuffer if it is empty. @@ -477,9 +477,9 @@ in case of incomplete or unknown commands." (with-current-buffer evil-ex-current-buffer (setq expr (evil-ex-parse string)) (when (eq (car expr) #'evil-ex-call-command) - (setq count (eval (nth 1 expr)) - cmd (eval (nth 2 expr)) - arg (eval (nth 3 expr)) + (setq count (eval (nth 1 expr) t) + cmd (eval (nth 2 expr) t) + arg (eval (nth 3 expr) t) range (cond ((evil-range-p count) count) ((numberp count) (evil-ex-range count count))) @@ -845,7 +845,8 @@ This function interprets special file names like # and %." (unless (eq binding #'evil-ex-repeat) (setq hist nil) (eval (or evil-ex-expression - (user-error "Ex: syntax error")))))))))) + (user-error "Ex: syntax error")) + t)))))))) (defun evil-ex-call-command (range command argument) "Execute the given command COMMAND." diff --git a/evil-tests.el b/evil-tests.el index d9311a59d9..455f7470c3 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -1,4 +1,4 @@ -;; evil-tests.el --- unit tests for Evil -*- coding: utf-8 -*- +;; evil-tests.el --- unit tests for Evil -*- coding: utf-8; lexical-binding: t; -*- ;; Author: Vegard Øye <vegard_oye at hotmail.com> ;; Maintainer: Vegard Øye <vegard_oye at hotmail.com> @@ -200,13 +200,12 @@ with `M-x evil-tests-run'")) (defun evil-test-change-state (state) "Change state to STATE and check keymaps" - (let (mode keymap local-mode local-keymap tag) - (evil-change-state state) - (setq mode (evil-state-property state :mode) - keymap (evil-state-property state :keymap t) - local-mode (evil-state-property state :local) - local-keymap (evil-state-property state :local-keymap t) - tag (evil-state-property state :tag t)) + (evil-change-state state) + (let ((mode (evil-state-property state :mode)) + ;; (keymap (evil-state-property state :keymap t)) + (local-mode (evil-state-property state :local)) + ;; (local-keymap (evil-state-property state :local-keymap t)) + (tag (evil-state-property state :tag t))) (when (functionp tag) (setq tag (funcall tag))) (ert-info ("Update `evil-state'") @@ -442,14 +441,16 @@ when exiting Operator-Pending state") (ert-deftest evil-test-auxiliary-maps () "Test auxiliary keymaps" :tags '(evil state) - (let ((map (make-sparse-keymap)) aux) + ;; `evil-define-key' can't be used on a lexically-scoped keymap var. + (defvar evil--map) + (let ((evil--map (make-sparse-keymap)) aux) (ert-info ("Create a new auxiliary keymap") - (evil-define-key 'normal map "f" 'foo) - (setq aux (evil-get-auxiliary-keymap map 'normal)) + (evil-define-key 'normal evil--map "f" 'foo) + (setq aux (evil-get-auxiliary-keymap evil--map 'normal)) (should (evil-auxiliary-keymap-p aux)) (should (eq (lookup-key aux "f") 'foo))) (ert-info ("Add to auxiliary keymap") - (evil-define-key 'normal map "b" 'bar) + (evil-define-key 'normal evil--map "b" 'bar) (should (eq (lookup-key aux "f") 'foo)) (should (eq (lookup-key aux "b") 'bar))))) @@ -492,10 +493,8 @@ when exiting Operator-Pending state") (let* ((first-line 1) (second-line (progn (forward-line) - (point))) - (third-line (progn - (forward-line) - (point)))) + (point)))) + (forward-line) (ert-info ("Return the beginning and end unchanged \ if they are the same") (should (equal (evil-normalize 1 1 'exclusive) @@ -6032,7 +6031,7 @@ Line 2")) (ert-deftest evil-test-text-object () "Test `evil-define-text-object'" :tags '(evil text-object) - (let ((object (evil-define-text-object nil (count &optional beg end type) + (let ((object (evil-define-text-object nil (count &optional beg end _type) (let ((sel (and beg end (evil-range beg end)))) (when (and sel (> count 0)) (forward-char 1)) (let ((range (if (< count 0) @@ -8524,6 +8523,15 @@ maybe we need one line more with some text\n") ("vj!sort" [return]) "line 5\n[l]ine 3\nline 4\nline 2\nline 1\n"))) +(defmacro evil-with-both-search-modules (&rest body) + `(mapc (lambda (search-module) + (setq evil-search-forward-history nil + evil-search-backward-history nil + evil-ex-search-history nil) + (evil-select-search-module 'evil-search-module search-module) + ,@body) + '(isearch evil-search))) + (ert-deftest evil-test-global () "Test `evil-ex-global'." :tags '(evil ex global) @@ -8892,15 +8900,6 @@ Source (execute-kbd-macro "q:") (should (= (length (window-list)) num-windows)))))) -(defmacro evil-with-both-search-modules (&rest body) - `(mapc (lambda (search-module) - (setq evil-search-forward-history nil - evil-search-backward-history nil - evil-ex-search-history nil) - (evil-select-search-module 'evil-search-module search-module) - ,@body) - '(isearch evil-search))) - (ert-deftest evil-test-command-window-search-history () "Test command window with forward and backward search history" (skip-unless (not noninteractive)) @@ -9105,25 +9104,26 @@ parameter set." (ert-deftest evil-test-properties () "Test `evil-get-property' and `evil-put-property'" :tags '(evil util) - (let (alist) + (defvar evil--alist) + (let (evil--alist) (ert-info ("Set properties") - (evil-put-property 'alist 'wibble :foo t) - (should (equal alist '((wibble . (:foo t))))) - (evil-put-property 'alist 'wibble :bar nil) - (should (equal alist '((wibble . (:foo t :bar nil))))) - (evil-put-property 'alist 'wobble :foo nil :bar nil :baz t) - (should (equal alist '((wobble . (:foo nil :bar nil :baz t)) + (evil-put-property 'evil--alist 'wibble :foo t) + (should (equal evil--alist '((wibble . (:foo t))))) + (evil-put-property 'evil--alist 'wibble :bar nil) + (should (equal evil--alist '((wibble . (:foo t :bar nil))))) + (evil-put-property 'evil--alist 'wobble :foo nil :bar nil :baz t) + (should (equal evil--alist '((wobble . (:foo nil :bar nil :baz t)) (wibble . (:foo t :bar nil)))))) (ert-info ("Get properties") - (should (evil-get-property alist 'wibble :foo)) - (should-not (evil-get-property alist 'wibble :bar)) - (should-not (evil-get-property alist 'wobble :foo)) - (should-not (evil-get-property alist 'wibble :baz)) - (should (equal (evil-get-property alist t :foo) + (should (evil-get-property evil--alist 'wibble :foo)) + (should-not (evil-get-property evil--alist 'wibble :bar)) + (should-not (evil-get-property evil--alist 'wobble :foo)) + (should-not (evil-get-property evil--alist 'wibble :baz)) + (should (equal (evil-get-property evil--alist t :foo) '((wibble . t) (wobble . nil)))) - (should (equal (evil-get-property alist t :bar) + (should (equal (evil-get-property evil--alist t :bar) '((wibble . nil) (wobble . nil)))) - (should (equal (evil-get-property alist t :baz) + (should (equal (evil-get-property evil--alist t :baz) '((wobble . t))))))) (ert-deftest evil-test-filter-list () @@ -9674,6 +9674,8 @@ main(argc, argv) char **argv; { (ert-deftest evil-test-initial-state () "Test `evil-initial-state'" :tags '(evil core) + ;; FIXME: These have a global effect, so better move them out and give them + ;; a proper namespace prefix. (define-derived-mode test-1-mode prog-mode "Test1") (define-derived-mode test-2-mode test-1-mode "Test2") (evil-set-initial-state 'test-1-mode 'insert) @@ -9703,6 +9705,7 @@ main(argc, argv) char **argv; { ;; is sufficient for `evil-initial-state-for-buffer' to work. (should-error (evil-initial-state-for-buffer))) (put 'test-1-mode 'derived-mode-parent 'prog-mode)))) + ;; FIXME: Same as above. (defalias 'test-1-alias-mode #'test-1-mode) (define-derived-mode test-3-mode test-1-alias-mode "Test3") (evil-set-initial-state 'test-1-mode 'insert) diff --git a/evil-types.el b/evil-types.el index 276cdbbf1f..9d460412a6 100644 --- a/evil-types.el +++ b/evil-types.el @@ -376,7 +376,7 @@ If visual state is inactive then those values are nil." (if (eq (car expr) 'evil-goto-line) (save-excursion (goto-char evil-ex-point) - (eval (cadr expr))) + (eval (cadr expr) t)) (user-error "Invalid address")))))) (evil-define-interactive-code "<!>" diff --git a/evil.el b/evil.el index 00e7d7ce9c..769f29dd1d 100644 --- a/evil.el +++ b/evil.el @@ -1,4 +1,4 @@ -;;; evil.el --- Extensible Vi layer for Emacs +;;; evil.el --- Extensible Vi layer for Emacs -*- lexical-binding: t; -*- ;; The following list of authors was kept up to date until the beginning of ;; 2017, when evil moved under new maintainers. For authors since then, please