Split buffers in groups
It is possible with tabbar. You can add rules to group buffers in groups. Here's a basic snippet:
(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"
))))
Example rules:
- List buffer names:
((member (buffer-name)
'("*scratch*" "*Messages*" "*Help*"))
"Common" ;; this is a group name
)
- Regarding common buffers I prefer to put in "Common" each buffer which name starts with a star. This gives an example of making a buffer for this rule:
((string-equal "*" (substring (buffer-name) 0 1))
"Common"
)
- Here's an example of grouping buffers by major-mode:
((memq major-mode
'(org-mode text-mode rst-mode))
"Text"
)
- Here's an example of grouping buffers based on mode they are derived from:
((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"
)
- Here's an example of grouping tabs by regexp:
((string-match "^__" (buffer-name))
"Templates"
)
- Group buffers by major mode:
(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))
Once you composed the rules, you can press on + or - on tabbar's tab line to toggle groups, and also ◀ and ▶ to switch between buffers. Or just bind the following defuns:
tabbar-forward
tabbar-backward
tabbar-forward-group
tabbar-backward-group
and move between tabs and tab groups with keyboard.
Personally I group tabs, so that I see what is open, but navigate them with ido-switch-buffer
.
Switch between set of rules
Also one can define different set of buffer grouping rules and cycle between these. Here's an example of cycling between two set of buffer grouping rules:
;; 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)
This toggles between tabbar-buffer-groups-common
and tabbar-buffer-groups
tab grouping defuns.
Sort tabbar buffers by name
I find it beneficial to sort tabbar buffers by name. Here's how to get it:
(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))))))))))
tabbar-buffer-groups-function
istabbar-buffer-groups
, which groups tabs based upon predefined sets that can be seen by looking at the source code and on wiki. You can create your own groups -- tasks, code, web-reading. You can switch between groups. You can have multiple windows open in the frame, and each window can have a different group showing. I took it one step further and group tabs based upon particular frames, which requires marring tabbar with frame-bufs (by Alp Aker) -- this enables me to associate buffers and tabs with a particular frame. – lawlist Mar 17 '15 at 17:34window-parameter
to store the list of associated buffers, using the same concept that frame-bufs uses. http://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Parameters.html E.g., add / remove buffers from the window-parameter list and have that be a buffer group. Some thought would need to be given with respect to how to update the buffer-groups -- e.g., visit only the current window in the current frame. Again, this is only theoretical at this point in time. – lawlist Mar 17 '15 at 20:15i3
which besides tiling, also has tabbed containers for windows. I definitely recommend it. – Omar Mar 20 '15 at 13:46