ema2159 / centaur-tabs

Emacs plugin aiming to become an aesthetic, modern looking tabs plugin
GNU General Public License v3.0
743 stars 51 forks source link
elisp emacs emacs-lisp emacs-package emacs-plugin

+TITLE: Centaur tabs

+CREATOR: Emmanuel Bustos T.

+OPTIONS: toc:nil

[[https://melpa.org/#/centaur-tabs][file:https://melpa.org/packages/centaur-tabs-badge.svg]] [[https://stable.melpa.org/#/centaur-tabs][file:https://stable.melpa.org/packages/centaur-tabs-badge.svg]] [[https://jcs-emacs.github.io/jcs-elpa/#/centaur-tabs][https://raw.githubusercontent.com/jcs-emacs/badges/master/elpa/v/centaur-tabs.svg]] [[http://www.gnu.org/licenses/gpl-3.0][file:https://img.shields.io/badge/License-GPL%20v3-blue.svg]] [[https://github.com/ema2159/centaur-tabs/actions/workflows/test.yml][https://github.com/ema2159/centaur-tabs/actions/workflows/test.yml/badge.svg]]

[[./images/centaur.png]]

** Tab height To change the tab height do

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-height 32)

+END_SRC

** Tab icons To display themed icons from all the icons

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-set-icons t)

+END_SRC

** Plain icons To make icons plain (same color as tabs' text):

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-plain-icons t)

+END_SRC

** Graying out icons To gray out icons for the unselected tabs:

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-gray-out-icons 'buffer)

+END_SRC

** Selected tab bar To display a colored bar at the left of the selected tab

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-set-bar 'left)

+END_SRC

[[./images/bar.png]]

To display an overline over the selected tab:

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-set-bar 'over)

+END_SRC

[[./images/overline.png]]

To display an underline over the selected tab:

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-set-bar 'under)
;; Note: If you're not using Spacmeacs, in order for the underline to display
;; correctly you must add the following line:
(setq x-underline-at-descent-line t)

+END_SRC

[[./images/underline.png]]

The color can be customized via the centaur-tabs-active-bar-face face. ** Customize the close button To disable the close button

+BEGIN_SRC emacs-lisp :tangle yes

(setq centaur-tabs-set-close-button nil)

+END_SRC

To change the displayed string for the close button

+BEGIN_SRC emacs-lisp :tangle yes

 (setq centaur-tabs-close-button "X")

+END_SRC

Also there are two faces to customize the close button string: centaur-tabs-close-unselected and centaur-tabs-close-selected ** Customize the modified marker To display a marker indicating that a buffer has been modified (atom-style)

+BEGIN_SRC emacs-lisp :tangle yes

 (setq centaur-tabs-set-modified-marker t)

+END_SRC

To change the displayed string for the modified-marker

+BEGIN_SRC emacs-lisp :tangle yes

 (setq centaur-tabs-modified-marker "*")

+END_SRC

Also there are two faces to customize the close button string: centaur-tabs-modified-marker-unselected and centaur-tabs-modified-marker-selected

[[./images/marker.png]] ** Change the font family and height To easily customize the tabs font by changing it's height and font family use the following function:

+BEGIN_SRC emacs-lisp :tangle yes

 (centaur-tabs-change-fonts "arial" 160)

+END_SRC

** Disable centaur-tabs in selected buffers To disable the tabs in a buffer just add a hook to the ~centaur-tabs-local-mode~ function like this:

+BEGIN_SRC emacs-lisp :tangle yes

 (add-hook 'dired-mode-hook 'centaur-tabs-local-mode)

+END_SRC

or with ~use-package~:

+BEGIN_SRC emacs-lisp :tangle yes

 (use-package centaur-tabs
   ...
   :hook
   (dired-mode . centaur-tabs-local-mode)
   ...)

+END_SRC

** Buffer groups To customize the way that the buffers are grouped modify the ~centaur-tabs-buffer-groups~ function like this:

