Skip to content

Commit

Permalink
Some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
axelf4 committed Aug 12, 2023
1 parent b291039 commit 0cbd61f
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 290 deletions.
3 changes: 1 addition & 2 deletions evil-command-window.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
289 changes: 120 additions & 169 deletions evil-commands.el

Large diffs are not rendered by default.

23 changes: 9 additions & 14 deletions evil-common.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))))

This comment has been minimized.

Copy link
@dankessler

dankessler Aug 12, 2023

Somehow this seems to very badly break emacs for some spacemacs users (and maybe others, too); see syl20bnr/spacemacs#16119.

I don't know elisp well enough to immediately see what went wrong, but I wanted to flag it ASAP.

This comment has been minimized.

Copy link
@axelf4

axelf4 Aug 13, 2023

Author Collaborator

Sorry about that, it should be fixed now. The issue was that expanding the macro in a file not using lexical scoping would lead to fun-name not being captured by the lambda as a closure.

((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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
43 changes: 14 additions & 29 deletions evil-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)))

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))))))
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
52 changes: 23 additions & 29 deletions evil-ex.el
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

(require 'evil-common)
(require 'evil-states)
(require 'evil-types)

(declare-function evil-goto-line "evil-commands")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions evil-maps.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 0cbd61f

Please sign in to comment.