aboutsummaryrefslogtreecommitdiff
path: root/evil-commands.el
diff options
context:
space:
mode:
authorJakub Kadlcik <frostyx@email.cz>2023-12-09 13:21:33 +0100
committerTom Dalziel <33435574+tomdl89@users.noreply.github.com>2023-12-18 10:20:46 +0100
commitfc6bd006503258e5cc09c92de8882f4496992946 (patch)
tree6c6643c5e42d13999a6c83d8308fa5f33f050978 /evil-commands.el
parenteced3088ce860431b6d0e0af2409c56d754ffab2 (diff)
Add :retab command
See "Changing tabs" section in the Vim manual https://vimhelp.org/change.txt.html#change.txt
Diffstat (limited to 'evil-commands.el')
-rw-r--r--evil-commands.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/evil-commands.el b/evil-commands.el
index e7fb345..44306c3 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -5172,6 +5172,23 @@ event that triggered the execution of this command."
(push event unread-command-events)))
(evil-declare-ignore-repeat 'evil-exit-visual-and-repeat)
+(evil-define-command evil-retab (tabstop)
+ "Convert all tabs to spaces or the other way around.
+Replace all sequences of white-space containing a <Tab> with new
+strings of white-space using the new TABSTOP value given.
+If you do not specify a new TABSTOP size or it is zero, Evil uses the
+current value of `tab-width'."
+ (interactive "<a>")
+ (unless (or (not tabstop) (string-match-p "^[0-9]*$" tabstop))
+ (user-error "Invalid argument: %s" tabstop))
+ (let ((beg (if (use-region-p) (region-beginning) (point-min)))
+ (end (if (use-region-p) (region-end) (point-max)))
+ (retab (if indent-tabs-mode #'tabify #'untabify))
+ (tab-width (cond ((not tabstop) tab-width)
+ ((equal tabstop "0") tab-width)
+ (t (string-to-number tabstop)))))
+ (funcall retab beg end)))
+
(provide 'evil-commands)
;;; evil-commands.el ends here