emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil f003ca28a9: Fix Fundamental mode hack


From: ELPA Syncer
Subject: [nongnu] elpa/evil f003ca28a9: Fix Fundamental mode hack
Date: Tue, 10 Jan 2023 15:59:04 -0500 (EST)

branch: elpa/evil
commit f003ca28a9691d24a17866e5dce3e7866c9bb257
Author: Axel Forsman <axelsfor@gmail.com>
Commit: Axel Forsman <axelsfor@gmail.com>

    Fix Fundamental mode hack
    
    This commit fixes some issues surrounding the initialization of Evil.
    
    First of all, since GNU Emacs 26.1 major mode hooks actually do run in
    Fundamental mode buffers. In any case, manually enabling
    fundamental-mode correctly instead of turn-on-evil-mode (by setting
    major-mode default) successfully enables evil-local-mode, as major mode
    hooks then run. The major-mode variable also never needed to be reset;
    it is the job of the major mode to set it, as it starts off as
    fundamental-mode regardless of its default value.
    
    Secondly, while some hooks and variables set up by evil-local-mode were
    marked as permanent, this did not matter as evil-initialize
    unconditionally reinitialized evil-local-mode whenever the major mode
    changed. Fixed by marking them all as permanent and not executing
    evil-local-mode if it is already enabled.
    
    Closes #1268, closes #1561
---
 evil-commands.el |  72 ++++++---------
 evil-common.el   |   7 +-
 evil-core.el     | 276 +++++++++++++++++++++++--------------------------------
 evil-jumps.el    |  56 +++++------
 evil-states.el   |  19 ++--
 evil-tests.el    |  25 +++--
 6 files changed, 193 insertions(+), 262 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 03fd0635d2..3f9b5ab417 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -706,29 +706,27 @@ Movement is restricted to the current line unless 
`evil-cross-lines' is non-nil.
   (setq count (or count 1))
   (let ((fwd (> count 0))
         (visual (and evil-respect-visual-line-mode
-                     visual-line-mode)))
+                     visual-line-mode))
+        case-fold-search)
     (setq evil-last-find (list #'evil-find-char char fwd))
     (when fwd (evil-forward-char 1 evil-cross-lines))
-    (let ((case-fold-search nil))
-      (unless (prog1
-                  (search-forward (char-to-string char)
-                                  (cond (evil-cross-lines
-                                         nil)
-                                        ((and fwd visual)
-                                         (save-excursion
-                                           (end-of-visual-line)
-                                           (point)))
-                                        (fwd
-                                         (line-end-position))
-                                        (visual
-                                         (save-excursion
-                                           (beginning-of-visual-line)
-                                           (point)))
-                                        (t
-                                         (line-beginning-position)))
-                                  t count)
-                (when fwd (backward-char)))
-        (user-error "Can't find %c" char)))))
+    (unless (prog1
+                (search-forward
+                 (char-to-string char)
+                 (cond (evil-cross-lines nil)
+                       ((and fwd visual)
+                        (save-excursion
+                          (end-of-visual-line)
+                          (point)))
+                       (fwd (line-end-position))
+                       (visual
+                        (save-excursion
+                          (beginning-of-visual-line)
+                          (point)))
+                       (t (line-beginning-position)))
+                 t count)
+              (when fwd (backward-char)))
+      (user-error "Can't find `%c'" char))))
 
 (evil-define-motion evil-find-char-backward (count char)
   "Move to the previous COUNT'th occurrence of CHAR."
@@ -4476,13 +4474,8 @@ and open a new buffer or edit a certain FILE."
                                   (if evil-split-window-below 'below 'above))))
     (when (and (not count) evil-auto-balance-windows)
       (balance-windows (window-parent)))
-    (let ((buffer (generate-new-buffer "*new*")))
-      (set-window-buffer new-window buffer)
-      (select-window new-window)
-      (with-current-buffer buffer
-        (funcall (default-value 'major-mode))))
-    (when file
-      (evil-edit file))))
+    (select-window new-window)
+    (evil-buffer-new file)))
 
 (evil-define-command evil-window-vnew (count file)
   "Split the current window vertically
@@ -4493,25 +4486,18 @@ and open a new buffer name or edit a certain FILE."
                                   (if evil-vsplit-window-right 'right 'left))))
     (when (and (not count) evil-auto-balance-windows)
       (balance-windows (window-parent)))
