From df377ec12f85954439f61a1ef8df2499a22187a7 Mon Sep 17 00:00:00 2001 From: Ankit Pandey Date: Fri, 7 Apr 2023 23:52:15 -0700 Subject: [PATCH] Implement tabmove tabmove allows specifying the index in two ways: either as an aboslute index, or an offset from the current tab prefixed by +/-. --- evil-commands.el | 9 +++++++++ evil-maps.el | 1 + evil-types.el | 20 ++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/evil-commands.el b/evil-commands.el index d44d3ab7e..bde3b4359 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1201,6 +1201,15 @@ the right edge." (message "%s: hscroll-margin = %d" this-command hscroll-margin)) (evil-scroll-column-left (- dist-from-right-edge (abs (* 2 hscroll-margin)))))) +(when (featurep 'tab-bar) + (evil-define-command evil-tab-move (index-or-offset relative) + "Move the current tab to INDEX-OR-OFFSET. Treat as offset if +RELATIVE is non-nil." + (interactive "<+N>") + (if relative + (tab-bar-move-tab index-or-offset) + (tab-bar-move-tab-to index-or-offset)))) + (evil-define-command evil-scroll-start-column () "Scroll the window to position the cursor at the start (left side) of the screen. Warn if `hscroll-margin' > 0, as cursor will be `hscroll-margin' chars from diff --git a/evil-maps.el b/evil-maps.el index 8d39d5d0b..3b36af182 100644 --- a/evil-maps.el +++ b/evil-maps.el @@ -577,6 +577,7 @@ included in `evil-insert-state-bindings' by default." (evil-ex-define-cmd "red[o]" 'evil-redo) (when (featurep 'tab-bar) + (evil-ex-define-cmd "tabm[ove]" 'evil-tab-move) (evil-ex-define-cmd "tabnew" 'tab-bar-new-tab) (evil-ex-define-cmd "tabc[lose]" 'tab-bar-close-tab) (evil-ex-define-cmd "tabo[nly]" 'tab-bar-close-other-tabs) diff --git a/evil-types.el b/evil-types.el index 276cdbbf1..68a36006e 100644 --- a/evil-types.el +++ b/evil-types.el @@ -342,6 +342,26 @@ If visual state is inactive then those values are nil." ((evil-ex-p) nil) (t 1)))) +(evil-define-interactive-code "<+N>" () + "Prefix argument or ex-arg, converted to number. Allow prefixing +the number with +/- to indicate that this should be treated as +a relative value instead of absolute." + (list + (cond + (current-prefix-arg (prefix-numeric-value current-prefix-arg)) + ((and evil-ex-argument (evil-ex-p)) + (cond + ;; Required, since `string-to-number' parses these as 0. + ((string-equal evil-ex-argument "+") 1) + ((string-equal evil-ex-argument "-") -1) + (t (string-to-number evil-ex-argument)))) + ((evil-ex-p) nil) + (t 1)) + (cond + ((and evil-ex-argument (evil-ex-p)) + (memq (string-to-char evil-ex-argument) '(?- ?+))) + (t nil)))) + (evil-define-interactive-code "" "Ex file argument." :ex-arg file