[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re:Re: [patch] two patchs about tab-bar.el
From: |
tumashu |
Subject: |
Re:Re: [patch] two patchs about tab-bar.el |
Date: |
Sat, 11 Sep 2021 02:33:51 +0800 (CST) |
This is my tab-bar config
---------------------------------------------------------------------
;; ** buffer 显示方式
(setq switch-to-buffer-obey-display-actions t)
(setq display-buffer-alist
'((eh-display-buffer-in-tab-p
display-buffer-in-tab
(reusable-frames . visible))))
(defun eh-display-buffer-in-tab-p (buffer-name alist)
(with-current-buffer (get-buffer buffer-name)
(and
;; Minibuffer.
(not (minibufferp buffer-name))
;; Python, Term 等 buffer.
(not (derived-mode-p 'comint-mode))
(not (derived-mode-p 'term-mode))
;; magit 相关 buffer
(not (string-match-p "magit" buffer-name))
(not (string-match-p "COMMIT_EDITMSG" buffer-name))
;; gnus 相关 buffer
(not (derived-mode-p 'gnus-article-mode))
;; 隐藏的 buffer
(not (string-match-p "^ +" buffer-name)))))
;; ** 开启 tab-bar
(tab-bar-mode 1)
(tab-bar-history-mode 1)
(global-set-key (kbd "C-t") 'tab-bar-switch-to-recent-tab)
(global-set-key (kbd "C-c t") 'tab-switcher)
(setq tab-bar-format
'(tab-bar-format-tabs
tab-bar-separator))
(setq tab-bar-separator " ")
(setq tab-bar-tab-hints t)
(setq tab-bar-close-button-show 'selected)
(setq tab-bar-tab-name-function
#'eh-tab-bar-tab-name)
(defun eh-tab-bar-tab-name ()
(mapconcat (lambda (buf)
(let ((tab-name (buffer-name buf))
(length 20))
(if (< (string-width tab-name) length)
tab-name
(propertize (truncate-string-to-width
tab-name length nil nil
tab-bar-tab-name-ellipsis)
'help-echo tab-name))))
(delete-dups (mapcar #'window-buffer
(window-list-1 (frame-first-window)
'nomini)))
", "))
(defun eh-tab-bar-rename-tab ()
(tab-bar-rename-tab ""))
(add-hook 'window-configuration-change-hook #'eh-tab-bar-rename-tab)
(add-hook 'buffer-list-update-hook #'eh-tab-bar-rename-tab)
(setq tab-bar-tab-name-format-function
#'eh-tab-bar-tab-name-format-default)
(defun eh-tab-bar-tab-name-format-default (tab i)
(let ((current-p (eq (car tab) 'current-tab)))
(propertize
(concat (if tab-bar-tab-hints (format "[%d] " i) "")
(alist-get 'name tab)
(or (and tab-bar-close-button-show
(not (eq tab-bar-close-button-show
(if current-p 'non-selected 'selected)))
tab-bar-close-button)
""))
'face (funcall tab-bar-tab-face-function tab))))
(defun eh-buffer-used-by-org-agenda-p (buffer)
(and (get-buffer "*Org Agenda*")
(with-current-buffer buffer
(and (derived-mode-p 'org-mode)
(member (buffer-file-name)
(org-agenda-files))))))
(defun eh-kill-buffer (buffer)
(interactive)
(let ((buffer-name (buffer-name buffer)))
(cond
((equal buffer-name "*scratch*")
(message "NOTE: do not kill *scratch* buffer."))
((eh-buffer-used-by-org-agenda-p buffer)
(message "NOTE: buffer %S is used by org-agenda, do not kill it."
buffer-name))
((tab-bar-get-buffer-tab buffer t t)
(message "Warn: buffer %S has been managed by other tab, do not kill it."
buffer-name))
(t (message "Kill buffer %S." buffer-name)
(kill-buffer buffer)))))
(defun eh-tab-bar-close-tab (orig-func &rest args)
(interactive)
(let* ((use-dialog-box t)
(n (length (window-list)))
(buffers (mapcar #'window-buffer (window-list)))
(tabs (funcall tab-bar-tabs-function))
(current-index (tab-bar--current-tab-index tabs))
(close-index (when (integerp (car args)) (1- (car args)))))
(if (or (not close-index)
(eq close-index current-index))
;; 如果要关闭的 tab 是 current tab, 就将 buffer 也删除。
(progn
(cond ((memq this-command
'(tab-bar-close-tab
tab-close))
(eh-kill-buffer (current-buffer)))
((memq this-command
'(tab-bar-mouse-close-tab
tab-bar-mouse-select-tab))
(dolist (buffer buffers)
(eh-kill-buffer buffer)))
(t (message "Note: do not kill any buffer.")))
(let ((tab-bar-close-last-tab-choice
`(@,tab-bar-close-last-tab-choice eh-tab-bar-rename-tab)))
(if (and (equal this-command 'tab-bar-close-tab)
(> n 1))
(funcall-interactively #'delete-window)
(apply orig-func args))))
;; 如果删除的 tab 不是 current tab, 就不删除任何 buffer.
(apply orig-func args))))
(advice-add 'tab-bar-close-tab :around #'eh-tab-bar-close-tab)
(global-set-key (kbd "C-x k") 'tab-bar-close-tab)
At 2021-09-10 14:33:48, "Juri Linkov" <juri@linkov.net> wrote:
>> * lisp/tab-bar.el (tab-bar-get-buffer-tab): Fix issue when
>> 'current-tab is not at the beginning of tabs.
>>
>> --- a/lisp/tab-bar.el
>> +++ b/lisp/tab-bar.el
>> @@ -1940,7 +1940,9 @@ tab-bar-get-buffer-tab
>> - (funcall tab-bar-tabs-function frame)))
>> + (let ((tabs (funcall tab-bar-tabs-function frame)))
>> + ;; Make sure current-tab is alway at the beginning of tabs.
>> + (push (assq 'current-tab tabs) tabs))))
>
>Please explain what problem this patch is intended to fix.
>
>> --- a/lisp/tab-bar.el
>> +++ b/lisp/tab-bar.el
>> @@ -1962,11 +1962,12 @@ display-buffer-in-tab
>>
>> If ALIST contains a `reusable-frames' entry, its value determines
>> which frames to search for a reusable tab:
>> - nil -- the selected frame (actually the last non-minibuffer frame)
>> + nil -- do not reuse any frames.
>> A frame -- just that frame
>> `visible' -- all visible frames
>> 0 -- all frames on the current terminal
>> t -- all frames.
>> + others -- selected frame.
>
>I wonder where did you get the value 'others' that means the selected frame?
Re: [patch] two patchs about tab-bar.el, Feng Shu, 2021/09/10