diff options
| author | Juri Linkov | 2025-05-20 21:30:38 +0300 |
|---|---|---|
| committer | Juri Linkov | 2025-05-20 21:30:38 +0300 |
| commit | 87fa5f565d70c514bd47b59bb0ef0cba8750e983 (patch) | |
| tree | 85e1d2af843fdaa24c6978406c75c1d6320bafc2 | |
| parent | d8bf84f7f45620070f5666c023ca977eebf4dd90 (diff) | |
| download | emacs-87fa5f565d70c514bd47b59bb0ef0cba8750e983.tar.gz emacs-87fa5f565d70c514bd47b59bb0ef0cba8750e983.zip | |
* lisp/tab-line.el (tab-line-move-tab-forward): New command.
(tab-line-move-tab-backward): New command.
(tab-line-mode-map): Bind 'C-x M-<left>' to
'tab-line-move-tab-backward' and 'C-x M-<right>' to
'tab-line-move-tab-forward'.
(tab-line-switch-repeat-map): Bind 'M-<left>' to
'tab-line-move-tab-backward' and 'M-<right>' to
'tab-line-move-tab-forward'.
Suggested by pinmacs <pinmacs@cas.cat>.
| -rw-r--r-- | etc/NEWS | 6 | ||||
| -rw-r--r-- | lisp/tab-line.el | 52 |
2 files changed, 54 insertions, 4 deletions
| @@ -383,6 +383,12 @@ customize help text for tabs displayed on the tab-bar. Help text is | |||
| 383 | normally shown in the echo area or via tooltips. See the variable's | 383 | normally shown in the echo area or via tooltips. See the variable's |
| 384 | docstring for arguments passed to a help-text function. | 384 | docstring for arguments passed to a help-text function. |
| 385 | 385 | ||
| 386 | --- | ||
| 387 | *** New command 'tab-line-move-tab-forward' ('C-x M-<right>'). | ||
| 388 | Together with the new command 'tab-line-move-tab-backward' | ||
| 389 | ('C-x M-<left>') it can be used to move the current tab | ||
| 390 | on the tab line to a different position. | ||
| 391 | |||
| 386 | ** Project | 392 | ** Project |
| 387 | 393 | ||
| 388 | --- | 394 | --- |
diff --git a/lisp/tab-line.el b/lisp/tab-line.el index 552c480725c..411d8cbd70d 100644 --- a/lisp/tab-line.el +++ b/lisp/tab-line.el | |||
| @@ -1004,7 +1004,7 @@ is possible when `tab-line-switch-cycling' is non-nil." | |||
| 1004 | (switch-to-buffer buffer)))))))) | 1004 | (switch-to-buffer buffer)))))))) |
| 1005 | 1005 | ||
| 1006 | (defun tab-line-mouse-move-tab (event) | 1006 | (defun tab-line-mouse-move-tab (event) |
| 1007 | "Move a tab to a different position on the tab line. | 1007 | "Move a tab to a different position on the tab line using mouse. |
| 1008 | This command should be bound to a drag event. It moves the tab | 1008 | This command should be bound to a drag event. It moves the tab |
| 1009 | at the mouse-down event to the position at mouse-up event. | 1009 | at the mouse-down event to the position at mouse-up event. |
| 1010 | It can be used only when `tab-line-tabs-function' is | 1010 | It can be used only when `tab-line-tabs-function' is |
| @@ -1028,6 +1028,46 @@ customized to `tab-line-tabs-fixed-window-buffers'." | |||
| 1028 | (set-window-parameter window1 'tab-line-cache nil) | 1028 | (set-window-parameter window1 'tab-line-cache nil) |
| 1029 | (with-selected-window window1 (force-mode-line-update)))))) | 1029 | (with-selected-window window1 (force-mode-line-update)))))) |
| 1030 | 1030 | ||
| 1031 | (defun tab-line-move-tab-forward (&optional arg) | ||
| 1032 | "Move a tab to a different position on the tab line. | ||
| 1033 | ARG specifies the number of positions to move: | ||
| 1034 | - When positive, move the current tab ARG positions to the right. | ||
| 1035 | - When negative, move the current tab -ARG positions to the left. | ||
| 1036 | - When nil, act as if ARG is 1, moving one position to the right. | ||
| 1037 | It can be used only when `tab-line-tabs-function' is | ||
| 1038 | customized to `tab-line-tabs-fixed-window-buffers'." | ||
| 1039 | (interactive "p") | ||
| 1040 | (when (eq tab-line-tabs-function #'tab-line-tabs-fixed-window-buffers) | ||
| 1041 | (let* ((window (selected-window)) | ||
| 1042 | (buffers (window-parameter window 'tab-line-buffers)) | ||
| 1043 | (buffer (current-buffer)) | ||
| 1044 | (pos (seq-position buffers buffer)) | ||
| 1045 | (len (length buffers)) | ||
| 1046 | (new-pos (+ pos (or arg 1)))) | ||
| 1047 | (when (and pos (> len 1)) | ||
| 1048 | (setq new-pos (if tab-line-switch-cycling | ||
| 1049 | (mod new-pos len) | ||
| 1050 | (max 0 (min new-pos (1- len))))) | ||
| 1051 | (setq buffers (delq buffer buffers)) | ||
| 1052 | (setq buffers (append | ||
| 1053 | (seq-take buffers new-pos) | ||
| 1054 | (list buffer) | ||
| 1055 | (seq-drop buffers new-pos))) | ||
| 1056 | (set-window-parameter window 'tab-line-buffers buffers) | ||
| 1057 | (set-window-parameter window 'tab-line-cache nil) | ||
| 1058 | (force-mode-line-update))))) | ||
| 1059 | |||
| 1060 | (defun tab-line-move-tab-backward (&optional arg) | ||
| 1061 | "Move a tab to a different position on the tab line. | ||
| 1062 | ARG specifies the number of positions to move: | ||
| 1063 | - When positive, move the current tab ARG positions to the left. | ||
| 1064 | - When negative, move the current tab -ARG positions to the right. | ||
| 1065 | - When nil, act as if ARG is 1, moving one position to the left. | ||
| 1066 | It can be used only when `tab-line-tabs-function' is | ||
| 1067 | customized to `tab-line-tabs-fixed-window-buffers'." | ||
| 1068 | (interactive "p") | ||
| 1069 | (tab-line-move-tab-forward (- (or arg 1)))) | ||
| 1070 | |||
| 1031 | 1071 | ||
| 1032 | (defcustom tab-line-close-tab-function 'bury-buffer | 1072 | (defcustom tab-line-close-tab-function 'bury-buffer |
| 1033 | "What to do upon closing a tab on the tab line. | 1073 | "What to do upon closing a tab on the tab line. |
| @@ -1133,14 +1173,18 @@ However, return the correct mouse position list if EVENT is a | |||
| 1133 | :doc "Keymap for keys of `tab-line-mode'." | 1173 | :doc "Keymap for keys of `tab-line-mode'." |
| 1134 | "C-x <left>" #'tab-line-switch-to-prev-tab | 1174 | "C-x <left>" #'tab-line-switch-to-prev-tab |
| 1135 | "C-x C-<left>" #'tab-line-switch-to-prev-tab | 1175 | "C-x C-<left>" #'tab-line-switch-to-prev-tab |
| 1176 | "C-x M-<left>" #'tab-line-move-tab-backward | ||
| 1136 | "C-x <right>" #'tab-line-switch-to-next-tab | 1177 | "C-x <right>" #'tab-line-switch-to-next-tab |
| 1137 | "C-x C-<right>" #'tab-line-switch-to-next-tab) | 1178 | "C-x C-<right>" #'tab-line-switch-to-next-tab |
| 1179 | "C-x M-<right>" #'tab-line-move-tab-forward) | ||
| 1138 | 1180 | ||
| 1139 | (defvar-keymap tab-line-switch-repeat-map | 1181 | (defvar-keymap tab-line-switch-repeat-map |
| 1140 | :doc "Keymap to repeat tab/buffer cycling. Used in `repeat-mode'." | 1182 | :doc "Keymap to repeat tab/buffer cycling. Used in `repeat-mode'." |
| 1141 | :repeat t | 1183 | :repeat t |
| 1142 | "<left>" #'tab-line-switch-to-prev-tab | 1184 | "<left>" #'tab-line-switch-to-prev-tab |
| 1143 | "<right>" #'tab-line-switch-to-next-tab) | 1185 | "M-<left>" #'tab-line-move-tab-backward |
| 1186 | "<right>" #'tab-line-switch-to-next-tab | ||
| 1187 | "M-<right>" #'tab-line-move-tab-forward) | ||
| 1144 | 1188 | ||
| 1145 | ;;;###autoload | 1189 | ;;;###autoload |
| 1146 | (define-minor-mode tab-line-mode | 1190 | (define-minor-mode tab-line-mode |