aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/tab-line.el55
2 files changed, 47 insertions, 13 deletions
diff --git a/etc/NEWS b/etc/NEWS
index ed5db3a01a3..da809096d94 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -364,6 +364,11 @@ By default it contains a keybinding 'C-TAB' to switch tabs,
364but only when 'C-TAB' is not bound globally. You can unbind it 364but only when 'C-TAB' is not bound globally. You can unbind it
365if it conflicts with 'C-TAB' in other modes. 365if it conflicts with 'C-TAB' in other modes.
366 366
367---
368*** New user option 'tab-line-tabs-buffer-group-function'.
369It provides two choices to group tab buffers by major mode
370and by project name.
371
367+++ 372+++
368** New optional argument for modifying directory-local variables. 373** New optional argument for modifying directory-local variables.
369The commands 'add-dir-local-variable', 'delete-dir-local-variable' and 374The commands 'add-dir-local-variable', 'delete-dir-local-variable' and
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index fd18e7b7909..54e9ee16243 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -342,8 +342,7 @@ returns a list of buffers associated with the selected window.
342When `tab-line-tabs-mode-buffers', return a list of buffers 342When `tab-line-tabs-mode-buffers', return a list of buffers
343with the same major mode as the current buffer. 343with the same major mode as the current buffer.
344When `tab-line-tabs-buffer-groups', return a list of buffers 344When `tab-line-tabs-buffer-groups', return a list of buffers
345grouped either by `tab-line-tabs-buffer-group-function', when set, 345grouped by `tab-line-tabs-buffer-group-function'."
346or by `tab-line-tabs-buffer-groups'."
347 :type '(choice (const :tag "Window buffers" 346 :type '(choice (const :tag "Window buffers"
348 tab-line-tabs-window-buffers) 347 tab-line-tabs-window-buffers)
349 (const :tag "Same mode buffers" 348 (const :tag "Same mode buffers"
@@ -377,10 +376,29 @@ Used only for `tab-line-tabs-mode-buffers' and `tab-line-tabs-buffer-groups'.")
377 (derived-mode-p mode))) 376 (derived-mode-p mode)))
378 (funcall tab-line-tabs-buffer-list-function))))) 377 (funcall tab-line-tabs-buffer-list-function)))))
379 378
380(defvar tab-line-tabs-buffer-group-function nil 379(defcustom tab-line-tabs-buffer-group-function
380 #'tab-line-tabs-buffer-group-by-mode
381 "Function to add a buffer to the appropriate group of tabs. 381 "Function to add a buffer to the appropriate group of tabs.
382Takes a buffer as arg and should return a group name as a string. 382Takes a buffer as arg and should return a group name as a string.
383If the return value is nil, the buffer should be filtered out.") 383If the return value is nil, the buffer has no group, so \"No group\"
384is displayed instead of a group name and the buffer is not grouped
385together with other buffers.
386If the value is `tab-line-tabs-buffer-group-by-mode',
387use mode-to-group mappings in `tab-line-tabs-buffer-groups'
388to group by major mode. If the value is
389`tab-line-tabs-buffer-group-by-project' use the project name
390as a group name."
391 :type '(choice (const :tag "Group by mode"
392 tab-line-tabs-buffer-group-by-mode)
393 (const :tag "Group by project name"
394 tab-line-tabs-buffer-group-by-project)
395 (function :tag "Custom function"))
396 :initialize 'custom-initialize-default
397 :set (lambda (sym val)
398 (set-default sym val)
399 (force-mode-line-update))
400 :group 'tab-line
401 :version "30.1")
384 402
385(defvar tab-line-tabs-buffer-group-sort-function nil 403(defvar tab-line-tabs-buffer-group-sort-function nil
386 "Function to sort buffers in a group.") 404 "Function to sort buffers in a group.")
@@ -395,16 +413,27 @@ If the major mode's name matches REGEXP, it belongs to GROUPNAME.
395The default is for each major mode to have a separate group 413The default is for each major mode to have a separate group
396named the same as the mode.") 414named the same as the mode.")
397 415
416(defun tab-line-tabs-buffer-group-by-mode (&optional buffer)
417 "Group tab buffers by major mode."
418 (let ((mode (if buffer (with-current-buffer buffer
419 (format-mode-line mode-name))
420 (format-mode-line mode-name))))
421 (or (cdr (seq-find (lambda (group)
422 (string-match-p (car group) mode))
423 tab-line-tabs-buffer-groups))
424 mode)))
425
426(declare-function project-name "project" (project))
427(defun tab-line-tabs-buffer-group-by-project (&optional buffer)
428 "Group tab buffers by project name."
429 (with-current-buffer buffer
430 (if-let ((project (project-current)))
431 (project-name project)
432 "No project")))
433
398(defun tab-line-tabs-buffer-group-name (&optional buffer) 434(defun tab-line-tabs-buffer-group-name (&optional buffer)
399 (if (functionp tab-line-tabs-buffer-group-function) 435 (if (functionp tab-line-tabs-buffer-group-function)
400 (funcall tab-line-tabs-buffer-group-function buffer) 436 (funcall tab-line-tabs-buffer-group-function buffer)))
401 (let ((mode (if buffer (with-current-buffer buffer
402 (format-mode-line mode-name))
403 (format-mode-line mode-name))))
404 (or (cdr (seq-find (lambda (group)
405 (string-match-p (car group) mode))
406 tab-line-tabs-buffer-groups))
407 mode))))
408 437
409(defun tab-line-tabs-buffer-groups () 438(defun tab-line-tabs-buffer-groups ()
410 "Return a list of tabs that should be displayed in the tab line. 439 "Return a list of tabs that should be displayed in the tab line.
@@ -436,7 +465,7 @@ generate the group name."
436 465
437 (let* ((window-parameter (window-parameter nil 'tab-line-group)) 466 (let* ((window-parameter (window-parameter nil 'tab-line-group))
438 (group-name (tab-line-tabs-buffer-group-name (current-buffer))) 467 (group-name (tab-line-tabs-buffer-group-name (current-buffer)))
439 (group (prog1 (or window-parameter group-name "All") 468 (group (prog1 (or window-parameter group-name "No group")
440 (when (equal window-parameter group-name) 469 (when (equal window-parameter group-name)
441 (set-window-parameter nil 'tab-line-group nil)))) 470 (set-window-parameter nil 'tab-line-group nil))))
442 (group-tab `(tab 471 (group-tab `(tab