Skip to content

Instantly share code, notes, and snippets.

@jclosure
Created April 28, 2019 09:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jclosure/e9d04250c53f899003d723945881cd21 to your computer and use it in GitHub Desktop.
Save jclosure/e9d04250c53f899003d723945881cd21 to your computer and use it in GitHub Desktop.
Emacs - make tabbar groups based on projectile project membership
;; Make tabbar groups based on projectile project membership
;;; Nice hack of the group function;; Make tabbar groups based on projectile project membership to add projectile aware-ness.
;;; Assign buffer with group name projectile project name if
;;; the buffer is within the project and associated to a file or process.
(use-package tabbar :ensure t
:after projectile
:config
(defun tabbar-buffer-groups ()
"Return the list of group names the current buffer belongs to.
Return a list of one element based on major mode."
(list
(cond
((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"
)
((member (buffer-name)
'("*scratch*" "*Messages*" "*dashboard*" "TAGS"))
"Common"
)
((eq major-mode 'dired-mode)
"Dired"
)
((memq major-mode
'(help-mode apropos-mode Info-mode Man-mode))
"Help"
)
((memq major-mode
'(rmail-mode
rmail-edit-mode vm-summary-mode vm-mode mail-mode
mh-letter-mode mh-show-mode mh-folder-mode
gnus-summary-mode message-mode gnus-group-mode
gnus-article-mode score-mode gnus-browse-killed-mode))
"Mail"
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Group tabs by projectile projects
((memq (current-buffer)
(condition-case nil
(projectile-buffers-with-file-or-process (projectile-project-buffers))
(error nil)))
(projectile-project-name)
)
;;; end of hacking
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(t
;; Return `mode-name' if not blank, `major-mode' otherwise.
(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))
))))
(tabbar-mode )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment