Skip to content

Commit

Permalink
Bind all possible ex cmd abbreviations
Browse files Browse the repository at this point in the history
Means that :de expands to delete
  • Loading branch information
tomdl89 committed Jul 17, 2024
1 parent 81ec688 commit aeb670c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions evil-ex.el
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,20 @@ in case of incomplete or unknown commands."

(defun evil-ex-define-cmd (cmd function)
"Bind the function FUNCTION to the command CMD."
(if (string-match "\\[\\(.*\\)\\]" cmd)
(let ((abbrev (replace-match "" nil t cmd))
(full (replace-match "\\1" nil nil cmd)))
(evil--add-to-alist evil-ex-commands
full function
abbrev full))
(evil--add-to-alist evil-ex-commands cmd function)))
(cond ((not (string-match-p "\\[" cmd))
(evil--add-to-alist evil-ex-commands cmd function))
((string-match "\\]\\(.+\\)" cmd)
(user-error "Trailing characters in cmd definition: %s"
(match-string 1 cmd)))
((not (string-match-p "\\]" cmd))
(user-error "Missing ] in cmd definition: %s" cmd))
(t (string-match "\\(.*\\)\\[\\(.*\\)\\]" cmd)
(let ((mandatory (match-string 1 cmd))
(optional (match-string 2 cmd)))
(dotimes (n (1+ (length optional)))
(evil--add-to-alist evil-ex-commands
(concat mandatory (substring optional 0 n))
function))))))

(defmacro evil-ex-define-argument-type (arg-type doc &rest body)
"Define a new handler for argument-type ARG-TYPE.
Expand Down

0 comments on commit aeb670c

Please sign in to comment.