diff options
| author | Juri Linkov | 2024-04-12 19:35:55 +0300 |
|---|---|---|
| committer | Juri Linkov | 2024-04-12 19:35:55 +0300 |
| commit | 414f8d02c1a361fa780e55fcf0f260fe00a9a62d (patch) | |
| tree | f1924fae2e519e3d40d4243107c7bbc4e81901ac | |
| parent | 2fc7e21f5e75ea6b00d6f7344335f44f5663d955 (diff) | |
| download | emacs-414f8d02c1a361fa780e55fcf0f260fe00a9a62d.tar.gz emacs-414f8d02c1a361fa780e55fcf0f260fe00a9a62d.zip | |
New user option 'tab-line-tabs-buffer-group-function'
* lisp/tab-line.el (tab-line-tabs-buffer-group-function):
Turn defvar into defcustom with the default value
'tab-line-tabs-buffer-group-by-mode'.
(tab-line-tabs-buffer-group-by-mode): New function with body from
'tab-line-tabs-buffer-group-name'.
(tab-line-tabs-buffer-group-by-project): New function.
(tab-line-tabs-buffer-groups): Use fallback name "No group" instead of "All".
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/tab-line.el | 55 |
2 files changed, 47 insertions, 13 deletions
| @@ -364,6 +364,11 @@ By default it contains a keybinding 'C-TAB' to switch tabs, | |||
| 364 | but only when 'C-TAB' is not bound globally. You can unbind it | 364 | but only when 'C-TAB' is not bound globally. You can unbind it |
| 365 | if it conflicts with 'C-TAB' in other modes. | 365 | if it conflicts with 'C-TAB' in other modes. |
| 366 | 366 | ||
| 367 | --- | ||
| 368 | *** New user option 'tab-line-tabs-buffer-group-function'. | ||
| 369 | It provides two choices to group tab buffers by major mode | ||
| 370 | and by project name. | ||
| 371 | |||
| 367 | +++ | 372 | +++ |
| 368 | ** New optional argument for modifying directory-local variables. | 373 | ** New optional argument for modifying directory-local variables. |
| 369 | The commands 'add-dir-local-variable', 'delete-dir-local-variable' and | 374 | The 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. | |||
| 342 | When `tab-line-tabs-mode-buffers', return a list of buffers | 342 | When `tab-line-tabs-mode-buffers', return a list of buffers |
| 343 | with the same major mode as the current buffer. | 343 | with the same major mode as the current buffer. |
| 344 | When `tab-line-tabs-buffer-groups', return a list of buffers | 344 | When `tab-line-tabs-buffer-groups', return a list of buffers |
| 345 | grouped either by `tab-line-tabs-buffer-group-function', when set, | 345 | grouped by `tab-line-tabs-buffer-group-function'." |
| 346 | or 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. |
| 382 | Takes a buffer as arg and should return a group name as a string. | 382 | Takes a buffer as arg and should return a group name as a string. |
| 383 | If the return value is nil, the buffer should be filtered out.") | 383 | If the return value is nil, the buffer has no group, so \"No group\" |
| 384 | is displayed instead of a group name and the buffer is not grouped | ||
| 385 | together with other buffers. | ||
| 386 | If the value is `tab-line-tabs-buffer-group-by-mode', | ||
| 387 | use mode-to-group mappings in `tab-line-tabs-buffer-groups' | ||
| 388 | to group by major mode. If the value is | ||
| 389 | `tab-line-tabs-buffer-group-by-project' use the project name | ||
| 390 | as 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. | |||
| 395 | The default is for each major mode to have a separate group | 413 | The default is for each major mode to have a separate group |
| 396 | named the same as the mode.") | 414 | named 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 |