aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2024-04-17 20:55:45 +0300
committerJuri Linkov2024-04-17 20:56:10 +0300
commit230eecf12a688f87354ed2d360a7dfcd7e2dae6a (patch)
tree69b8d2214771076bf878b03ac3f71af6176dd39b
parent91333dacfa1b9f1041ceeebb3d46e8e04048c4c9 (diff)
downloademacs-230eecf12a688f87354ed2d360a7dfcd7e2dae6a.tar.gz
emacs-230eecf12a688f87354ed2d360a7dfcd7e2dae6a.zip
New keymap tab-line-mode-map and new tab order on tab-line (bug#69993)
* lisp/tab-line.el (tab-line-new-button-functions): New variable. (tab-line-tabs-function): Change the default value from 'tab-line-tabs-window-buffers' to the new option 'tab-line-tabs-fixed-window-buffers'. (tab-line-tabs-buffer-group-sort-function): Change the default value from nil to 'tab-line-tabs-buffer-group-sort-by-name'. (tab-line-tabs-buffer-group-sort-by-name): New function. (tab-line-tabs-fixed-window-buffers): New function. (tab-line-format-template): Use 'tab-line-new-button-functions'. (tab-line-mode-map, tab-line-switch-repeat-map): New keymaps.
-rw-r--r--etc/NEWS22
-rw-r--r--lisp/tab-line.el52
2 files changed, 68 insertions, 6 deletions
diff --git a/etc/NEWS b/etc/NEWS
index e6f8eb5ba46..2f90a3067f7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -371,10 +371,32 @@ but only when 'C-TAB' is not bound globally. You can unbind it
371if it conflicts with 'C-TAB' in other modes. 371if it conflicts with 'C-TAB' in other modes.
372 372
373--- 373---
374*** New keymap 'tab-line-mode-map'.
375By default it contains keybindings for switching tabs:
376'C-x <left>', 'C-x <right>', 'C-x C-<left>', 'C-x C-<right>'.
377You can unbind them if you want to use these keys for the
378commands 'previous-buffer' and 'next-buffer'.
379
380---
381*** Default list of tabs is changed to support a fixed order.
382This means that the new default tabs function
383'tab-line-tabs-fixed-window-buffers' is like the previous
384'tab-line-tabs-window-buffers' where both of them show
385only buffers that were previously displayed in the window.
386But the difference is that the new function always keeps
387the original order of buffers on the tab line, even after
388switching between these buffers.
389
390---
374*** New user option 'tab-line-tabs-buffer-group-function'. 391*** New user option 'tab-line-tabs-buffer-group-function'.
375It provides two choices to group tab buffers by major mode 392It provides two choices to group tab buffers by major mode
376and by project name. 393and by project name.
377 394
395---
396*** Now buffers on group tabs are sorted alphabetically.
397This will keep the fixed order of tabs, even after
398switching between them.
399
378+++ 400+++
379** New optional argument for modifying directory-local variables. 401** New optional argument for modifying directory-local variables.
380The commands 'add-dir-local-variable', 'delete-dir-local-variable' and 402The commands 'add-dir-local-variable', 'delete-dir-local-variable' and
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 48272b7b4b3..09081501705 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -210,6 +210,11 @@ If the value is a function, call it with no arguments."
210 'help-echo "Click to add tab") 210 'help-echo "Click to add tab")
211 "Button for creating a new tab.") 211 "Button for creating a new tab.")
212 212
213(defvar tab-line-new-button-functions
214 '(tab-line-tabs-window-buffers
215 tab-line-tabs-fixed-window-buffers)
216 "Functions of `tab-line-tabs-function' for which to show a new button.")
217
213(defcustom tab-line-close-button-show t 218(defcustom tab-line-close-button-show t
214 "Defines where to show the close tab button. 219 "Defines where to show the close tab button.
215If t, show the close tab button on all tabs. 220If t, show the close tab button on all tabs.
@@ -333,18 +338,21 @@ If truncated, append ellipsis per `tab-line-tab-name-ellipsis'."
333 'help-echo tab-name)))) 338 'help-echo tab-name))))
334 339
335 340
336(defcustom tab-line-tabs-function #'tab-line-tabs-window-buffers 341(defcustom tab-line-tabs-function #'tab-line-tabs-fixed-window-buffers
337 "Function to get a list of tabs to display in the tab line. 342 "Function to get a list of tabs to display in the tab line.
338This function should return either a list of buffers whose names will 343This function should return either a list of buffers whose names will
339be displayed, or just a list of strings to display in the tab line. 344be displayed, or just a list of strings to display in the tab line.
340By default, use function `tab-line-tabs-window-buffers' that 345By default, use function `tab-line-tabs-fixed-window-buffers' that
341returns a list of buffers associated with the selected window. 346returns a list of buffers associated with the selected window where
347buffers always keep the original order after switching buffers.
342When `tab-line-tabs-mode-buffers', return a list of buffers 348When `tab-line-tabs-mode-buffers', return a list of buffers
343with the same major mode as the current buffer. 349with the same major mode as the current buffer.
344When `tab-line-tabs-buffer-groups', return a list of buffers 350When `tab-line-tabs-buffer-groups', return a list of buffers
345grouped by `tab-line-tabs-buffer-group-function'." 351grouped by `tab-line-tabs-buffer-group-function'."
346 :type '(choice (const :tag "Window buffers" 352 :type '(choice (const :tag "Window buffers"
347 tab-line-tabs-window-buffers) 353 tab-line-tabs-window-buffers)
354 (const :tag "Window buffers with fixed order"
355 tab-line-tabs-fixed-window-buffers)
348 (const :tag "Same mode buffers" 356 (const :tag "Same mode buffers"
349 tab-line-tabs-mode-buffers) 357 tab-line-tabs-mode-buffers)
350 (const :tag "Grouped buffers" 358 (const :tag "Grouped buffers"
@@ -400,9 +408,13 @@ as a group name."
400 :group 'tab-line 408 :group 'tab-line
401 :version "30.1") 409 :version "30.1")
402 410
403(defvar tab-line-tabs-buffer-group-sort-function nil 411(defvar tab-line-tabs-buffer-group-sort-function
412 #'tab-line-tabs-buffer-group-sort-by-name
404 "Function to sort buffers in a group.") 413 "Function to sort buffers in a group.")
405 414
415(defun tab-line-tabs-buffer-group-sort-by-name (a b)
416 (string< (buffer-name a) (buffer-name b)))
417
406(defvar tab-line-tabs-buffer-groups-sort-function #'string< 418(defvar tab-line-tabs-buffer-groups-sort-function #'string<
407 "Function to sort group names.") 419 "Function to sort group names.")
408 420
@@ -515,6 +527,21 @@ variable `tab-line-tabs-function'."
515 (list buffer) 527 (list buffer)
516 next-buffers))) 528 next-buffers)))
517 529
530(defun tab-line-tabs-fixed-window-buffers ()
531 "Like `tab-line-tabs-window-buffers' but keep stable sorting order.
532This means that switching to a buffer previously shown in the same
533window will keep the same order of tabs that was before switching.
534And newly displayed buffers are added to the end of the tab line."
535 (let* ((old-buffers (window-parameter nil 'tab-line-fixed-window-buffers))
536 (new-buffers (sort (tab-line-tabs-window-buffers)
537 (lambda (a b)
538 (< (or (seq-position old-buffers a)
539 most-positive-fixnum)
540 (or (seq-position old-buffers b)
541 most-positive-fixnum))))))
542 (set-window-parameter nil 'tab-line-fixed-window-buffers new-buffers)
543 new-buffers))
544
518 545
519(defcustom tab-line-tab-name-format-function #'tab-line-tab-name-format-default 546(defcustom tab-line-tab-name-format-function #'tab-line-tab-name-format-default
520 "Function to format a tab name. 547 "Function to format a tab name.
@@ -599,7 +626,7 @@ This is used by `tab-line-format'."
599 tab-line-right-button))) 626 tab-line-right-button)))
600 (if hscroll (nthcdr (truncate hscroll) strings) strings) 627 (if hscroll (nthcdr (truncate hscroll) strings) strings)
601 (list separator) 628 (list separator)
602 (when (and (eq tab-line-tabs-function #'tab-line-tabs-window-buffers) 629 (when (and (memq tab-line-tabs-function tab-line-new-button-functions)
603 tab-line-new-button-show 630 tab-line-new-button-show
604 tab-line-new-button) 631 tab-line-new-button)
605 (list tab-line-new-button))))) 632 (list tab-line-new-button)))))
@@ -940,7 +967,7 @@ buffers, which effectively hides the buffer's tab from the tab line.
940If `kill-buffer', kills the tab's buffer. 967If `kill-buffer', kills the tab's buffer.
941When a function, it is called with the tab as its argument. 968When a function, it is called with the tab as its argument.
942This option is useful when `tab-line-tabs-function' has the value 969This option is useful when `tab-line-tabs-function' has the value
943`tab-line-tabs-window-buffers'." 970`tab-line-tabs-window-buffers' or `tab-line-tabs-fixed-window-buffers'."
944 :type '(choice (const :tag "Bury buffer" bury-buffer) 971 :type '(choice (const :tag "Bury buffer" bury-buffer)
945 (const :tag "Kill buffer" kill-buffer) 972 (const :tag "Kill buffer" kill-buffer)
946 (function :tag "Function")) 973 (function :tag "Function"))
@@ -1033,6 +1060,19 @@ However, return the correct mouse position list if EVENT is a
1033 (event-start event))) 1060 (event-start event)))
1034 1061
1035 1062
1063(defvar-keymap tab-line-mode-map
1064 :doc "Keymap for keys of `tab-line-mode'."
1065 "C-x <left>" #'tab-line-switch-to-prev-tab
1066 "C-x C-<left>" #'tab-line-switch-to-prev-tab
1067 "C-x <right>" #'tab-line-switch-to-next-tab
1068 "C-x C-<right>" #'tab-line-switch-to-next-tab)
1069
1070(defvar-keymap tab-line-switch-repeat-map
1071 :doc "Keymap to repeat tab/buffer cycling. Used in `repeat-mode'."
1072 :repeat t
1073 "<left>" #'tab-line-switch-to-prev-tab
1074 "<right>" #'tab-line-switch-to-next-tab)
1075
1036;;;###autoload 1076;;;###autoload
1037(define-minor-mode tab-line-mode 1077(define-minor-mode tab-line-mode
1038 "Toggle display of tab line in the windows displaying the current buffer." 1078 "Toggle display of tab line in the windows displaying the current buffer."