diff options
| author | Axel Forsman <axel@axelf.se> | 2023-08-08 21:56:53 +0200 |
|---|---|---|
| committer | Tom Dalziel <tom_dl@hotmail.com> | 2023-08-20 23:46:23 +0100 |
| commit | 1c4c3bfff8987aa498d6bb8bd88e2e4ba9615ab9 (patch) | |
| tree | 9f827e8ae63cd57f2e842d07c63bbd3c8b1e00b1 | |
| parent | a9a9c65b5d0777048c4e8a66fcc06032e3dafc18 (diff) | |
Some cleanups
| -rw-r--r-- | evil-command-window.el | 3 | ||||
| -rw-r--r-- | evil-commands.el | 289 | ||||
| -rw-r--r-- | evil-common.el | 23 | ||||
| -rw-r--r-- | evil-core.el | 43 | ||||
| -rw-r--r-- | evil-ex.el | 52 | ||||
| -rw-r--r-- | evil-maps.el | 10 | ||||
| -rw-r--r-- | evil-search.el | 58 | ||||
| -rw-r--r-- | evil-tests.el | 13 | ||||
| -rw-r--r-- | evil-vars.el | 3 |
9 files changed, 204 insertions, 290 deletions
diff --git a/evil-command-window.el b/evil-command-window.el index 68068a8..c364e41 100644 --- a/evil-command-window.el +++ b/evil-command-window.el @@ -44,8 +44,7 @@ (define-derived-mode evil-command-window-mode fundamental-mode "Evil-cmd" "Major mode for the Evil command line window." (auto-fill-mode 0) - (setq-local after-change-functions - (cons #'evil-command-window-draw-prefix after-change-functions))) + (add-hook 'after-change-functions #'evil-command-window-draw-prefix nil t)) (defun evil-command-window (history cmd-key execute-fn) "Open a command line window for HISTORY with CMD-KEY and EXECUTE-FN. diff --git a/evil-commands.el b/evil-commands.el index 40a0132..7dfc1e0 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -37,7 +37,6 @@ (require 'cl-lib) (require 'reveal) -(declare-function flyspell-overlay-p "flyspell") (declare-function imenu--in-alist "imenu") ;;; Motions @@ -215,10 +214,9 @@ move COUNT - 1 screen lines downward first." "Move the cursor to COUNT % of the width of the current line. If no COUNT is given, default to 50%." :type exclusive - (let ((line-length (- (line-end-position) - (line-beginning-position) + (let ((line-length (- (line-end-position) (line-beginning-position) (if evil-move-beyond-eol -1 0)))) - (move-to-column (truncate (* line-length (/ (or count 50) 100.0)))))) + (move-to-column (truncate (* line-length (or count 50)) 100)))) (evil-define-motion evil-first-non-blank () "Move the cursor to the first non-blank character of the current line." @@ -229,13 +227,9 @@ If no COUNT is given, default to 50%." "Move the cursor to the last non-blank character of the current line. If COUNT is given, move COUNT - 1 lines downward first." :type inclusive - (goto-char - (save-excursion - (evil-move-beginning-of-line count) - (if (re-search-forward "[ \t]*$") - (max (line-beginning-position) - (1- (match-beginning 0))) - (line-beginning-position))))) + (evil-move-end-of-line count) + (skip-chars-backward " \t") + (unless (bolp) (backward-char))) (evil-define-motion evil-first-non-blank-of-visual-line () "Move the cursor to the first non blank character @@ -498,30 +492,28 @@ and jump to the corresponding one." (t (let* ((open (point-max)) (close (point-max)) - (open-pair (condition-case nil - (save-excursion - ;; consider the character right before eol given that - ;; point may be placed there, e.g. in visual state - (when (and (eolp) (not (bolp))) - (backward-char)) - (setq open (1- (scan-lists (point) 1 -1))) - (when (< open (line-end-position)) - (goto-char open) - (forward-list) - (1- (point)))) - (error nil))) - (close-pair (condition-case nil - (save-excursion - ;; consider the character right before eol given that - ;; point may be placed there, e.g. in visual state - (when (and (eolp) (not (bolp))) - (backward-char)) - (setq close (1- (scan-lists (point) 1 1))) - (when (< close (line-end-position)) - (goto-char (1+ close)) - (backward-list) - (point))) - (error nil)))) + (open-pair (ignore-errors + (save-excursion + ;; consider the character right before eol given that + ;; point may be placed there, e.g. in visual state + (when (and (eolp) (not (bolp))) + (backward-char)) + (setq open (1- (scan-lists (point) 1 -1))) + (when (< open (line-end-position)) + (goto-char open) + (forward-list) + (1- (point)))))) + (close-pair (ignore-errors + (save-excursion + ;; consider the character right before eol given that + ;; point may be placed there, e.g. in visual state + (when (and (eolp) (not (bolp))) + (backward-char)) + (setq close (1- (scan-lists (point) 1 1))) + (when (< close (line-end-position)) + (goto-char (1+ close)) + (backward-list) + (point)))))) (cond ((not (or open-pair close-pair)) ;; nothing found, check if we are inside a string @@ -548,6 +540,7 @@ and jump to the corresponding one." ((< open close) (goto-char open-pair)) (t (goto-char close-pair))))))) +(declare-function flyspell-overlay-p "flyspell") (evil-define-motion evil-next-flyspell-error (count) "Go to the COUNT'th spelling mistake after point." :jump t @@ -608,27 +601,16 @@ and jump to the corresponding one." (defun evil--next-mark (forwardp) "Move to next lowercase mark. -Move forward if FORWARDP is truthy or backward if falsey. -Loop back to the top of buffer if the end is reached." - (let ((pos (point)) - (sorted-markers (sort (evil--lowercase-markers) - (lambda (a b) (< (cdr a) (cdr b)))))) - (cond - ((null sorted-markers) - (user-error "No marks in this buffer")) - (forwardp - (let ((next-marker (cl-some (lambda (x) (and (< pos (cdr x)) (cdr x))) - sorted-markers))) - (if next-marker - (goto-char (marker-position next-marker)) - (goto-char (marker-position (cdar sorted-markers)))))) - (t - (let* ((descending-markers (reverse sorted-markers)) - (prev-marker (cl-some (lambda (x) (and (> pos (cdr x)) (cdr x))) - descending-markers))) - (if prev-marker - (goto-char (marker-position prev-marker)) - (goto-char (marker-position (cdar descending-markers))))))))) +Move forward if FORWARDP is non-nil, and backward otherwise. Loop back +to the beginning of buffer if the end is reached." + (let* ((pos (if forwardp (1+ (point)) (point))) + (centered-markers + (cl-sort + (or (evil--lowercase-markers) (user-error "No marks in this buffer")) + (if forwardp #'< #'>) + :key (lambda (x) (+ (if (< (cdr x) pos) 0 most-negative-fixnum) + (cdr x)))))) + (goto-char (cdar centered-markers)))) (evil-define-motion evil-next-mark (count) "Go to COUNT next lowercase mark." @@ -645,12 +627,11 @@ Loop back to the top of buffer if the end is reached." :repeat nil :type exclusive :jump t - (if (evil--lowercase-markers) - (dotimes (_ (or count 1)) - (evil-end-of-line) - (evil--next-mark t) - (evil-first-non-blank)) - (user-error "No marks in this buffer"))) + (unless (evil--lowercase-markers) (user-error "No marks in this buffer")) + (dotimes (_ (or count 1)) + (move-end-of-line nil) + (evil--next-mark t)) + (evil-first-non-blank)) (evil-define-motion evil-previous-mark (count) "Go to COUNT previous lowercase mark." @@ -667,15 +648,15 @@ Loop back to the top of buffer if the end is reached." :repeat nil :type exclusive :jump t - (if (evil--lowercase-markers) - (dotimes (_ (or count 1)) - (evil-beginning-of-line) - (evil--next-mark nil) - (evil-first-non-blank)) - (user-error "No marks in this buffer"))) + (unless (evil--lowercase-markers) (user-error "No marks in this buffer")) + (dotimes (_ (or count 1)) + (move-beginning-of-line nil) + (evil--next-mark nil)) + (evil-first-non-blank)) (evil-define-command evil-set-col-0-mark (beg end mark) - "Set MARK at column 0 of line of END. Default is cursor line." + "Set MARK at column 0 of line of END. +Default is cursor line." (interactive "<r><a>") (if (< 1 (length mark)) (user-error "Trailing characters") @@ -686,7 +667,8 @@ Loop back to the top of buffer if the end is reached." (evil-define-motion evil-find-char (count char) "Move to the next COUNT'th occurrence of CHAR. -Movement is restricted to the current line unless `evil-cross-lines' is non-nil." +Movement is restricted to the current line unless `evil-cross-lines' +is non-nil." :type inclusive (interactive "<c><C>") (setq count (or count 1)) @@ -725,12 +707,11 @@ Movement is restricted to the current line unless `evil-cross-lines' is non-nil. :type inclusive (interactive "<c><C>") (unwind-protect - (progn - (evil-find-char count char) - (if (> (or count 1) 0) - (backward-char) - (forward-char))) - (setcar evil-last-find #'evil-find-char-to))) + (evil-find-char count char) + (setcar evil-last-find #'evil-find-char-to)) + (if (> (or count 1) 0) + (backward-char) + (forward-char))) (evil-define-motion evil-find-char-to-backward (count char) "Move before the previous COUNT'th occurrence of CHAR." @@ -742,26 +723,22 @@ Movement is restricted to the current line unless `evil-cross-lines' is non-nil. "Repeat the last find COUNT times." :type inclusive (setq count (or count 1)) - (if evil-last-find - (let ((cmd (car evil-last-find)) - (char (nth 1 evil-last-find)) - (fwd (nth 2 evil-last-find)) - evil-last-find) - ;; ensure count is non-negative - (when (< count 0) - (setq count (- count) - fwd (not fwd))) - ;; skip next character when repeating t or T - (and (eq cmd #'evil-find-char-to) - evil-repeat-find-to-skip-next - (= count 1) - (or (and fwd (= (char-after (1+ (point))) char)) - (and (not fwd) (= (char-before) char))) - (setq count (1+ count))) - (funcall cmd (if fwd count (- count)) char) - (unless (nth 2 evil-last-find) - (setq evil-this-type 'exclusive))) - (user-error "No previous search"))) + (cl-destructuring-bind (cmd char fwd) + (or evil-last-find (user-error "No previous search")) + ;; ensure count is non-negative + (when (< count 0) + (setq count (- count) + fwd (not fwd))) + ;; skip next character when repeating t or T + (and (eq cmd #'evil-find-char-to) + evil-repeat-find-to-skip-next + (= count 1) + (eql (if fwd (char-after (1+ (point))) (char-before)) char) + (setq count (1+ count))) + (let (evil-last-find) + (funcall cmd (if fwd count (- count)) char) + (unless (nth 2 evil-last-find) + (setq evil-this-type 'exclusive))))) (evil-define-motion evil-repeat-find-char-reverse (count) "Repeat the last find COUNT times in the opposite direction." @@ -2007,9 +1984,7 @@ If a `#' is included before the mark args, the lines are numbered." :move-point nil :type line (save-excursion - (condition-case nil - (fill-region beg end) - (error nil)))) + (ignore-errors (fill-region beg end)))) (evil-define-operator evil-fill-and-move (beg end) "Fill text and move point to the end of the filled region." @@ -2017,12 +1992,10 @@ If a `#' is included before the mark args, the lines are numbered." :type line (let ((marker (make-marker))) (move-marker marker (1- end)) - (condition-case nil - (progn - (fill-region beg end) - (goto-char marker) - (evil-first-non-blank)) - (error nil)))) + (ignore-errors + (fill-region beg end) + (goto-char marker) + (evil-first-non-blank)))) (evil-define-operator evil-indent (beg end) "Indent text." @@ -2421,26 +2394,23 @@ leave the cursor just after the new text." (defun evil-paste-from-register (register) "Paste from REGISTER." (interactive - (let* ((opoint (point)) - (overlay (make-overlay opoint (+ opoint (if (evil-replace-state-p) 1 0))))) + (let ((ov (make-overlay (point) (+ (point) (if (evil-replace-state-p) 1 0))))) (unwind-protect (progn - (overlay-put overlay 'invisible t) - (overlay-put overlay 'after-string (propertize "\"" - 'face 'minibuffer-prompt - 'cursor 1)) + (overlay-put ov 'invisible t) + (overlay-put ov 'after-string + #("\"" 0 1 (face minibuffer-prompt cursor 1))) (list (or evil-this-register (read-char)))) - (delete-overlay overlay)))) + (delete-overlay ov)))) (let ((opoint (point)) - (evil-move-cursor-back nil) - reg-length chars-to-delete) + evil-move-cursor-back) (evil-paste-before nil register t) (when (evil-replace-state-p) - (setq reg-length (- (point) opoint) - chars-to-delete (min (- (line-end-position) (point)) reg-length)) - ;; TODO: handle multi-line paste backspacing - (evil-update-replace-alist (point) reg-length chars-to-delete chars-to-delete) - (delete-char chars-to-delete)))) + (let* ((reg-length (- (point) opoint)) + (chars-to-delete (min (- (line-end-position) (point)) reg-length))) + ;; TODO: handle multi-line paste backspacing + (evil-update-replace-alist (point) reg-length chars-to-delete chars-to-delete) + (delete-char chars-to-delete))))) (defun evil-paste-last-insertion () "Paste last insertion." @@ -2496,10 +2466,8 @@ will be opened instead." ((eq register ?\C-g) (keyboard-quit)) ((and evil-this-macro defining-kbd-macro) - (setq evil-macro-buffer nil) - (condition-case nil - (setq last-macro (evil-end-and-return-macro)) - (error nil)) + (setq evil-macro-buffer nil + last-macro (ignore-errors (evil-end-and-return-macro))) (when last-macro (evil-set-register evil-this-macro last-macro)) (setq evil-this-macro nil)) @@ -2771,26 +2739,23 @@ switch to insert state." (defun evil-quoted-insert (count) "Like `quoted-insert' but delete COUNT chars forward in replace state. -Adds a `^' overlay as an input prompt." +Adds a \"^\" overlay as an input prompt." (interactive "p") (let* ((opoint (point)) - chars-to-delete insert-prompt) + chars-to-delete + (ov (if (not (evil-replace-state-p)) + (make-overlay opoint opoint) + (setq chars-to-delete (min (- (line-end-position) opoint) count)) + (evil-update-replace-alist opoint count chars-to-delete) + (make-overlay opoint (+ chars-to-delete opoint))))) (unwind-protect (progn - (if (evil-replace-state-p) - (progn - (setq chars-to-delete (min (- (line-end-position) opoint) count) - insert-prompt (make-overlay opoint (+ chars-to-delete opoint))) - (evil-update-replace-alist opoint count chars-to-delete)) - (setq insert-prompt (make-overlay opoint opoint))) - (overlay-put insert-prompt 'invisible t) - (overlay-put insert-prompt 'after-string (propertize "^" - 'face 'escape-glyph - 'cursor 1)) - (let (overwrite-mode) ;; Force `read-quoted-char' + (overlay-put ov 'invisible t) + (overlay-put ov 'after-string #("^" 0 1 (face escape-glyph cursor 1))) + (let (overwrite-mode) ; Force `read-quoted-char' (quoted-insert count)) - (when (evil-replace-state-p) (delete-char chars-to-delete))) - (when insert-prompt (delete-overlay insert-prompt))))) + (when chars-to-delete (delete-char chars-to-delete))) + (delete-overlay ov)))) (evil-define-command evil-open-above (count) "Insert a new line above point and switch to Insert state. @@ -3192,10 +3157,9 @@ The search is unbounded, i.e., the pattern is not wrapped in (let ((identifier (save-excursion (goto-char position) (xref-backend-identifier-at-point (xref-find-backend))))) - (condition-case () - (progn - (xref-find-definitions identifier) - t) + (condition-case nil + (progn (xref-find-definitions identifier) + t) (user-error nil))))) (defun evil-goto-definition-search (string _position) @@ -3400,8 +3364,7 @@ files." (evil-define-command evil-goto-error (count) "Go to error number COUNT. - -If no COUNT supplied, move to the current error. +If no COUNT is supplied, move to the current error. Acts like `first-error' other than when given no counts, goes to the current error instead of the first, like in Vim's :cc @@ -3461,17 +3424,12 @@ for the last window in each frame." ;; if the buffer which was initiated by emacsclient, ;; call `server-edit' from server.el to avoid ;; "Buffer still has clients" message - (if (and (fboundp 'server-edit) - (boundp 'server-buffer-clients) - server-buffer-clients) + (if (and (bound-and-true-p server-buffer-clients) + (fboundp 'server-edit)) (server-edit) (kill-buffer nil)) ;; close all windows that showed this buffer - (mapc #'(lambda (w) - (condition-case nil - (delete-window w) - (error nil))) - wins)))) + (dolist (w wins) (ignore-errors (delete-window w)))))) (evil-define-command evil-quit (&optional force) "Close the current window, current frame, current tab, Emacs. @@ -3482,10 +3440,9 @@ is closed." (condition-case nil (delete-window) (error - (if (and (boundp 'server-buffer-clients) + (if (and (bound-and-true-p server-buffer-clients) (fboundp 'server-edit) - (fboundp 'server-buffer-done) - server-buffer-clients) + (fboundp 'server-buffer-done)) (if force (server-buffer-done (current-buffer)) (server-edit)) @@ -3519,10 +3476,7 @@ The FORCE argument is only there for compatibility and is ignored. This function fails with an error if Emacs is run in server mode." :repeat nil (interactive "<!>") - (if (and (boundp 'server-buffer-clients) - (fboundp 'server-edit) - (fboundp 'server-buffer-done) - server-buffer-clients) + (if (bound-and-true-p server-buffer-clients) (user-error "Cannot exit client process with error code.") (kill-emacs 1))) @@ -4525,17 +4479,14 @@ the deleted window's parent window are rebalanced." (let ((p (window-parent))) ;; If tabs are enabled and this is the only visible window, then attempt to ;; close this tab. - (if (and (boundp 'tab-bar-mode) - tab-bar-mode - (not p)) + (if (and (bound-and-true-p tab-bar-mode) + (null p)) (tab-close) - (delete-window)) - (when evil-auto-balance-windows - ;; balance-windows raises an error if the parent does not have - ;; any further children (then rebalancing is not necessary anyway) - (condition-case nil - (balance-windows p) - (error))))) + (delete-window) + (when evil-auto-balance-windows + ;; balance-windows raises an error if the parent does not have + ;; any further children (then rebalancing is not necessary anyway) + (ignore-errors (balance-windows p)))))) (evil-define-command evil-window-split (&optional count file) "Split the current window horizontally, COUNT lines height, diff --git a/evil-common.el b/evil-common.el index 9af0863..84b0817 100644 --- a/evil-common.el +++ b/evil-common.el @@ -35,7 +35,6 @@ (declare-function evil-visual-restore "evil-states") (declare-function evil-motion-state "evil-states") (declare-function evil-replace-state-p "evil-states") -(declare-function evil-ex-p "evil-ex") (declare-function evil-set-jump "evil-jumps") ;;; Compatibility with different Emacs versions @@ -58,8 +57,8 @@ If LOCAL is non-nil, the buffer-local value of HOOK is modified." (cl-destructuring-bind (hook-sym &optional append local name) (mapcar #'macroexp-quote (if (consp hook) hook (list hook))) (macroexp-let2* nil - ((fun-name `',(make-symbol - (or name (format "evil-delay-in-%s" hook-sym)))) + ((fun-name `(make-symbol + ,(or name (format "evil-delay-in-%s" hook-sym)))) (fun `(lambda (&rest _) (when ,(or condition t) (remove-hook ,hook-sym ,fun-name ,local) @@ -762,15 +761,14 @@ cursor type is either `evil-force-cursor' or the current state." (defmacro evil-save-cursor (&rest body) "Save the current cursor; execute BODY; restore the cursor." - (declare (indent defun) - (debug t)) + (declare (indent defun) (debug t) (obsolete nil "1.15.0")) `(let ((cursor cursor-type) (color (frame-parameter (selected-frame) 'cursor-color)) (inhibit-quit t)) (unwind-protect (progn ,@body) - (evil-set-cursor cursor) - (evil-set-cursor color)))) + (setq cursor-type cursor) + (evil-set-cursor-color color)))) (defun evil-echo (string &rest args) "Display an unlogged message in the echo area. @@ -798,15 +796,12 @@ Does not restore if `evil-write-echo-area' is non-nil." (defmacro evil-save-echo-area (&rest body) "Save the echo area; execute BODY; restore the echo area. Intermittent messages are not logged in the *Messages* buffer." - (declare (indent defun) - (debug t)) + (declare (indent defun) (debug t)) `(let ((inhibit-quit t) - evil-echo-area-message - evil-write-echo-area) + evil-echo-area-message evil-write-echo-area) + (evil-echo-area-save) (unwind-protect - (progn - (evil-echo-area-save) - ,@body) + (progn ,@body) (evil-echo-area-restore)))) (defmacro evil-without-display (&rest body) diff --git a/evil-core.el b/evil-core.el index 22b6654..23937e7 100644 --- a/evil-core.el +++ b/evil-core.el @@ -225,15 +225,10 @@ Restore the previous state afterwards." (evil-change-state ',state) ,@body))) -(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'. +(defun evil-initialize-state () + "Set up the initial state for the current buffer. See also `evil-set-initial-state'." - (with-current-buffer (or buffer (current-buffer)) - (evil-change-state - (or state (evil-initial-state-for-buffer buffer))))) -(put 'evil-initialize-state 'permanent-local-hook t) + (evil-change-state (evil-initial-state-for-buffer))) (defun evil-initial-state-for-buffer-name (&optional name default) "Return the initial Evil state to use for a buffer with name NAME. @@ -254,17 +249,12 @@ Matches the name against the regular expressions in (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'." +BUFFER defaults to the current buffer. See also `evil-initial-state'." (with-current-buffer (or buffer (current-buffer)) (or (evil-initial-state-for-buffer-name) - (catch 'done - (dolist (mode minor-mode-map-alist) - (setq mode (car mode)) - (and (boundp mode) (symbol-value mode) - (setq mode (evil-initial-state mode)) - (throw 'done mode)))) + (cl-loop for (mode) in minor-mode-map-alist + when (and (boundp mode) (symbol-value mode)) + thereis (evil-initial-state mode)) (evil-initial-state major-mode nil t) evil-default-state))) @@ -340,11 +330,10 @@ then this function does nothing." ;; otherwise, though, so advise this function to initialize Evil. (defadvice set-window-buffer (before evil) "Initialize Evil in the displayed buffer." - (when evil-mode - (when (get-buffer (ad-get-arg 1)) - (with-current-buffer (ad-get-arg 1) - (unless evil-local-mode - (save-match-data (evil-initialize))))))) + (when (and evil-mode (get-buffer (ad-get-arg 1))) + (with-current-buffer (ad-get-arg 1) + (unless evil-local-mode + (save-match-data (evil-initialize)))))) ;; Refresh cursor color. ;; Cursor color can only be set for each frame but not for each buffer. @@ -452,7 +441,7 @@ This allows input methods to be used in normal-state." "Initialize a buffer-local value for local keymaps as necessary. The initial value is that of `make-sparse-keymap'." (dolist (entry evil-local-keymaps-alist) - (let ((map (cdr entry))) + (let ((map (cdr entry))) (unless (and (keymapp (symbol-value map)) (local-variable-p map)) (set map (make-sparse-keymap)))))) @@ -813,7 +802,6 @@ If AUX is nil, create a new auxiliary keymap." (format "%s state" state))))) (define-key map (vector (intern (format "%s-state" state))) aux) aux) -(put 'evil-set-auxiliary-keymap 'lisp-indent-function 'defun) (defun evil-get-auxiliary-keymap (map state &optional create ignore-parent) "Get the auxiliary keymap for MAP in STATE. @@ -1284,9 +1272,7 @@ If ARG is nil, don't display a message in the echo area.%s" name doc) (deactivate-input-method))) (unless evil-no-display (evil-refresh-cursor ',state) - (evil-refresh-mode-line ',state) - (when (called-interactively-p 'any) - (redisplay))) + (evil-refresh-mode-line ',state)) ,@body (run-hooks ',entry-hook) (when (and evil-echo-state @@ -1295,8 +1281,7 @@ If ARG is nil, don't display a message in the echo area.%s" name doc) (funcall ,message) (evil-echo "%s" ,message)))))))) - (evil-set-command-property ',toggle :keep-visual t) - (evil-set-command-property ',toggle :suppress-operator t) + (evil-add-command-properties ',toggle :keep-visual t :suppress-operator t) (evil-define-keymap ,keymap nil :mode ,mode @@ -44,7 +44,6 @@ (require 'evil-common) (require 'evil-states) -(require 'evil-types) (declare-function evil-goto-line "evil-commands") @@ -77,10 +76,9 @@ #'(evil-ex-char-marker-range $2 $4))) (line ((\? base) (\? offset) search (\? offset) - #'(let ((tmp (evil-ex-line $1 $2))) - (save-excursion - (goto-line tmp) - (evil-ex-line $3 $4)))) + #'(save-excursion + (goto-line (evil-ex-line $1 $2)) + (evil-ex-line $3 $4))) (base (\? offset) #'evil-ex-line) (nil offset #'evil-ex-line)) (base @@ -306,6 +304,9 @@ The following symbols have reserved meanings within a grammar: (defvar evil-ex-argument-types nil "Association list of argument handlers.") +(defvar evil-ex-commands nil + "Association list of command bindings and functions.") + (defvar evil-ex-reverse-range nil "Whether the current Ex range was entered reversed.") @@ -399,8 +400,9 @@ symbol, which defaults to `expression'." #'delete-backward-char #'abort-recursive-edit))) -(define-obsolete-function-alias - 'evil-ex-elisp-completion-at-point #'elisp-completion-at-point "1.15.0") +(cl-defstruct (evil-ex-argument-handler (:type list) (:constructor nil) + (:copier nil) (:predicate nil)) + (runner nil :read-only t) (completer nil :read-only t)) (defun evil-ex-setup () "Initialize Ex minibuffer. @@ -413,10 +415,9 @@ actions during Ex state." (defun evil-ex-teardown () "Deinitialize Ex minibuffer. Clean up everything set up by `evil-ex-setup'." - (when evil--ex-argument-handler - (let ((runner (evil-ex-argument-handler-runner - evil--ex-argument-handler))) - (when runner (funcall runner 'stop))))) + (let ((runner (evil-ex-argument-handler-runner + evil--ex-argument-handler))) + (when runner (funcall runner 'stop)))) (put 'evil-ex-teardown 'permanent-local-hook t) (defsubst evil--ex-bang-p (command) @@ -489,13 +490,10 @@ in case of incomplete or unknown commands." (defun evil--ex-remove-echo-overlay () "Remove echo overlay from Ex minibuffer." - (when evil--ex-echo-overlay - (delete-overlay evil--ex-echo-overlay) - (setq evil--ex-echo-overlay nil)) + (delete-overlay evil--ex-echo-overlay) + (setq evil--ex-echo-overlay nil) (remove-hook 'pre-command-hook #'evil--ex-remove-echo-overlay t)) -(define-obsolete-function-alias 'evil-ex-completion #'completion-at-point "1.15.0") - (cl-defun evil-ex-completion-at-point () "Function used for `completion-at-point-functions' in Ex state." (cl-flet ((fix-beg (b) (min (save-excursion @@ -526,9 +524,6 @@ in case of incomplete or unknown commands." (`((expression) (sexp . ,_)) (when (fboundp 'elisp-completion-at-point) (elisp-completion-at-point)))))) -(define-obsolete-function-alias - 'evil-ex-command-completion-at-point #'evil-ex-completion-at-point "1.15.0") - (defun evil-ex-completion-table () (let ((ex-cmds (cl-loop @@ -577,10 +572,18 @@ in case of incomplete or unknown commands." (p2 (eq (get-text-property 0 'face str2) 'evil-ex-commands))) (if (eq p1 p2) (string< str1 str2) p1))))) +(define-obsolete-function-alias 'evil-ex-completion #'completion-at-point "1.15.0") + +(define-obsolete-function-alias + 'evil-ex-command-completion-at-point #'evil-ex-completion-at-point "1.15.0") + (defalias 'evil-ex-argument-completion-at-point #'ignore) (make-obsolete 'evil-ex-argument-completion-at-point #'evil-ex-completion-at-point "1.15.0") +(define-obsolete-function-alias + 'evil-ex-elisp-completion-at-point #'elisp-completion-at-point "1.15.0") + (defun evil-ex-define-cmd (cmd function) "Bind the function FUNCTION to the command CMD." (if (string-match "\\[\\(.*\\)\\]" cmd) @@ -591,15 +594,6 @@ in case of incomplete or unknown commands." abbrev full)) (evil--add-to-alist evil-ex-commands cmd function))) -(defsubst evil-ex-make-argument-handler (runner completer) - (list runner completer)) - -(defun evil-ex-argument-handler-runner (arg-handler) - (car arg-handler)) - -(defun evil-ex-argument-handler-completer (arg-handler) - (cadr arg-handler)) - (defmacro evil-ex-define-argument-type (arg-type doc &rest body) "Define a new handler for argument-type ARG-TYPE. DOC is the documentation string. It is followed by a list of keywords @@ -835,7 +829,7 @@ This function interprets special file names like # and %." (defun evil-ex-last-visual-range () "Return a linewise range of the last visual selection." - (evil-line-expand evil-visual-mark evil-visual-point)) + (evil-range evil-visual-mark evil-visual-point 'line)) (defun evil-ex-marker (marker) "Return MARKER's line number in the current buffer. diff --git a/evil-maps.el b/evil-maps.el index 678ebfd..fbf5af1 100644 --- a/evil-maps.el +++ b/evil-maps.el @@ -25,14 +25,14 @@ ;; You should have received a copy of the GNU General Public License ;; along with Evil. If not, see <http://www.gnu.org/licenses/>. +;;; Code: + (require 'evil-states) (require 'evil-ex) (require 'evil-commands) (require 'evil-command-window) (require 'evil-common) -;;; Code: - ;;; Normal state (define-key evil-normal-state-map "a" 'evil-append) @@ -668,10 +668,8 @@ included in `evil-insert-state-bindings' by default." (define-key evil-read-key-map "\r" "\n") ;; command line window -(evil-define-key 'normal - evil-command-window-mode-map (kbd "RET") 'evil-command-window-execute) -(evil-define-key 'insert - evil-command-window-mode-map (kbd "RET") 'evil-command-window-execute) +(evil-define-key* '(normal insert) evil-command-window-mode-map + (kbd "RET") 'evil-command-window-execute) (provide 'evil-maps) diff --git a/evil-search.el b/evil-search.el index b81a7e2..d4f870b 100644 --- a/evil-search.el +++ b/evil-search.el @@ -389,9 +389,7 @@ letter, otherwise it will be case-insensitive." ((string-match "\\(?:^\\|[^\\\\]\\)\\(?:\\\\\\\\\\)*\\\\\\([cC]\\)" re) (if (eq (aref (match-string 1 re) 0) ?c) 'insensitive 'sensitive)) ((eq default-case 'smart) - (if (isearch-no-upper-case-p re t) - 'insensitive - 'sensitive)) + (if (isearch-no-upper-case-p re t) 'insensitive 'sensitive)) (t default-case))) ;; a pattern @@ -399,17 +397,15 @@ letter, otherwise it will be case-insensitive." "Create a PATTERN for substitution with FLAGS. This function respects the values of `evil-ex-substitute-case' and `evil-ex-substitute-global'." - (evil-ex-make-pattern regexp - (cond - ((memq ?i flags) 'insensitive) - ((memq ?I flags) 'sensitive) - ((not evil-ex-substitute-case) - evil-ex-search-case) - (t evil-ex-substitute-case)) - (or (and evil-ex-substitute-global - (not (memq ?g flags))) - (and (not evil-ex-substitute-global) - (memq ?g flags))))) + (evil-ex-make-pattern + regexp + (cond ((memq ?i flags) 'insensitive) + ((memq ?I flags) 'sensitive) + ((not evil-ex-substitute-case) evil-ex-search-case) + (t evil-ex-substitute-case)) + (if (memq ?g flags) + (not evil-ex-substitute-global) + evil-ex-substitute-global))) (defun evil-ex-make-search-pattern (regexp) "Create a PATTERN for search. @@ -433,15 +429,14 @@ style regular expression and is not transformed." ;; possibly transform regular expression from vim-style to ;; Emacs-style. (if (and evil-ex-search-vim-style-regexp - (not (or (string-match-p "\\`\\\\_<" regexp) - (string-match-p "\\\\_>\\'" regexp)))) + (not (or (string-prefix-p "\\_<" regexp) + (string-suffix-p "\\_>" regexp)))) (setq re (evil-transform-vim-style-regexp re)) ;; Even for Emacs regular expressions we translate certain ;; whitespace sequences - (setq re (evil-transform-regexp re - '((?t . "\t") - (?n . "\n") - (?r . "\r"))))) + (setq re (evil-transform-regexp re '((?t . "\t") + (?n . "\n") + (?r . "\r"))))) (list re ignore-case whole-line))) (defun evil-ex-pattern-regex (pattern) @@ -716,20 +711,20 @@ This function does nothing if `evil-ex-search-interactive' or (evil-ex-hl-change 'evil-ex-search pattern))))) (defun evil-ex-search (&optional count) - "Search forward or backward COUNT times for the current ex search pattern. -The search pattern is determined by `evil-ex-search-pattern' and -the direcion is determined by `evil-ex-search-direction'." + "Search forward or backward COUNT times for the current Ex search pattern. +The search pattern is determined by `evil-ex-search-pattern', and the +direction by `evil-ex-search-direction'." (setq evil-ex-search-start-point (point) evil-ex-last-was-search t count (or count 1)) (let ((orig (point)) wrapped) (dotimes (_ (or count 1)) - (when (eq evil-ex-search-direction 'forward) - (unless (eobp) (forward-char)) + (when (and (eq evil-ex-search-direction 'forward) (not (eobp))) + (forward-char) ;; maybe skip end-of-line - (when (and (not evil-move-beyond-eol) (eolp) (not (eobp))) - (forward-char))) + (and (not evil-move-beyond-eol) (eolp) (not (eobp)) + (forward-char))) (let ((res (evil-ex-find-next nil nil (not evil-search-wrap)))) (cond ((not res) @@ -1040,10 +1035,11 @@ current search result." evil-ex-search-match-end (match-end 0)) (evil-ex-search-goto-offset offset) (evil-push-search-history search-string (eq direction 'forward)) - (when (and (not evil-ex-search-incremental) evil-ex-search-highlight-all) - (evil-ex-search-activate-highlight pattern)) - (when (and evil-ex-search-incremental (not evil-ex-search-persistent-highlight)) - (evil-ex-delete-hl 'evil-ex-search))) + (if evil-ex-search-incremental + (unless evil-ex-search-persistent-highlight + (evil-ex-delete-hl 'evil-ex-search)) + (when evil-ex-search-highlight-all + (evil-ex-search-activate-highlight pattern)))) (t (goto-char evil-ex-search-start-point) (evil-ex-delete-hl 'evil-ex-search) diff --git a/evil-tests.el b/evil-tests.el index cacc1b5..b1b3f79 100644 --- a/evil-tests.el +++ b/evil-tests.el @@ -85,22 +85,21 @@ (defun evil-tests-initialize (&optional tests profiler interactive) (setq profiler (or profiler evil-tests-profiler)) - (when (listp profiler) + (when (consp profiler) (setq profiler (car profiler))) (when profiler (setq evil-tests-profiler t) (setq profiler - (or (cdr (assq profiler - '((call . elp-sort-by-call-count) - (average . elp-sort-by-average-time) - (total . elp-sort-by-total-time)))))) + (cdr (assq profiler + '((call . elp-sort-by-call-count) + (average . elp-sort-by-average-time) + (total . elp-sort-by-total-time))))) (setq elp-sort-by-function (or profiler 'elp-sort-by-call-count)) (elp-instrument-package "evil")) (if interactive (if (y-or-n-p-with-timeout "Run tests? " 2 t) (evil-tests-run tests interactive) - (message "You can run the tests at any time \ -with `M-x evil-tests-run'")) + (message "You can run the tests at any time with `M-x evil-tests-run'")) (evil-tests-run tests))) (defun evil-tests-run (&optional tests interactive) diff --git a/evil-vars.el b/evil-vars.el index 47a2a3d..f9de907 100644 --- a/evil-vars.el +++ b/evil-vars.el @@ -1903,9 +1903,6 @@ Key sequences bound in this map are immediately executed.") This content of this variable is appended to the Ex command line when Ex is started interactively.") -(defvar evil-ex-commands nil - "Association list of command bindings and functions.") - (defvar evil-ex-history nil "History of Ex commands.") |
