diff options
| author | Stefan Monnier <monnier@iro.umontreal.ca> | 2023-07-01 16:17:16 -0400 |
|---|---|---|
| committer | Tom Dalziel <tom_dl@hotmail.com> | 2023-08-20 23:46:23 +0100 |
| commit | ca024ff6a7ba6de7cfd581878d1bdce02b6adef2 (patch) | |
| tree | cb8234274af101259f8593ae460d3bc9c2b0ca85 | |
| parent | 60ba716bf500ca21cdf5a8f83101449a1cbe3413 (diff) | |
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-types.el ("<addr>"):
* evil-common.el (evil--eval-expr):
* evil-commands.el (evil-ex-global): Tell `eval` to use the lexbind
dialect of ELisp.
| -rw-r--r-- | evil-commands.el | 2 | ||||
| -rw-r--r-- | evil-common.el | 2 | ||||
| -rw-r--r-- | evil-tests.el | 83 | ||||
| -rw-r--r-- | evil-types.el | 2 | ||||
| -rw-r--r-- | evil.el | 2 |
5 files changed, 47 insertions, 44 deletions
diff --git a/evil-commands.el b/evil-commands.el index 45f6b59..97598f3 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -4271,7 +4271,7 @@ Use `evil-flush-lines' if INVERT is nil, or `evil-keep-lines' if not." (let ((evil--ex-global-active-p t)) (dolist (marker markers) (goto-char marker) - (eval command-form)))) + (eval command-form t)))) ;; ensure that all markers are deleted afterwards, ;; even in the event of failure (dolist (marker markers) diff --git a/evil-common.el b/evil-common.el index e423a1c..ffe5eb7 100644 --- a/evil-common.el +++ b/evil-common.el @@ -1888,7 +1888,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-tests.el b/evil-tests.el index 5d323b8..58d530d 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> @@ -201,13 +201,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'") @@ -443,14 +442,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))))) @@ -493,10 +494,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) @@ -6033,7 +6032,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) @@ -8533,6 +8532,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) @@ -8901,15 +8909,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)) @@ -9121,25 +9120,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 () @@ -9690,6 +9690,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) @@ -9719,6 +9721,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 5969ddc..0e347d0 100644 --- a/evil-types.el +++ b/evil-types.el @@ -373,7 +373,7 @@ If visual state is inactive then those values are nil." (let ((expr (evil-ex-parse (or evil-ex-argument "")))) (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 "<!>" @@ -1,4 +1,4 @@ -;;; evil.el --- extensible vi layer +;;; evil.el --- Extensible vi layer -*- 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 |