-    (let ((buffer (generate-new-buffer "*new*")))
-      (set-window-buffer new-window buffer)
-      (select-window new-window)
-      (with-current-buffer buffer
-        (funcall (default-value 'major-mode))))
-    (when file
-      (evil-edit file))))
-
-(evil-define-command evil-buffer-new (count file)
-  "Create a new buffer replacing the current window, optionally
-   editing a certain FILE"
+    (select-window new-window)
+    (evil-buffer-new file)))
+
+(evil-define-command evil-buffer-new (&optional file)
+  "Edit a new unnamed buffer or FILE."
   :repeat nil
-  (interactive "P<f>")
+  (interactive "<f>")
   (if file
       (evil-edit file)
     (let ((buffer (generate-new-buffer "*new*")))
-      (set-window-buffer nil buffer)
-      (with-current-buffer buffer
-        (funcall (default-value 'major-mode))))))
+      (set-buffer-major-mode buffer)
+      (set-window-buffer nil buffer))))
 
 (evil-define-command evil-window-increase-height (count)
   "Increase current window height by COUNT."
diff --git a/evil-common.el b/evil-common.el
index fef5b18a69..bc76653d3e 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -410,7 +410,7 @@ See also `evil-get-command-property'."
 To set multiple properties at once, see
 `evil-set-command-properties' and `evil-add-command-properties'."
   (evil-put-property 'evil-command-properties command property value))
-(defalias 'evil-put-command-property 'evil-set-command-property)
+(defalias 'evil-put-command-property #'evil-set-command-property)
 
 (defun evil-add-command-properties (command &rest properties)
   "Add PROPERTIES to COMMAND.
@@ -3625,7 +3625,7 @@ make the entries undoable as a single action. See
   "Execute BODY with enabled undo.
 If undo is disabled in the current buffer, the undo information
 is stored in `evil-temporary-undo' instead of `buffer-undo-list'."
-  (declare (debug t))
+  (declare (indent defun) (debug t))
   (let ((undo-list (make-symbol "undo-list")))
     `(let ((,undo-list buffer-undo-list)
            (evil-undo-system evil-undo-system))
@@ -3645,7 +3645,7 @@ is stored in `evil-temporary-undo' instead of 
`buffer-undo-list'."
 
 (defmacro evil-with-single-undo (&rest body)
   "Execute BODY as a single undo step."
-  (declare (debug t))
+  (declare (indent defun) (debug t))
   `(let (evil-undo-list-pointer)
      (evil-with-undo
        (evil-start-undo-step)
@@ -4000,7 +4000,6 @@ should be left-aligned for left justification."
 ;;; View helper
 
 (defvar-local evil-list-view-select-action nil)
-(put 'evil-list-view-select-action 'permanent-local t)
 
 (define-derived-mode evil-list-view-mode tabulated-list-mode
   "Evil List View"
diff --git a/evil-core.el b/evil-core.el
index 62ec6ab6b0..d773b2e5d8 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -104,107 +104,90 @@
 ;; ("visual"), Replace state ("replace"), Operator-Pending state
 ;; ("operator"), Motion state ("motion") and Emacs state ("emacs").
 
-(require 'evil-common)
-
 ;;; Code:
 
+(require 'advice)
+(require 'evil-common)
+
 (declare-function evil-emacs-state-p "evil-states")
 (declare-function evil-ex-p "evil-ex")
-(defvar evil-mode-buffers)
 
 (define-minor-mode evil-local-mode
   "Minor mode for setting up Evil in a single buffer."
   :init-value nil
-  (cond
-   ((evil-disabled-buffer-p)
-    ;; Don't leave the mode variable on in buffers where evil disabled, because
-    ;; functions that check this variable will get an incorrect result (e.g.,
-    ;; evil-refresh-cursor).
-    (setq evil-local-mode nil))
-   (evil-local-mode
-    (setq emulation-mode-map-alists
-          (evil-concat-lists '(evil-mode-map-alist)
-                             emulation-mode-map-alists))
-    (evil-initialize-local-keymaps)
-    ;; restore the proper value of `major-mode' in Fundamental buffers
-    (when (eq major-mode 'turn-on-evil-mode)
-      (setq major-mode 'fundamental-mode))
-    (when (minibufferp)
-      (setq-local evil-default-state 'insert)
-      (setq-local evil-echo-state nil))
-    (setq evil-input-method current-input-method)
-    ;; The initial state is usually setup by `evil-initialize' when
-    ;; the major-mode in a buffer changes. This preliminary
-    ;; initialization is only for the case when `evil-local-mode' is
-    ;; called directly for the first time in a buffer.
-    (unless evil-state (evil-initialize-state))
-    (add-hook 'input-method-activate-hook 'evil-activate-input-method t t)
-    (add-hook 'input-method-deactivate-hook 'evil-deactivate-input-method t t)
-    (add-hook 'activate-mark-hook 'evil-visual-activate-hook nil t)
-    (add-hook 'pre-command-hook 'evil-repeat-pre-hook)
-    (add-hook 'post-command-hook 'evil-repeat-post-hook))
-   (t
+  (if evil-local-mode
+      (progn
+        (cl-pushnew 'evil-mode-map-alist emulation-mode-map-alists)
+        (evil-initialize-local-keymaps)
+        (when (minibufferp)
+          (setq-local evil-default-state 'insert
+                      evil-echo-state nil))
+        (setq evil-input-method current-input-method)
+        (evil-initialize-state)
+        (add-hook 'input-method-activate-hook #'evil-activate-input-method t t)
+        (add-hook 'input-method-deactivate-hook #'evil-deactivate-input-method 
t t)
+        (add-hook 'activate-mark-hook 'evil-visual-activate-hook nil t)
+        ;; FIXME: Add these hooks buffer-locally
+        (add-hook 'pre-command-hook 'evil-repeat-pre-hook)
+        (add-hook 'post-command-hook 'evil-repeat-post-hook))
     (evil-refresh-mode-line)
     (remove-hook 'activate-mark-hook 'evil-visual-activate-hook t)
-    (remove-hook 'input-method-activate-hook 'evil-activate-input-method t)
-    (remove-hook 'input-method-deactivate-hook 'evil-deactivate-input-method t)
-    (evil-change-state nil))))
+    (remove-hook 'input-method-activate-hook #'evil-activate-input-method t)
+    (remove-hook 'input-method-deactivate-hook #'evil-deactivate-input-method 
t)
+    (evil-change-state nil)))
 
 ;; Make the variable permanent local.  This is particular useful in
 ;; conjunction with nXhtml/mumamo because mumamo does not touch these
 ;; variables.
 (put 'evil-local-mode 'permanent-local t)
 
-(defun turn-on-evil-mode (&optional arg)
+(defun turn-on-evil-mode ()
   "Turn on Evil in the current buffer."
   (interactive)
-  (evil-local-mode (or arg 1)))
+  (evil-local-mode))
 
-(defun turn-off-evil-mode (&optional arg)
+(defun turn-off-evil-mode ()
   "Turn off Evil in the current buffer."
   (interactive)
-  (evil-local-mode (or arg -1)))
+  (evil-local-mode -1))
 
 ;; The function `evil-initialize' should only be used to initialize
 ;; `evil-local-mode' from the globalized minor-mode `evil-mode'. It is
 ;; called whenever evil is enabled in a buffer for the first time or
-;; when evil is active and the major-mode of the buffer changes. In
-;; addition to enabling `evil-local-mode' it also sets the initial
-;; evil-state according to the major-mode.
+;; when evil is active and the major-mode of the buffer changes.
 (defun evil-initialize ()
   "Enable Evil in the current buffer, if appropriate.
-To enable Evil globally, do (evil-mode 1)."
-  (unless (and (minibufferp) (not evil-want-minibuffer))
-    (evil-local-mode 1)
-    (evil-initialize-state)))
+To enable Evil globally, do (evil-mode)."
+  (if evil-local-mode
+      ;; Set Evil state according to new major-mode
+      (evil-initialize-state)
+    (or (and (minibufferp) (not evil-want-minibuffer))
+        (evil-disabled-buffer-p)
+        (evil-local-mode))))
+
+(defalias 'evil--fundamental-mode #'fundamental-mode)
 
 ;;;###autoload (autoload 'evil-mode "evil" nil t)
 (define-globalized-minor-mode evil-mode
   evil-local-mode evil-initialize
-  :group 'evil)
-
-;; No hooks are run in Fundamental buffers, so other measures are
-;; necessary to initialize Evil in these buffers. When Evil is
-;; enabled globally, the default value of `major-mode' is set to
-;; `turn-on-evil-mode', so that Evil is enabled in Fundamental
-;; buffers as well. Then, the buffer-local value of `major-mode' is
-;; changed back to `fundamental-mode'. (Since the `evil-mode' function
-;; is created by a macro, we use `defadvice' to augment it.)
-(defadvice evil-mode (after start-evil activate)
-  "Enable Evil in Fundamental mode."
+  :group 'evil
+  ;; Hooks used to not run in Fundamental buffers (bug#23827), so
+  ;; other measures are necessary to initialize Evil there. When Evil
+  ;; is enabled globally, the default value of `major-mode' is set to
+  ;; the `evil--fundamental-mode' alias, sidestepping the restriction.
   (if evil-mode
       (progn
-        (when (eq (default-value 'major-mode) 'fundamental-mode)
-          ;; changed back by `evil-local-mode'
-          (setq-default major-mode 'turn-on-evil-mode))
+        (and (eval-when-compile (version< emacs-version "26.1"))
+             (eq (default-value 'major-mode) 'fundamental-mode)
+             (setq-default major-mode 'evil--fundamental-mode))
         (ad-enable-regexp "^evil")
         (ad-activate-regexp "^evil")
-        (with-no-warnings (evil-esc-mode 1)))
-    (when (eq (default-value 'major-mode) 'turn-on-evil-mode)
+        (evil-esc-mode 1))
+    (when (eq (default-value 'major-mode) 'evil--fundamental-mode)
       (setq-default major-mode 'fundamental-mode))
     (ad-disable-regexp "^evil")
     (ad-update-regexp "^evil")
-    (with-no-warnings (evil-esc-mode -1))))
+    (evil-esc-mode -1)))
 
 (defun evil-change-state (state &optional message)
   "Change the state to STATE.
@@ -218,13 +201,13 @@ If STATE is nil, disable all states."
   "Save the current state; execute BODY; restore the state."
   (declare (indent defun)
            (debug t))
-  `(let* ((evil-state evil-state)
-          (evil-previous-state evil-previous-state)
-          (evil-previous-state-alist (copy-tree evil-previous-state-alist))
-          (evil-next-state evil-next-state)
-          (old-state evil-state)
-          (inhibit-quit t)
-          (buf (current-buffer)))
+  `(let ((evil-state evil-state)
+         (evil-previous-state evil-previous-state)
+         (evil-previous-state-alist (copy-tree evil-previous-state-alist))
+         (evil-next-state evil-next-state)
+         (old-state evil-state)
+         (inhibit-quit t)
+         (buf (current-buffer)))
      (unwind-protect
          (progn ,@body)
        (when (buffer-live-p buf)
@@ -241,53 +224,48 @@ Restore the previous state afterwards."
        (evil-change-state ',state)
        ,@body)))
 
-(defun evil-initializing-p (&optional buffer)
-  "Whether Evil is in the process of being initialized."
-  (memq (or buffer (current-buffer)) evil-mode-buffers))
-
 (defun evil-initialize-state (&optional state buffer)
   "Set up the initial state for BUFFER.
 BUFFER defaults to the current buffer.
 Uses STATE if specified, or calls `evil-initial-state-for-buffer'.
 See also `evil-set-initial-state'."
   (with-current-buffer (or buffer (current-buffer))
-    (if state (evil-change-state state)
-      (evil-change-to-initial-state buffer))))
+    (evil-change-state
+     (or state (evil-initial-state-for-buffer buffer)))))
 (put 'evil-initialize-state 'permanent-local-hook t)
 
 (defun evil-initial-state-for-buffer-name (&optional name default)
   "Return the initial Evil state to use for a buffer with name NAME.
 Matches the name against the regular expressions in
 `evil-buffer-regexps'. If none matches, returns DEFAULT."
-  (let ((name (if (stringp name) name (buffer-name name)))
-        regexp state)
-    (when (stringp name)
+  (let ((name (if (stringp name) name (buffer-name name))))
+    (when name
       (catch 'done
         (dolist (entry evil-buffer-regexps default)
-          (setq regexp (car entry)
-                state (cdr entry))
-          (when (string-match regexp name)
-            (throw 'done state)))))))
+          (let ((regexp (car entry))
+                (state (cdr entry)))
+            (when (string-match-p regexp name)
+              (throw 'done state))))))))
 
 (defun evil-disabled-buffer-p (&optional buffer)
   "Whether Evil should be disabled in BUFFER."
   (null (evil-initial-state-for-buffer-name buffer 'undefined)))
 
-(defun evil-initial-state-for-buffer (&optional buffer default)
+(defun evil-initial-state-for-buffer (&optional buffer)
   "Return the initial Evil state to use for BUFFER.
 BUFFER defaults to the current buffer. Returns DEFAULT
 if no initial state is associated with BUFFER.
 See also `evil-initial-state'."
   (with-current-buffer (or buffer (current-buffer))
-    (or (evil-initial-state-for-buffer-name (buffer-name))
+    (or (evil-initial-state-for-buffer-name)
         (catch 'done
           (dolist (mode minor-mode-map-alist)
-            (setq mode (car-safe mode))
-            (when (and (boundp mode) (symbol-value mode))
-              (when (setq mode (evil-initial-state mode))
-                (throw 'done mode)))))
+            (setq mode (car mode))
+            (and (boundp mode) (symbol-value mode)
+                 (setq mode (evil-initial-state mode))
+                 (throw 'done mode))))
         (evil-initial-state major-mode nil t)
-        default)))
+        evil-default-state)))
 
 (defun evil-initial-state (mode &optional default follow-parent checked-modes)
   "Return the Evil state to use for MODE or its alias.
@@ -298,30 +276,24 @@ The initial state for a mode can be set with
 If FOLLOW-PARENT is non-nil, also check parent modes of MODE and
 its alias. CHECKED-MODES is used internally and should not be set
 initially."
-  (cond
-   ((and mode (symbolp mode) (memq mode checked-modes))
-    (error "Circular reference detected in ancestors of %s\n%s"
+  (when (memq mode checked-modes)
+    (error "Circular reference detected in ancestors of `%s'\n%s"
            major-mode checked-modes))
-   ((and mode (symbolp mode))
-    (let ((mode-alias (let ((func (symbol-function mode)))
-                        (when (symbolp func)
-                          func)))
-          state modes)
-      (or
-       (catch 'done
-         (dolist (entry (evil-state-property t :modes) default)
-           (setq state (car entry)
-                 modes (symbol-value (cdr entry)))
-           (when (or (memq mode modes)
-                     (and mode-alias
-                          (memq mode-alias modes)))
-             (throw 'done state))))
-       (when follow-parent
-         (evil-initial-state (get mode 'derived-mode-parent)
-                             nil t (cons mode checked-modes)))
-       (when follow-parent
-         (evil-initial-state (get mode-alias 'derived-mode-parent)
-                             nil t (cons mode-alias checked-modes))))))))
+  (let ((mode-alias (let ((func (symbol-function mode)))
+                      (when (symbolp func) func))))
+    (or (cl-dolist (entry (evil-state-property t :modes) default)
+          (let ((state (car entry))
+                (modes (symbol-value (cdr entry))))
+            (when (or (memq mode modes)
+                      (and mode-alias (memq mode-alias modes)))
+              (cl-return state))))
+        (and follow-parent (get mode 'derived-mode-parent)
+             (evil-initial-state (get mode 'derived-mode-parent)
+                                 nil t (cons mode checked-modes)))
+        (and follow-parent mode-alias
+             (get mode-alias 'derived-mode-parent)
+             (evil-initial-state (get mode-alias 'derived-mode-parent)
+                                 nil t (cons mode-alias checked-modes))))))
 
 (defun evil-set-initial-state (mode state)
   "Set the initial state for major mode MODE to STATE.
@@ -341,8 +313,7 @@ then this function does nothing."
   :suppress-operator t
   (with-current-buffer (or buffer (current-buffer))
     (when evil-local-mode
-      (evil-change-state (evil-initial-state-for-buffer
-                          buffer (or evil-default-state 'normal))
+      (evil-change-state (evil-initial-state-for-buffer buffer)
                          message))))
 
 (evil-define-command evil-change-to-previous-state
@@ -372,11 +343,11 @@ then this function does nothing."
     (when (get-buffer (ad-get-arg 1))
       (with-current-buffer (ad-get-arg 1)
         (unless evil-local-mode
-          (save-match-data (evil-local-mode 1)))))))
+          (save-match-data (evil-initialize)))))))
 
 ;; Refresh cursor color.
 ;; Cursor color can only be set for each frame but not for each buffer.
-(add-hook 'window-configuration-change-hook 'evil-refresh-cursor)
+(add-hook 'window-configuration-change-hook #'evil-refresh-cursor)
 (defadvice select-window (after evil activate)
   (evil-refresh-cursor))
 
@@ -450,18 +421,15 @@ then this function does nothing."
 
 (defmacro evil-without-input-method-hooks (&rest body)
   "Execute body with evil's activate/deactivate-input-method hooks deactivated.
-
 This allows input methods to be used in normal-state."
+  (declare (indent defun))
   `(unwind-protect
        (progn
-         (remove-hook 'input-method-activate-hook 'evil-activate-input-method 
t)
-         (remove-hook 'input-method-deactivate-hook
-                      'evil-deactivate-input-method t)
+         (remove-hook 'input-method-activate-hook #'evil-activate-input-method 
t)
+         (remove-hook 'input-method-deactivate-hook 
#'evil-deactivate-input-method t)
          ,@body)
-     (progn
-       (add-hook 'input-method-activate-hook 'evil-activate-input-method nil t)
-       (add-hook 'input-method-deactivate-hook
-                 'evil-deactivate-input-method nil t))))
+     (add-hook 'input-method-activate-hook #'evil-activate-input-method nil t)
+     (add-hook 'input-method-deactivate-hook #'evil-deactivate-input-method 
nil t)))
 
 (defadvice toggle-input-method (around evil)
   "Refresh `evil-input-method'."
@@ -540,16 +508,11 @@ may be specified before the body code:
       (setq key (pop body)
             arg (pop body))
       (cond
-       ((eq key :mode)
-        (setq mode arg))
-       ((eq key :local)
-        (setq local arg))
-       ((eq key :func)
-        (setq func arg))
-       ((eq key :intercept)
-        (setq intercept arg))
-       ((eq key :overriding)
-        (setq overriding arg))))
+       ((eq key :mode) (setq mode arg))
+       ((eq key :local) (setq local arg))
+       ((eq key :func) (setq func arg))
+       ((eq key :intercept) (setq intercept arg))
+       ((eq key :overriding) (setq overriding arg))))
     (setq mode (or mode
                    (intern (replace-regexp-in-string
                             "\\(?:-\\(?:mode-\\)?\\(?:key\\)?map\\)?$"
@@ -582,10 +545,8 @@ may be specified before the body code:
              ,@(when doc `(,doc))
              (interactive)
              (cond
-              ((numberp arg)
-               (setq ,mode (> arg 0)))
-              (t
-               (setq ,mode (not ,mode))))
+              ((numberp arg) (setq ,mode (> arg 0)))
+              (t (setq ,mode (not ,mode))))
              ,@body))
        ',keymap)))
 
@@ -924,14 +885,10 @@ If STATE is nil, it means any state."
   (let ((entry (and (keymapp map)
                     (lookup-key map [intercept-state]))))
     (cond
-     ((null entry)
-      nil)
-     ((null state)
-      map)
-     ((eq entry state)
-      map)
-     ((eq entry 'all)
-      map))))
+     ((null entry) nil)
+     ((null state) map)
+     ((eq entry state) map)
+     ((eq entry 'all) map))))
 
 (defun evil-overriding-keymap-p (map &optional state)
   "Whether MAP is an overriding keymap for STATE.
@@ -939,16 +896,11 @@ If STATE is nil, it means any state."
   (let ((entry (and (keymapp map)
                     (lookup-key map [override-state]))))
     (cond
-     ((null entry)
-      nil)
-     ((keymapp entry)
-      (evil-overriding-keymap-p entry state))
-     ((null state)
-      map)
-     ((eq entry state)
-      map)
-     ((eq entry 'all)
-      map))))
+     ((null entry) nil)
+     ((keymapp entry) (evil-overriding-keymap-p entry state))
+     ((null state) map)
+     ((eq entry state) map)
+     ((eq entry 'all) map))))
 
 (defun evil-intercept-keymap-state (map)
   "Return the state for the intercept keymap MAP.
@@ -1054,13 +1006,12 @@ mode, in which case `evil-define-minor-mode-key' is 
used."
                           `(keymapp ,keymap))
               '(condition-case-unless-debug err
                    (evil-define-key* ,state ,keymap ,key ,def ,@bindings)
-                 (error
-                  (message "error in evil-define-key: %s"
-                           (error-message-string err))))
+                 (error "error in evil-define-key: %s"
+                        (error-message-string err)))
             'after-load-functions t nil
             (format "evil-define-key-in-%s"
                     ',(if (symbolp keymap) keymap 'keymap))))))
-(defalias 'evil-declare-key 'evil-define-key)
+(defalias 'evil-declare-key #'evil-define-key)
 
 (defun evil-define-key* (state keymap key def &rest bindings)
   "Create a STATE binding from KEY to DEF for KEYMAP.
@@ -1342,8 +1293,7 @@ If ARG is nil, don't display a message in the echo 
area.%s" name doc)
              (evil-normalize-keymaps)
              ,@body))
           (t
-           (unless evil-local-mode
-             (evil-local-mode 1))
+           (unless evil-local-mode (evil-local-mode))
            (let ((evil-next-state ',state)
                  input-method-activate-hook
                  input-method-deactivate-hook)
diff --git a/evil-jumps.el b/evil-jumps.el
index 6c0203ca92..2e08f862a8 100644
--- a/evil-jumps.el
+++ b/evil-jumps.el
@@ -95,9 +95,8 @@ Otherwise the jump commands act only within the current 
buffer."
        (insert (apply #'format format args) "\n"))))
 
 (defun evil--jumps-get-current (&optional window)
-  (unless window
-    (setq window (frame-selected-window)))
-  (let* ((jump-struct (gethash window evil--jumps-window-jumps)))
+  (unless window (setq window (selected-window)))
+  (let ((jump-struct (gethash window evil--jumps-window-jumps)))
     (unless jump-struct
       (setq jump-struct (make-evil-jumps-struct))
       (puthash window jump-struct evil--jumps-window-jumps))
@@ -168,28 +167,28 @@ Otherwise the jump commands act only within the current 
buffer."
 
 (defun evil--jumps-push ()
   "Push the current cursor/file position to the jump list."
-  (let ((target-list (evil--jumps-get-window-jump-list)))
-    (let ((file-name (buffer-file-name))
-          (buffer-name (buffer-name))
-          (current-pos (point-marker))
-          (first-pos nil)
-          (first-file-name nil)
-          (excluded nil))
-      (when (and (not file-name)
-                 (string-match-p evil--jumps-buffer-targets buffer-name))
-        (setq file-name buffer-name))
-      (when file-name
-        (dolist (pattern evil-jumps-ignored-file-patterns)
-          (when (string-match-p pattern file-name)
-            (setq excluded t)))
-        (unless excluded
-          (unless (ring-empty-p target-list)
-            (setq first-pos (car (ring-ref target-list 0)))
-            (setq first-file-name (car (cdr (ring-ref target-list 0)))))
-          (unless (and (equal first-pos current-pos)
-                       (equal first-file-name file-name))
-            (evil--jumps-message "pushing %s on %s" current-pos file-name)
-            (ring-insert target-list `(,current-pos ,file-name))))))
+  (let ((target-list (evil--jumps-get-window-jump-list))
+        (file-name (buffer-file-name))
+        (buffer-name (buffer-name))
+        (current-pos (point-marker))
+        (first-pos nil)
+        (first-file-name nil)
+        (excluded nil))
+    (when (and (not file-name)
+               (string-match-p evil--jumps-buffer-targets buffer-name))
+      (setq file-name buffer-name))
+    (when file-name
+      (dolist (pattern evil-jumps-ignored-file-patterns)
+        (when (string-match-p pattern file-name)
+          (setq excluded t)))
+      (unless excluded
+        (unless (ring-empty-p target-list)
+          (setq first-pos (car (ring-ref target-list 0)))
+          (setq first-file-name (car (cdr (ring-ref target-list 0)))))
+        (unless (and (equal first-pos current-pos)
+                     (equal first-file-name file-name))
+          (evil--jumps-message "pushing %s on %s" current-pos file-name)
+          (ring-insert target-list `(,current-pos ,file-name)))))
     (evil--jumps-message "%s %s"
                          (selected-window)
                          (and (not (ring-empty-p target-list))
@@ -240,6 +239,7 @@ POS defaults to point."
       (when pos
         (goto-char pos))
       (evil--jumps-push))))
+(put 'evil-set-jump 'permanent-local-hook t)
 
 (defun evil--jump-backward (count)
   (setq evil--jumps-jumping-backward t)
@@ -288,6 +288,7 @@ POS defaults to point."
                  (evil--jumps-message "removing %s" key)
                  (remhash key evil--jumps-window-jumps)))
              evil--jumps-window-jumps)))
+(put 'evil--jumps-window-configuration-hook 'permanent-local-hook t)
 
 (defun evil--jump-hook (&optional command)
   "`pre-command-hook' for evil-jumps.
@@ -299,6 +300,7 @@ change the current buffer."
       (evil-set-jump)
     (setf (evil-jumps-struct-previous-pos (evil--jumps-get-current))
           (point-marker))))
+(put 'evil--jump-hook 'permanent-local-hook t)
 
 (defun evil--jump-handle-buffer-crossing ()
   (let ((jumping-backward evil--jumps-jumping-backward))
@@ -330,6 +332,7 @@ change the current buffer."
                         (not (eq previous-buffer (window-buffer window))))))
                 (evil-set-jump previous-pos)
               (set-marker previous-pos nil))))))))
+(put 'evil--jump-handle-buffer-crossing 'permanent-local-hook t)
 
 (if (bound-and-true-p savehist-loaded)
     (evil--jumps-savehist-load)
@@ -345,8 +348,7 @@ change the current buffer."
     (remove-hook 'pre-command-hook #'evil--jump-hook t)
     (remove-hook 'post-command-hook #'evil--jump-handle-buffer-crossing t)
     (remove-hook 'next-error-hook #'evil-set-jump t)
-    (remove-hook 'window-configuration-change-hook 
#'evil--jumps-window-configuration-hook t)
-    (evil--jump-handle-buffer-crossing)))
+    (remove-hook 'window-configuration-change-hook 
#'evil--jumps-window-configuration-hook t)))
 
 (add-hook 'evil-local-mode-hook #'evil--jumps-install-or-uninstall)
 
diff --git a/evil-states.el b/evil-states.el
index 05f46a571f..47ff9b227a 100644
--- a/evil-states.el
+++ b/evil-states.el
@@ -48,8 +48,7 @@ AKA \"Command\" state."
   "Reset command loop variables in Normal state.
 Also prevent point from reaching the end of the line.
 If the region is activated, enter Visual state."
-  (unless (or (evil-initializing-p)
-              (null this-command))
+  (unless (null this-command)
     (setq command (or command this-command))
     (when (evil-normal-state-p)
       (setq evil-this-type nil
@@ -449,17 +448,13 @@ or `block'."
 SELECTION is a kind of selection as defined by
 `evil-define-visual-selection', such as `char', `line'
 or `block'."
-  (let (message)
-    (setq selection (or selection evil-visual-selection))
-    (when selection
-      (setq message
-            (symbol-value (intern (format "evil-visual-%s-message"
-                                          selection))))
+  (unless selection (setq selection evil-visual-selection))
+  (when selection
+    (let ((message (symbol-value (intern (format "evil-visual-%s-message"
+                                                 selection)))))
       (cond
-       ((functionp message)
-        (funcall message))
-       ((stringp message)
-        (evil-echo "%s" message))))))
+       ((functionp message) (funcall message))
+       ((stringp message) (evil-echo "%s" message))))))
 
 (defun evil-visual-select (beg end &optional type dir message)
   "Create a Visual selection of type TYPE from BEG to END.
diff --git a/evil-tests.el b/evil-tests.el
index e2a637bd00..51eb5ab4a3 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -9328,7 +9328,7 @@ parameter set."
 ;;; ESC
 
 (ert-deftest evil-test-esc-count ()
-  "Test if prefix-argument is transfered for key sequences with meta-key"
+  "Test if prefix-argument is transferred for key sequences with meta-key"
   :tags '(evil esc)
   (unless noninteractive
     (ert-info ("Test M-<right>")
@@ -9370,11 +9370,10 @@ parameter set."
   (ert-info ("Execute yanked macro")
     (evil-test-buffer
       "[i]foo\e"
-      ("\"qd$@q\"qp"
-       "fooifoo\e")))
+      ("\"qD@q\"qp"
+      "fooifoo\e")))
   (ert-info ("Paste recorded marco")
     (evil-test-buffer
-      ""
       (evil-set-register ?q (vconcat "ifoo" [escape]))
       ("@q\"qp")
       "fooifoo\e")))
@@ -9453,14 +9452,14 @@ parameter set."
     (ert-info ("Jump across files")
       (let ((temp-file (make-temp-file "evil-test-")))
         (unwind-protect
-          (evil-test-buffer
-            "[z] z z z z z z"
-            ("\M-x" "find-file" [return] temp-file [return] "inew buffer" 
[escape])
-            "new buffe[r]"
-            ("\C-o")
-            "[z] z z z z z z"
-            ("\C-i")
-            "new buffe[r]")
+            (evil-test-buffer
+              "[z] z z z z z z"
+              ("\M-x" "find-file" [return] temp-file [return] "inew buffer" 
[escape])
+              "new buffe[r]"
+              ("\C-o")
+              "[z] z z z z z z"
+              ("\C-i")
+              "new buffe[r]")
           (delete-file temp-file)
           (with-current-buffer (get-file-buffer temp-file)
             (set-buffer-modified-p nil))
@@ -9708,7 +9707,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))))
-  (defalias 'test-1-alias-mode 'test-1-mode)
+  (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)
   (ert-info ("Check inheritance from major mode aliases")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]