aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2019-10-02 23:18:01 +0300
committerJuri Linkov2019-10-02 23:18:01 +0300
commit52ab9485107919771d3627b93c8a996563b34abd (patch)
tree38cea17e3e023ee71779d6b878c516d2b38ef0ff
parent5eb2477be214d379128a5527f67e0f7afcc4499b (diff)
downloademacs-52ab9485107919771d3627b93c8a996563b34abd.tar.gz
emacs-52ab9485107919771d3627b93c8a996563b34abd.zip
* lisp/tab-bar.el (tab-bar-show): New defcustom.
* lisp/tab-bar.el (tab-bar-close-current-tab, tab-bar-close-tab): (tab-bar-new-tab): Use tab-bar-show. * doc/emacs/frames.texi (Tab Bars): Add tab-bar-show. * lisp/speedbar.el (speedbar-mode): Set buffer-local tab-bar-mode and tab-line-format to nil to not show in dedicated speedbar frame.
-rw-r--r--doc/emacs/frames.texi13
-rw-r--r--lisp/speedbar.el4
-rw-r--r--lisp/tab-bar.el67
-rw-r--r--lisp/tab-line.el3
4 files changed, 72 insertions, 15 deletions
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 0003881fad1..0cb9c4eb1d7 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -1242,6 +1242,19 @@ command applies to all frames, including frames yet to be created. To
1242control the use of tab bars at startup, customize the variable 1242control the use of tab bars at startup, customize the variable
1243@code{tab-bar-mode}. 1243@code{tab-bar-mode}.
1244 1244
1245@vindex tab-bar-show
1246@cindex Tab Bar show
1247 This variable is intended to toggle the tab bar automatically.
1248When the value is @code{t}, then @code{tab-bar-mode} is enabled when
1249using the commands that create new window configurations. The value
1250@code{1} hides the tab bar when it has only one tab, and shows it
1251again once more tabs are created. If @code{nil}, always keep the tab
1252bar hidden. In this case it's still possible to use persistent named
1253window configurations without using the tab bar by relying on keyboard
1254commands that create a new window configuration (@kbd{M-x tab-new}),
1255that switch windows configurations (@kbd{M-x tab-next}, @kbd{M-x
1256tab-list}), or delete the existing ones (@kbd{M-x tab-close}).
1257
1245@vindex tab-bar-new-tab-choice 1258@vindex tab-bar-new-tab-choice
1246@cindex Tab Bar new tab 1259@cindex Tab Bar new tab
1247 By default, Emacs follows the same behavior as when creating frames, 1260 By default, Emacs follows the same behavior as when creating frames,
diff --git a/lisp/speedbar.el b/lisp/speedbar.el
index e4e67349949..addb2b42bb7 100644
--- a/lisp/speedbar.el
+++ b/lisp/speedbar.el
@@ -1115,7 +1115,9 @@ in the selected file.
1115 (setq dframe-track-mouse-function #'speedbar-track-mouse)) 1115 (setq dframe-track-mouse-function #'speedbar-track-mouse))
1116 (setq dframe-help-echo-function #'speedbar-item-info 1116 (setq dframe-help-echo-function #'speedbar-item-info
1117 dframe-mouse-click-function #'speedbar-click 1117 dframe-mouse-click-function #'speedbar-click
1118 dframe-mouse-position-function #'speedbar-position-cursor-on-line)) 1118 dframe-mouse-position-function #'speedbar-position-cursor-on-line)
1119 (setq-local tab-bar-mode nil)
1120 (setq-local tab-line-format nil))
1119 speedbar-buffer) 1121 speedbar-buffer)
1120 1122
1121(define-obsolete-function-alias 'speedbar-message 'dframe-message "24.4") 1123(define-obsolete-function-alias 'speedbar-message 'dframe-message "24.4")
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index 42d40a96543..6d2c915aa67 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -96,9 +96,9 @@
96 (assq-delete-all 'tab-bar-lines 96 (assq-delete-all 'tab-bar-lines
97 default-frame-alist))))) 97 default-frame-alist)))))
98 (when tab-bar-mode 98 (when tab-bar-mode
99 (global-set-key [(control shift iso-lefttab)] 'tab-bar-switch-to-prev-tab) 99 (global-set-key [(control shift iso-lefttab)] 'tab-previous)
100 (global-set-key [(control shift tab)] 'tab-bar-switch-to-prev-tab) 100 (global-set-key [(control shift tab)] 'tab-previous)
101 (global-set-key [(control tab)] 'tab-bar-switch-to-next-tab))) 101 (global-set-key [(control tab)] 'tab-next)))
102 102
103(defun tab-bar-handle-mouse (event) 103(defun tab-bar-handle-mouse (event)
104 "Text-mode emulation of switching tabs on the tab bar. 104 "Text-mode emulation of switching tabs on the tab bar.
@@ -152,6 +152,28 @@ Its main job is to show tabs in the tab bar."
152 (puthash key tab-bar-map tab-bar-keymap-cache))))) 152 (puthash key tab-bar-map tab-bar-keymap-cache)))))
153 153
154 154
155(defcustom tab-bar-show t
156 "Defines when to show the tab bar.
157If t, enable `tab-bar-mode' automatically on using the commands that
158create new window configurations (e.g. `tab-new').
159If the value is `1', then hide the tab bar when it has only one tab,
160and show it again once more tabs are created.
161If nil, always keep the tab bar hidden. In this case it's still
162possible to use persistent named window configurations by relying on
163keyboard commands `tab-list', `tab-new', `tab-close', `tab-next', etc."
164 :type '(choice (const :tag "Always" t)
165 (const :tag "When more than one tab" 1)
166 (const :tag "Never" nil))
167 :initialize 'custom-initialize-default
168 :set (lambda (sym val)
169 (set-default sym val)
170 (tab-bar-mode
171 (if (or (eq val t)
172 (and (natnump val) (> (length (tab-bar-tabs)) val)))
173 1 -1)))
174 :group 'tab-bar
175 :version "27.1")
176
155(defcustom tab-bar-new-tab-choice t 177(defcustom tab-bar-new-tab-choice t
156 "Defines what to show in a new tab. 178 "Defines what to show in a new tab.
157If t, start a new tab with the current buffer, i.e. the buffer 179If t, start a new tab with the current buffer, i.e. the buffer
@@ -192,8 +214,9 @@ If nil, don't show it at all."
192 (const :tag "On selected tab" selected) 214 (const :tag "On selected tab" selected)
193 (const :tag "On non-selected tabs" non-selected) 215 (const :tag "On non-selected tabs" non-selected)
194 (const :tag "None" nil)) 216 (const :tag "None" nil))
217 :initialize 'custom-initialize-default
195 :set (lambda (sym val) 218 :set (lambda (sym val)
196 (set sym val) 219 (set-default sym val)
197 (force-mode-line-update)) 220 (force-mode-line-update))
198 :group 'tab-bar 221 :group 'tab-bar
199 :version "27.1") 222 :version "27.1")
@@ -354,7 +377,8 @@ Return its existing value or a new value."
354 ((eq (car (car tabs)) 'current-tab) 377 ((eq (car (car tabs)) 'current-tab)
355 (setcar tabs new-tab))) 378 (setcar tabs new-tab)))
356 (setq tabs (cdr tabs))) 379 (setq tabs (cdr tabs)))
357 (force-mode-line-update)))) 380 (when tab-bar-mode
381 (force-mode-line-update)))))
358 382
359(defun tab-bar-switch-to-prev-tab (&optional _arg) 383(defun tab-bar-switch-to-prev-tab (&optional _arg)
360 "Switch to ARGth previous tab." 384 "Switch to ARGth previous tab."
@@ -389,11 +413,14 @@ If `rightmost', create as the last tab."
389(defun tab-bar-new-tab () 413(defun tab-bar-new-tab ()
390 "Clone the current tab to the position specified by `tab-bar-new-tab-to'." 414 "Clone the current tab to the position specified by `tab-bar-new-tab-to'."
391 (interactive) 415 (interactive)
392 (unless tab-bar-mode
393 (tab-bar-mode 1))
394 (let* ((tabs (tab-bar-tabs)) 416 (let* ((tabs (tab-bar-tabs))
395 ;; (i-tab (- (length tabs) (length (memq tab tabs)))) 417 ;; (i-tab (- (length tabs) (length (memq tab tabs))))
396 (new-tab (tab-bar-tab-default))) 418 (new-tab (tab-bar-tab-default)))
419 (when (and (not tab-bar-mode)
420 (or (eq tab-bar-show t)
421 (and (natnump tab-bar-show)
422 (>= (length tabs) tab-bar-show))))
423 (tab-bar-mode 1))
397 (cond 424 (cond
398 ((eq tab-bar-new-tab-to 'leftmost) 425 ((eq tab-bar-new-tab-to 'leftmost)
399 (setq tabs (cons new-tab tabs))) 426 (setq tabs (cons new-tab tabs)))
@@ -415,6 +442,9 @@ If `rightmost', create as the last tab."
415 (tab-bar-select-tab new-tab) 442 (tab-bar-select-tab new-tab)
416 (when tab-bar-new-tab-choice 443 (when tab-bar-new-tab-choice
417 (delete-other-windows) 444 (delete-other-windows)
445 ;; Create a new window to get rid of old window parameters
446 ;; (e.g. prev/next buffers) of old window.
447 (split-window) (delete-window)
418 (let ((buffer 448 (let ((buffer
419 (if (functionp tab-bar-new-tab-choice) 449 (if (functionp tab-bar-new-tab-choice)
420 (funcall tab-bar-new-tab-choice) 450 (funcall tab-bar-new-tab-choice)
@@ -463,6 +493,10 @@ if its value is provided."
463 (setq tabs (delq tab tabs) 493 (setq tabs (delq tab tabs)
464 i-select (max 0 (min (1- (length tabs)) i-select)) 494 i-select (max 0 (min (1- (length tabs)) i-select))
465 select-tab (nth i-select tabs)))) 495 select-tab (nth i-select tabs))))
496 (when (and tab-bar-mode
497 (and (natnump tab-bar-show)
498 (<= (length tabs) tab-bar-show)))
499 (tab-bar-mode -1))
466 (set-frame-parameter nil 'tabs tabs) 500 (set-frame-parameter nil 'tabs tabs)
467 (tab-bar-select-tab select-tab))) 501 (tab-bar-select-tab select-tab)))
468 502
@@ -474,9 +508,15 @@ specified by `tab-bar-close-tab-select'."
474 (when tab 508 (when tab
475 (if (eq (car tab) 'current-tab) 509 (if (eq (car tab) 'current-tab)
476 (tab-bar-close-current-tab tab) 510 (tab-bar-close-current-tab tab)
477 ;; Close non-current tab, no need to switch to another tab 511 (let ((tabs (tab-bar-tabs)))
478 (set-frame-parameter nil 'tabs (delq tab (tab-bar-tabs))) 512 ;; Close non-current tab, no need to switch to another tab
479 (force-mode-line-update)))) 513 (when (and tab-bar-mode
514 (and (natnump tab-bar-show)
515 (<= (length tabs) tab-bar-show)))
516 (tab-bar-mode -1))
517 (set-frame-parameter nil 'tabs (delq tab tabs))
518 (when tab-bar-mode
519 (force-mode-line-update))))))
480 520
481 521
482;;; Non-graphical access to frame-local tabs (named window configurations) 522;;; Non-graphical access to frame-local tabs (named window configurations)
@@ -733,7 +773,8 @@ in the selected frame."
733Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab." 773Like \\[switch-to-buffer-other-frame] (which see), but creates a new tab."
734 (interactive 774 (interactive
735 (list (read-buffer-to-switch "Switch to buffer in other tab: "))) 775 (list (read-buffer-to-switch "Switch to buffer in other tab: ")))
736 (tab-bar-new-tab) 776 (let ((tab-bar-new-tab-choice t))
777 (tab-bar-new-tab))
737 (delete-other-windows) 778 (delete-other-windows)
738 (switch-to-buffer buffer-or-name norecord)) 779 (switch-to-buffer buffer-or-name norecord))
739 780
@@ -752,8 +793,8 @@ Like \\[find-file-other-frame] (which see), but creates a new tab."
752 value) 793 value)
753 (switch-to-buffer-other-tab value)))) 794 (switch-to-buffer-other-tab value))))
754 795
755(define-key ctl-x-6-map "2" 'tab-bar-new-tab) 796(define-key ctl-x-6-map "2" 'tab-new)
756(define-key ctl-x-6-map "0" 'tab-bar-close-current-tab) 797(define-key ctl-x-6-map "0" 'tab-close)
757(define-key ctl-x-6-map "b" 'switch-to-buffer-other-tab) 798(define-key ctl-x-6-map "b" 'switch-to-buffer-other-tab)
758(define-key ctl-x-6-map "f" 'find-file-other-tab) 799(define-key ctl-x-6-map "f" 'find-file-other-tab)
759(define-key ctl-x-6-map "\C-f" 'find-file-other-tab) 800(define-key ctl-x-6-map "\C-f" 'find-file-other-tab)
diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 62e06a797d5..b552df9ba58 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -147,8 +147,9 @@ If nil, don't show it at all."
147 (const :tag "On selected tab" selected) 147 (const :tag "On selected tab" selected)
148 (const :tag "On non-selected tabs" non-selected) 148 (const :tag "On non-selected tabs" non-selected)
149 (const :tag "None" nil)) 149 (const :tag "None" nil))
150 :initialize 'custom-initialize-default
150 :set (lambda (sym val) 151 :set (lambda (sym val)
151 (set sym val) 152 (set-default sym val)
152 (force-mode-line-update)) 153 (force-mode-line-update))
153 :group 'tab-line 154 :group 'tab-line
154 :version "27.1") 155 :version "27.1")