+BEGIN_SRC emacs-lisp :tangle yes

 (defun centaur-tabs-buffer-groups ()
   "`centaur-tabs-buffer-groups' control buffers' group rules.

 Group centaur-tabs with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'.
 All buffer name start with * will group to \"Emacs\".
 Other buffer group by `centaur-tabs-get-group-name' with project name."
   (list
    (cond
     ((or (string-equal "*" (substring (buffer-name) 0 1))
          (memq major-mode '(magit-process-mode
                             magit-status-mode
                             magit-diff-mode
                             magit-log-mode
                             magit-file-mode
                             magit-blob-mode
                             magit-blame-mode
                             )))
      "Emacs")
     ((derived-mode-p 'prog-mode)
      "Editing")
     ((derived-mode-p 'dired-mode)
      "Dired")
     ((memq major-mode '(helpful-mode
                         help-mode))
      "Help")
     ((memq major-mode '(org-mode
                         org-agenda-clockreport-mode
                         org-src-mode
                         org-agenda-mode
                         org-beamer-mode
                         org-indent-mode
                         org-bullets-mode
                         org-cdlatex-mode
                         org-agenda-log-mode
                         diary-mode))
      "OrgMode")
     (t
      (centaur-tabs-get-group-name (current-buffer))))))

+END_SRC

** Show buffer groups names instead of buffer names in tabs If you want your tabs to display buffer groups names instead of buffer names you can put the following in your configuration:

+BEGIN_SRC emacs-lisp :tangle yes

 (setq centaur-tabs--buffer-show-groups t)

+END_SRC

You can toggle between the two options interactively with the ~(centaur-tabs-toggle-groups)~ command. ** Enable Vim like tab motions To enable Vim like tab changing binds

+BEGIN_SRC emacs-lisp :tangle yes

 (define-key evil-normal-state-map (kbd "g t") 'centaur-tabs-forward)
 (define-key evil-normal-state-map (kbd "g T") 'centaur-tabs-backward)

+END_SRC

or with ~use-package~:

+BEGIN_SRC emacs-lisp :tangle yes

 (use-package centaur-tabs
   ...
   :bind
   (:map evil-normal-state-map
         ("g t" . centaur-tabs-forward)
         ("g T" . centaur-tabs-backward))
   ...)

+END_SRC

** Prevent the access to specified buffers You can prevent the access to some buffers via tab motions changing the following function like this:

+BEGIN_SRC emacs-lisp :tangle yes

(defun centaur-tabs-hide-tab (x) "Do no to show buffer X in tabs." (let ((name (format "%s" x))) (or ;; Current window is not dedicated window. (window-dedicated-p (selected-window))

 ;; Buffer name not match below blacklist.
 (string-prefix-p "*epc" name)
 (string-prefix-p "*helm" name)
 (string-prefix-p "*Helm" name)
 (string-prefix-p "*Compile-Log*" name)
 (string-prefix-p "*lsp" name)
 (string-prefix-p "*company" name)
 (string-prefix-p "*Flycheck" name)
 (string-prefix-p "*tramp" name)
 (string-prefix-p " *Mini" name)
 (string-prefix-p "*help" name)
 (string-prefix-p "*straight" name)
 (string-prefix-p " *temp" name)
 (string-prefix-p "*Help" name)
 (string-prefix-p "*mybuf" name)

 ;; Is not magit buffer.
 (and (string-prefix-p "magit" name)
      (not (file-name-extension name)))
 )))
 #+END_SRC
 The function shown is the default function from the =centaur-tabs= configuration, adding the =(string-prefix-p "*​mybuf" name)= part to prevent the access to every buffer with its name ending in "mybuf". You can either add this function as it is to preserve =centaur-tabs= default filters and add any Boolean function that you want to filter your buffers (i.e =string-prefix-p= or =string-suffix-p=) like in this example with the "mybuf" line, or completely override the function with your custom filters if you completely know what you're doing.

** Tab cycling The default behaviour from the ~centaur-tabs-forward/backward~ functions is to go through all the tabs in the current group and then change the group. If this is something that is to desired to be changed the ~centaur-tabs-cycle-scope~ custom must be changed like this:

+BEGIN_SRC emacs-lisp :tangle yes

 (setq centaur-tabs-cycle-scope 'tabs)

+END_SRC

There are three options:

[[https://github.com/raxod502/selectrum][Selectrum]] integration (revert to ~completing-read~) Turn off default ~ido-mode~ completions by customising ~centaur-tabs-enable-ido-completion~ in order to revert to Emacs' native ~completing-read~. Helm integration You can integrate Helm with centaur-tabs for changing tab-groups. Just add helm-source-centaur-tabs-group in helm-source-list. Then you'll be able to use ~(centaur-tabs-build-helm-source)~ function and bind it to any key you want. (I'm not a Helm user so I'll not be able to solve problems related to this). Ivy integration You can integrate Ivy with centaur-tabs for changing tab-groups. Just use the ~(centaur-tabs-counsel-switch-group)~ and bind it to any key you want. Projectile integration You can group your tabs by Projectile's project. Just use the following function in your configuration:

+BEGIN_SRC emacs-lisp :tangle yes

 (centaur-tabs-group-by-projectile-project)

+END_SRC

This function can be called interactively to enable Projectile grouping. To go back to centaur-tabs's user defined (or default) buffer grouping function you can interactively call:

+BEGIN_SRC emacs-lisp :tangle yes

 (centaur-tabs-group-buffer-groups)

+END_SRC

** Mouse support (thanks to alvarogonzalezsotillo)

** Tab count (thanks to kamilwaheed) Adds a count of the current tab position in the total number of tabs in the current window. Controlled by the variable ~centaur-tabs-show-count~.

** Ace jump (thanks to Simon-Lin) Enables quick tab switching through an Ace-jump/Avy-like interface. To use it, interactively call the ~centaur-tabs-ace-jump~ function. While on Ace-jump mode, you can press ~?~ to display a menu showing the possible actions available. [[file:images/ace-jump.png]]

** Key bindings If you want to enable a series of key bindings with different tab managing functions, put the following in your configuration before the package is loaded (if you use =use-package=, this should go in the =:init= section):

+BEGIN_SRC emacs-lisp

 (setq centaur-tabs-enable-key-bindings t)

+END_SRC

This will enable a series of key bindings for centaur-tabs prefixed by "C-c t".

+BEGIN_SRC emacs-lisp :tangle yes

(use-package centaur-tabs :init (setq centaur-tabs-enable-key-bindings t) :config (setq centaur-tabs-style "bar" centaur-tabs-height 32 centaur-tabs-set-icons t centaur-tabs-show-new-tab-button t centaur-tabs-set-modified-marker t centaur-tabs-show-navigation-buttons t centaur-tabs-set-bar 'under centaur-tabs-show-count nil ;; centaur-tabs-label-fixed-length 15 ;; centaur-tabs-gray-out-icons 'buffer ;; centaur-tabs-plain-icons t x-underline-at-descent-line t centaur-tabs-left-edge-margin nil) (centaur-tabs-change-fonts (face-attribute 'default :font) 110) (centaur-tabs-headline-match) ;; (centaur-tabs-enable-buffer-alphabetical-reordering) ;; (setq centaur-tabs-adjust-buffer-order t) (centaur-tabs-mode t) (setq uniquify-separator "/") (setq uniquify-buffer-name-style 'forward) (defun centaur-tabs-buffer-groups () "`centaur-tabs-buffer-groups' control buffers' group rules.

Group centaur-tabs with mode if buffer is derived from eshell-mode'emacs-lisp-mode' dired-mode'org-mode' magit-mode'. All buffer name start with * will group to \"Emacs\". Other buffer group bycentaur-tabs-get-group-name' with project name." (list (cond ;; ((not (eq (file-remote-p (buffer-file-name)) nil)) ;; "Remote") ((or (string-equal "*" (substring (buffer-name) 0 1)) (memq major-mode '(magit-process-mode magit-status-mode magit-diff-mode magit-log-mode magit-file-mode magit-blob-mode magit-blame-mode ))) "Emacs") ((derived-mode-p 'prog-mode) "Editing") ((derived-mode-p 'dired-mode) "Dired") ((memq major-mode '(helpful-mode help-mode)) "Help") ((memq major-mode '(org-mode org-agenda-clockreport-mode org-src-mode org-agenda-mode org-beamer-mode org-indent-mode org-bullets-mode org-cdlatex-mode org-agenda-log-mode diary-mode)) "OrgMode") (t (centaur-tabs-get-group-name (current-buffer)))))) :hook (dashboard-mode . centaur-tabs-local-mode) (term-mode . centaur-tabs-local-mode) (calendar-mode . centaur-tabs-local-mode) (org-agenda-mode . centaur-tabs-local-mode) :bind ("C-" . centaur-tabs-backward) ("C-" . centaur-tabs-forward) ("C-S-" . centaur-tabs-move-current-tab-to-left) ("C-S-" . centaur-tabs-move-current-tab-to-right) (:map evil-normal-state-map ("g t" . centaur-tabs-forward) ("g T" . centaur-tabs-backward)))

+END_SRC

it is likely that you're missing a font that has the required unicode symbols. To solve this issue, simply install a font that has this symbols such as Google Noto Sans Symbols2.