From aeb670c012bdf3307f276504717dfcf3520ec8ad Mon Sep 17 00:00:00 2001 From: Tom Dalziel Date: Tue, 16 Jul 2024 18:28:28 +0200 Subject: [PATCH] Bind all possible ex cmd abbreviations Means that :de expands to delete --- evil-ex.el | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/evil-ex.el b/evil-ex.el index 644fe7f7..200f5770 100644 --- a/evil-ex.el +++ b/evil-ex.el @@ -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.