aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2020-01-21 01:03:37 +0200
committerJuri Linkov2020-01-21 01:03:37 +0200
commit3ba0db41e3fcfdc47368e9e6fd7cbe45230ba88b (patch)
treef6deb0eb40f22956805ffe1335d037220eb57a12
parent7dd065fc7bd561b09f79142974b8ada052dfa7d1 (diff)
downloademacs-3ba0db41e3fcfdc47368e9e6fd7cbe45230ba88b.tar.gz
emacs-3ba0db41e3fcfdc47368e9e6fd7cbe45230ba88b.zip
Allow optional truncation of tab names in tab-bar and tab-line (bug#38693)
* lisp/tab-line.el (tab-line-tab-name-truncated-max): New defcustom. (tab-line-tab-name-truncated-buffer): Use tab-line-tab-name-truncated-max consistently with similar options in tab-bar.el. (tab-line-tabs-limit): Remove variable. (tab-line-tabs-window-buffers): Remove use of tab-line-tabs-limit that was an experimental feature before horizontal scrolling was implemented. (tab-line-close-tab-function): Rename from tab-line-close-tab-action and allow a customizaed function as option. (tab-line-close-tab): Call function if tab-line-close-tab-function is customized to a function. * lisp/tab-bar.el (tab-bar-tab-name-function): Add option tab-bar-tab-name-truncated. (tab-bar-tab-name-truncated-max): New defcustom. (tab-bar-tab-name-truncated-ellipsis): New variable. (tab-bar-tab-name-truncated): New function.
-rw-r--r--lisp/tab-bar.el25
-rw-r--r--lisp/tab-line.el73
2 files changed, 59 insertions, 39 deletions
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index e4ff7325844..f70fb6baeee 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -319,6 +319,8 @@ from all windows in the window configuration."
319 tab-bar-tab-name-current) 319 tab-bar-tab-name-current)
320 (const :tag "Selected window buffer with window count" 320 (const :tag "Selected window buffer with window count"
321 tab-bar-tab-name-current-with-count) 321 tab-bar-tab-name-current-with-count)
322 (const :tag "Truncated buffer name"
323 tab-bar-tab-name-truncated)
322 (const :tag "All window buffers" 324 (const :tag "All window buffers"
323 tab-bar-tab-name-all) 325 tab-bar-tab-name-all)
324 (function :tag "Function")) 326 (function :tag "Function"))
@@ -350,6 +352,29 @@ Also add the number of windows in the window configuration."
350 'nomini))) 352 'nomini)))
351 ", ")) 353 ", "))
352 354
355(defcustom tab-bar-tab-name-truncated-max 20
356 "Maximum length of the tab name from the current buffer.
357Effective when `tab-bar-tab-name-function' is customized
358to `tab-bar-tab-name-truncated'."
359 :type 'integer
360 :group 'tab-bar
361 :version "27.1")
362
363(defvar tab-bar-tab-name-truncated-ellipsis
364 (if (char-displayable-p ?…) "…" "..."))
365
366(defun tab-bar-tab-name-truncated ()
367 "Generate tab name from the buffer of the selected window.
368Truncate it to the length specified by `tab-bar-tab-name-truncated-max'.
369Append ellipsis `tab-bar-tab-name-truncated-ellipsis' in this case."
370 (let ((tab-name (buffer-name (window-buffer (minibuffer-selected-window)))))
371 (if (< (length tab-name) tab-bar-tab-name-truncated-max)
372 tab-name
373 (propertize (truncate-string-to-width
374 tab-name tab-bar-tab-name-truncated-max nil nil
375 tab-bar-tab-name-truncated-ellipsis)
376 'help-echo tab-name))))
377
353 378
354(defvar tab-bar-tabs-function #'tab-bar-tabs 379(defvar tab-bar-tabs-function #'tab-bar-tabs
355 "Function to get a list of tabs to display in the tab bar. 380 "Function to get a list of tabs to display in the tab bar.
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 5bbc45b0aae..ad4050fec59 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -213,9 +213,6 @@ If nil, don't show it at all."
213 213
214(defvar tab-line-separator nil) 214(defvar tab-line-separator nil)
215 215
216(defvar tab-line-tab-name-ellipsis
217 (if (char-displayable-p ?…) "…" "..."))
218
219 216
220(defcustom tab-line-tab-name-function #'tab-line-tab-name-buffer 217(defcustom tab-line-tab-name-function #'tab-line-tab-name-buffer
221 "Function to get a tab name. 218 "Function to get a tab name.
@@ -240,23 +237,30 @@ This function can be overridden by changing the default value of the
240variable `tab-line-tab-name-function'." 237variable `tab-line-tab-name-function'."
241 (buffer-name buffer)) 238 (buffer-name buffer))
242 239
243(defun tab-line-tab-name-truncated-buffer (buffer &optional buffers) 240(defcustom tab-line-tab-name-truncated-max 20
241 "Maximum length of the tab name from the current buffer.
242Effective when `tab-line-tab-name-function' is customized
243to `tab-line-tab-name-truncated-buffer'."
244 :type 'integer
245 :group 'tab-line
246 :version "27.1")
247
248(defvar tab-line-tab-name-ellipsis
249 (if (char-displayable-p ?…) "…" "..."))
250
251(defun tab-line-tab-name-truncated-buffer (buffer &optional _buffers)
244 "Generate tab name from BUFFER. 252 "Generate tab name from BUFFER.
245Reduce tab width proportionally to space taken by other tabs." 253Truncate it to the length specified by `tab-line-tab-name-truncated-max'.
246 (let ((tab-name (buffer-name buffer)) 254Append ellipsis `tab-line-tab-name-ellipsis' in this case."
247 (limit (when buffers 255 (let ((tab-name (buffer-name buffer)))
248 (max 1 (- (/ (window-width) (length buffers)) 3))))) 256 (if (< (length tab-name) tab-line-tab-name-truncated-max)
249 (if (or (not limit) (< (length tab-name) limit))
250 tab-name 257 tab-name
251 (propertize (truncate-string-to-width tab-name limit nil nil 258 (propertize (truncate-string-to-width
252 tab-line-tab-name-ellipsis) 259 tab-name tab-line-tab-name-truncated-max nil nil
260 tab-line-tab-name-ellipsis)
253 'help-echo tab-name)))) 261 'help-echo tab-name))))
254 262
255 263
256(defvar tab-line-tabs-limit nil
257 "Maximum number of buffer tabs displayed in the tab line.
258If nil, no limit.")
259
260(defcustom tab-line-tabs-function #'tab-line-tabs-window-buffers 264(defcustom tab-line-tabs-function #'tab-line-tabs-window-buffers
261 "Function to get a list of tabs to display in the tab line. 265 "Function to get a list of tabs to display in the tab line.
262This function should return either a list of buffers whose names will 266This function should return either a list of buffers whose names will
@@ -395,22 +399,9 @@ variable `tab-line-tabs-function'."
395 (prev-buffers (seq-filter #'buffer-live-p prev-buffers)) 399 (prev-buffers (seq-filter #'buffer-live-p prev-buffers))
396 ;; Remove next-buffers from prev-buffers 400 ;; Remove next-buffers from prev-buffers
397 (prev-buffers (seq-difference prev-buffers next-buffers))) 401 (prev-buffers (seq-difference prev-buffers next-buffers)))
398 (if (natnump tab-line-tabs-limit) 402 (append (reverse prev-buffers)
399 (let* ((half-limit (/ tab-line-tabs-limit 2)) 403 (list buffer)
400 (prev-buffers-limit 404 next-buffers)))
401 (if (> (length prev-buffers) half-limit)
402 (if (> (length next-buffers) half-limit)
403 half-limit
404 (+ half-limit (- half-limit (length next-buffers))))
405 (length prev-buffers)))
406 (next-buffers-limit
407 (- tab-line-tabs-limit prev-buffers-limit)))
408 (append (reverse (seq-take prev-buffers prev-buffers-limit))
409 (list buffer)
410 (seq-take next-buffers next-buffers-limit)))
411 (append (reverse prev-buffers)
412 (list buffer)
413 next-buffers))))
414 405
415 406
416(defun tab-line-format-template (tabs) 407(defun tab-line-format-template (tabs)
@@ -681,15 +672,17 @@ Its effect is the same as using the `next-buffer' command
681 (switch-to-buffer buffer))))))) 672 (switch-to-buffer buffer)))))))
682 673
683 674
684(defcustom tab-line-close-tab-action 'bury-buffer 675(defcustom tab-line-close-tab-function 'bury-buffer
685 "Defines what to do on closing the tab. 676 "Defines what to do on closing the tab.
686If `bury-buffer', put the tab's buffer at the end of the list of all 677If `bury-buffer', put the tab's buffer at the end of the list of all
687buffers that effectively hides the buffer's tab from the tab line. 678buffers that effectively hides the buffer's tab from the tab line.
688If `kill-buffer', kills the tab's buffer. 679If `kill-buffer', kills the tab's buffer.
680When a function, it is called with the tab as its argument.
689This option is useful when `tab-line-tabs-function' has the value 681This option is useful when `tab-line-tabs-function' has the value
690`tab-line-tabs-window-buffers'." 682`tab-line-tabs-window-buffers'."
691 :type '(choice (const :tag "Bury buffer" bury-buffer) 683 :type '(choice (const :tag "Bury buffer" bury-buffer)
692 (const :tag "Kill buffer" kill-buffer)) 684 (const :tag "Kill buffer" kill-buffer)
685 (function :tag "Function"))
693 :group 'tab-line 686 :group 'tab-line
694 :version "27.1") 687 :version "27.1")
695 688
@@ -703,18 +696,20 @@ from the tab line."
703 (window (and posnp (posn-window posnp))) 696 (window (and posnp (posn-window posnp)))
704 (tab (get-pos-property 1 'tab (car (posn-string posnp)))) 697 (tab (get-pos-property 1 'tab (car (posn-string posnp))))
705 (buffer (if (bufferp tab) tab (cdr (assq 'buffer tab)))) 698 (buffer (if (bufferp tab) tab (cdr (assq 'buffer tab))))
706 (close-action (unless (bufferp tab) (cdr (assq 'close tab))))) 699 (close-function (unless (bufferp tab) (cdr (assq 'close tab)))))
707 (with-selected-window (or window (selected-window)) 700 (with-selected-window (or window (selected-window))
708 (cond 701 (cond
709 ((functionp close-action) 702 ((functionp close-function)
710 (funcall close-action)) 703 (funcall close-function))
711 ((eq tab-line-close-tab-action 'kill-buffer) 704 ((eq tab-line-close-tab-function 'kill-buffer)
712 (kill-buffer buffer)) 705 (kill-buffer buffer))
713 ((eq tab-line-close-tab-action 'bury-buffer) 706 ((eq tab-line-close-tab-function 'bury-buffer)
714 (if (eq buffer (current-buffer)) 707 (if (eq buffer (current-buffer))
715 (bury-buffer) 708 (bury-buffer)
716 (set-window-prev-buffers nil (assq-delete-all buffer (window-prev-buffers))) 709 (set-window-prev-buffers nil (assq-delete-all buffer (window-prev-buffers)))
717 (set-window-next-buffers nil (delq buffer (window-next-buffers)))))) 710 (set-window-next-buffers nil (delq buffer (window-next-buffers)))))
711 ((functionp tab-line-close-tab-function)
712 (funcall tab-line-close-tab-function)))
718 (force-mode-line-update)))) 713 (force-mode-line-update))))
719 714
720 715