分组拆分缓冲区
标签栏是可能的。您可以将规则添加到组中的组缓冲区中。这是一个基本片段:
(defun tabbar-buffer-groups ()
"Returns the list of group names the current buffer belongs to."
(list
(cond
;; ADD RULES TO SPLIT BUFFERS IN GROUPS HERE!
;; if buffer is not grouped by the rules you would add above
;; put it in the "General" group:
(t
"General"
))))
规则示例:
- 列出缓冲区名称:
((member (buffer-name)
'("*scratch*" "*Messages*" "*Help*"))
"Common" ;; this is a group name
)
- 关于公共缓冲区,我更喜欢在每个以“星号”开头的缓冲区中放入“公共”。这给出了为该规则创建缓冲区的示例:
((string-equal "*" (substring (buffer-name) 0 1))
"Common"
)
- 以下是按主要模式对缓冲区进行分组的示例:
((memq major-mode
'(org-mode text-mode rst-mode))
"Text"
)
- 这是根据从中派生的模式对缓冲区进行分组的示例:
((or (get-buffer-process (current-buffer))
;; Check if the major mode derives from `comint-mode' or
;; `compilation-mode'.
(tabbar-buffer-mode-derived-p
major-mode '(comint-mode compilation-mode)))
"Process"
)
- 这是通过regexp对标签进行分组的示例:
((string-match "^__" (buffer-name))
"Templates"
)
- 按主要模式对缓冲区进行分组:
(if (and (stringp mode-name)
;; Take care of preserving the match-data because this
;; function is called when updating the header line.
(save-match-data (string-match "[^ ]" mode-name)))
mode-name
(symbol-name major-mode))
组成规则后,您可以在标签栏的标签线上按+或-切换组,也可以按◀和▶在缓冲区之间切换。或者只是绑定以下defuns:
tabbar-forward
tabbar-backward
tabbar-forward-group
tabbar-backward-group
并使用键盘在选项卡和选项卡组之间移动。
我个人将标签分组,以便查看打开的内容,但使用进行导航ido-switch-buffer
。
在一组规则之间切换
也可以定义一组不同的缓冲区分组规则,并在它们之间循环。这是在两组缓冲区分组规则之间循环的示例:
;; tab-groups!
(setq tbbr-md "common")
(defun toggle-tabbar-mode ()
"Toggles tabbar modes - all buffers vs. defined in the `tabbar-buffer-groups'."
(interactive)
(if (string= tbbr-md "groups")
(progn ;; then
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups-common)
(setq tbbr-md "common"))
(progn ;; else
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups)
(setq tbbr-md "groups"))))
;; by default - all tabs:
(setq tabbar-buffer-groups-function 'tabbar-buffer-groups-common)
这会在tabbar-buffer-groups-common
和tabbar-buffer-groups
选项卡分组定义之间切换。
按名称对标签栏缓冲区排序
我发现按名称对标签栏缓冲区进行排序很有益。取得方法如下:
(defun tabbar-add-tab (tabset object &optional append_ignored)
"Add to TABSET a tab with value OBJECT if there isn't one there yet.
If the tab is added, it is added at the beginning of the tab list,
unless the optional argument APPEND is non-nil, in which case it is
added at the end."
(let ((tabs (tabbar-tabs tabset)))
(if (tabbar-get-tab object tabset)
tabs
(let ((tab (tabbar-make-tab object tabset)))
(tabbar-set-template tabset nil)
(set tabset (sort (cons tab tabs)
(lambda (a b) (string< (buffer-name (car a)) (buffer-name (car b))))))))))