From 6e90768143ff47e96a70d91534344161a1d85f46 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 22 Feb 2021 19:08:16 +0200 Subject: [PATCH] * lisp/tab-bar.el: 'C-x t M' bound to tab-move-to supports a negative argument * lisp/tab-bar.el (tab-bar-move-tab-to): Negative TO-INDEX counts tabs from the end of the tab bar. (tab-bar-move-tab): Fix docstring to add reference to tab-bar-move-tab-to. (tab-prefix-map): Bind "M" to tab-move-to. --- etc/NEWS | 5 +++++ lisp/tab-bar.el | 14 +++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index ca0d71567d0..983a75133f6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -488,6 +488,11 @@ independently from the value of 'tab-bar-mode' and 'tab-bar-show'. --- *** 'Mod-9' bound to 'tab-last' now switches to the last tab. +It also supports a negative argument. + +--- +*** 'C-x t M' moves the current tab to the specified absolute position. +It also supports a negative argument. --- *** New user option 'tab-bar-tab-name-format-function'. diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el index db2376d9efb..ddb716c15e7 100644 --- a/lisp/tab-bar.el +++ b/lisp/tab-bar.el @@ -759,12 +759,17 @@ most recent, and so on." (defun tab-bar-move-tab-to (to-index &optional from-index) "Move tab from FROM-INDEX position to new position at TO-INDEX. FROM-INDEX defaults to the current tab index. -FROM-INDEX and TO-INDEX count from 1." +FROM-INDEX and TO-INDEX count from 1. +Negative TO-INDEX counts tabs from the end of the tab bar. +Argument addressing is absolute in contrast to `tab-bar-move-tab' +where argument addressing is relative." (interactive "P") (let* ((tabs (funcall tab-bar-tabs-function)) (from-index (or from-index (1+ (tab-bar--current-tab-index tabs)))) (from-tab (nth (1- from-index) tabs)) - (to-index (max 0 (min (1- (or to-index 1)) (1- (length tabs)))))) + (to-index (if to-index (prefix-numeric-value to-index) 1)) + (to-index (if (< to-index 0) (+ (length tabs) (1+ to-index)) to-index)) + (to-index (max 0 (min (1- to-index) (1- (length tabs)))))) (setq tabs (delq from-tab tabs)) (cl-pushnew from-tab (nthcdr to-index tabs)) (set-frame-parameter nil 'tabs tabs) @@ -772,7 +777,9 @@ FROM-INDEX and TO-INDEX count from 1." (defun tab-bar-move-tab (&optional arg) "Move the current tab ARG positions to the right. -If a negative ARG, move the current tab ARG positions to the left." +If a negative ARG, move the current tab ARG positions to the left. +Argument addressing is relative in contrast to `tab-bar-move-tab-to' +where argument addressing is absolute." (interactive "p") (let* ((tabs (funcall tab-bar-tabs-function)) (from-index (or (tab-bar--current-tab-index tabs) 0)) @@ -1687,6 +1694,7 @@ When `switch-to-buffer-obey-display-actions' is non-nil, (define-key tab-prefix-map "0" 'tab-close) (define-key tab-prefix-map "o" 'tab-next) (define-key tab-prefix-map "m" 'tab-move) +(define-key tab-prefix-map "M" 'tab-move-to) (define-key tab-prefix-map "r" 'tab-rename) (define-key tab-prefix-map "\r" 'tab-bar-select-tab-by-name) (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab) -- 2.39.2