├── .gitignore ├── images ├── bar.png ├── box.png ├── slant.png ├── wave.png ├── centaur.png ├── chamfer.png ├── marker.png ├── rounded.png ├── zigzag.png ├── ace-jump.png ├── alternate.png ├── overline.png ├── underline.png ├── font-missing.png ├── tab-context-menu.png └── navigation-buttons.png ├── screenshot.png ├── .dir-locals.el ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── CHANGELOG.md ├── Eask ├── Makefile ├── centaur-tabs.el ├── README.org ├── centaur-tabs-interactive.el ├── LICENSE ├── centaur-tabs-elements.el └── centaur-tabs-functions.el /.gitignore: -------------------------------------------------------------------------------- 1 | *.elc 2 | 3 | /.eask 4 | /dist 5 | -------------------------------------------------------------------------------- /images/bar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/bar.png -------------------------------------------------------------------------------- /images/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/box.png -------------------------------------------------------------------------------- /images/slant.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/slant.png -------------------------------------------------------------------------------- /images/wave.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/wave.png -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/screenshot.png -------------------------------------------------------------------------------- /images/centaur.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/centaur.png -------------------------------------------------------------------------------- /images/chamfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/chamfer.png -------------------------------------------------------------------------------- /images/marker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/marker.png -------------------------------------------------------------------------------- /images/rounded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/rounded.png -------------------------------------------------------------------------------- /images/zigzag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/zigzag.png -------------------------------------------------------------------------------- /images/ace-jump.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/ace-jump.png -------------------------------------------------------------------------------- /images/alternate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/alternate.png -------------------------------------------------------------------------------- /images/overline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/overline.png -------------------------------------------------------------------------------- /images/underline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/underline.png -------------------------------------------------------------------------------- /images/font-missing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/font-missing.png -------------------------------------------------------------------------------- /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((emacs-lisp-mode 2 | . 3 | ((tab-width . 8) 4 | (indent-tabs-mode . nil)))) 5 | -------------------------------------------------------------------------------- /images/tab-context-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/tab-context-menu.png -------------------------------------------------------------------------------- /images/navigation-buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ema2159/centaur-tabs/HEAD/images/navigation-buttons.png -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: daily 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 6 | 7 | 8 | ## 3.3 (Unreleased) 9 | > Released N/A 10 | 11 | * feat: Handle change theme (9f04a13db07c102542f2b6ab05ba3e855178df15) 12 | 13 | ## 3.2 14 | > Released Sep 20, 2022 15 | 16 | * Tab context menu 17 | * Frame local visualization for daemon mode 18 | * New tab button 19 | * Enable support for completing-read to be able to use 20 | * Add optional tab index/count 21 | * Fix several bugs 22 | -------------------------------------------------------------------------------- /Eask: -------------------------------------------------------------------------------- 1 | ;; -*- mode: eask; lexical-binding: t -*- 2 | 3 | (package "centaur-tabs" 4 | "3.3" 5 | "Aesthetic, modern looking customizable tabs plugin") 6 | 7 | (website-url "https://github.com/ema2159/centaur-tabs") 8 | (keywords "frames") 9 | 10 | (package-file "centaur-tabs.el") 11 | 12 | (script "test" "echo \"Error: no test specified\" && exit 1") 13 | 14 | (source 'gnu) 15 | (source 'melpa) 16 | 17 | (depends-on "emacs" "27.1") 18 | (depends-on "powerline") 19 | 20 | (setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432 21 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | EMACS ?= emacs 2 | EASK ?= eask 3 | 4 | .PHONY: clean checkdoc lint package install compile test 5 | 6 | ci: clean package install compile 7 | 8 | package: 9 | @echo "Packaging..." 10 | $(EASK) package 11 | 12 | install: 13 | @echo "Installing..." 14 | $(EASK) install 15 | 16 | compile: 17 | @echo "Compiling..." 18 | $(EASK) compile 19 | 20 | test: 21 | @echo "Testing..." 22 | $(EASK) test ert ./test/*.el 23 | 24 | checkdoc: 25 | @echo "Run checkdoc..." 26 | $(EASK) lint checkdoc 27 | 28 | lint: 29 | @echo "Run package-lint..." 30 | $(EASK) lint package 31 | 32 | clean: 33 | $(EASK) clean all 34 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | workflow_dispatch: 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | test: 16 | runs-on: ${{ matrix.os }} 17 | continue-on-error: ${{ matrix.experimental }} 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | os: [ubuntu-latest, macos-latest, windows-latest] 22 | emacs-version: 23 | - 27.2 24 | - 28.2 25 | - 29.4 26 | - 30.2 27 | experimental: [false] 28 | include: 29 | - os: ubuntu-latest 30 | emacs-version: snapshot 31 | experimental: true 32 | - os: macos-latest 33 | emacs-version: snapshot 34 | experimental: true 35 | - os: windows-latest 36 | emacs-version: snapshot 37 | experimental: true 38 | exclude: 39 | - os: macos-latest 40 | emacs-version: 27.2 41 | 42 | steps: 43 | - uses: actions/checkout@v6 44 | 45 | - uses: jcs090218/setup-emacs@master 46 | with: 47 | version: ${{ matrix.emacs-version }} 48 | 49 | - uses: emacs-eask/setup-eask@master 50 | with: 51 | version: 'snapshot' 52 | 53 | - name: Run tests 54 | run: 55 | make ci 56 | -------------------------------------------------------------------------------- /centaur-tabs.el: -------------------------------------------------------------------------------- 1 | ;;; centaur-tabs.el --- Aesthetic, modern looking customizable tabs plugin -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2019-2024 Emmanuel Bustos 4 | ;; Copyright (C) 2024 Jen-Chieh Shen 5 | 6 | ;; Filename: centaur-tabs.el 7 | ;; Description: Provide an out of box configuration to use highly customizable tabs. 8 | ;; URL: https://github.com/ema2159/centaur-tabs 9 | ;; Author: Emmanuel Bustos 10 | ;; Maintainer: Jen-Chieh Shen 11 | ;; Created: 2019-21-19 22:14:34 12 | ;; Version: 3.3 13 | ;; Known Compatibility: GNU Emacs 26.2 14 | ;; Package-Requires: ((emacs "27.1") (powerline "2.4")) 15 | ;; Keywords: frames 16 | 17 | ;;; This file is NOT part of GNU Emacs 18 | 19 | ;;; License 20 | ;; 21 | ;; This program is free software; you can redistribute it and/or modify 22 | ;; it under the terms of the GNU General Public License as published by 23 | ;; the Free Software Foundation; either version 3, or (at your option) 24 | ;; any later version. 25 | 26 | ;; This program is distributed in the hope that it will be useful, 27 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | ;; GNU General Public License for more details. 30 | 31 | ;; You should have received a copy of the GNU General Public License 32 | ;; along with this program; see the file COPYING. If not, write to 33 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 34 | ;; Floor, Boston, MA 02110-1301, USA. 35 | 36 | ;;; Commentary: 37 | ;; 38 | ;; Emacs plugin aiming to become an aesthetic, modern looking tabs plugin. 39 | ;; 40 | ;; This package offers tabs with a wide range of customization options, both 41 | ;; aesthetical and functional, implementing them trying to follow the Emacs 42 | ;; philosophy packing them with useful keybindings and a nice integration 43 | ;; with the Emacs environment, without sacrificing customizability. 44 | ;; Some of the features Centaur tabs offers are: 45 | ;; - Tab styles 46 | ;; - Tab icons 47 | ;; - Graying out icons 48 | ;; - Selected tab bar (over, under and left bar) 49 | ;; - Close button 50 | ;; - Modified marker 51 | ;; - Buffer grouping 52 | ;; - Projectile integration 53 | ;; - Ivy and Helm integration for group switching 54 | ;; 55 | 56 | ;;; Code: 57 | 58 | (require 'centaur-tabs-elements) 59 | (require 'centaur-tabs-functions) 60 | (require 'centaur-tabs-interactive) 61 | 62 | ;; Compiler pacifier 63 | (declare-function undo-tree-undo-1 "ext:undo-tree.el") 64 | (declare-function undo-tree-redo-1 "ext:undo-tree.el") 65 | 66 | ;;;;;;;;;;;;;;;;;;;;;;; Centaur-Tabs source code ;;;;;;;;;;;;;;;;;;;;;;; 67 | 68 | (defgroup centaur-tabs nil 69 | "Display a tab bar in the header line." 70 | :group 'convenience) 71 | 72 | (defvar centaur-tabs--buffer-show-groups nil) 73 | 74 | ;; 75 | ;;; Minor modes 76 | 77 | (defsubst centaur-tabs-mode-on-p () 78 | "Return non-nil if Centaur-Tabs mode is on." 79 | (eq (default-value centaur-tabs-display-line-format) 80 | centaur-tabs-header-line-format)) 81 | 82 | ;; 83 | ;;; Centaur-Tabs-Local mode 84 | 85 | (defvar centaur-tabs--local-hlf nil) 86 | 87 | ;;;###autoload 88 | (define-minor-mode centaur-tabs-local-mode 89 | "Toggle local display of the tab bar. 90 | With prefix argument ARG, turn on if positive, otherwise off. 91 | Returns non-nil if the new state is enabled. 92 | When turned on, if a local header line is shown, it is hidden to show 93 | the tab bar. The tab bar is locally hidden otherwise. When turned 94 | off, if a local header line is hidden or the tab bar is locally 95 | hidden, it is shown again. Signal an error if Centaur-Tabs mode is off." 96 | :group 'centaur-tabs 97 | :global nil 98 | (unless (centaur-tabs-mode-on-p) 99 | (error "Centaur-Tabs mode must be enabled")) 100 | ;;; ON 101 | (if centaur-tabs-local-mode 102 | (if (and (local-variable-p centaur-tabs-display-line-format) 103 | (eval centaur-tabs-display-line-format)) 104 | ;; A local header line exists, hide it to show the tab bar. 105 | (progn 106 | ;; Fail in case of an inconsistency because another local 107 | ;; header line is already hidden. 108 | (when (local-variable-p 'centaur-tabs--local-hlf) 109 | (error "Another local header line is already hidden")) 110 | (set (make-local-variable 'centaur-tabs--local-hlf) 111 | (eval centaur-tabs-display-line-format)) 112 | (kill-local-variable centaur-tabs-display-line-format)) 113 | ;; Otherwise hide the tab bar in this buffer. 114 | (set centaur-tabs-display-line-format nil)) 115 | ;;; OFF 116 | (if (local-variable-p 'centaur-tabs--local-hlf) 117 | ;; A local header line is hidden, show it again. 118 | (progn 119 | (set centaur-tabs-display-line-format centaur-tabs--local-hlf) 120 | (kill-local-variable 'centaur-tabs--local-hlf)) 121 | ;; The tab bar is locally hidden, show it again. 122 | (kill-local-variable centaur-tabs-display-line-format)))) 123 | 124 | ;;; Centaur-Tabs mode 125 | ;; 126 | (defvar centaur-tabs--global-hlf nil) 127 | 128 | ;;;###autoload 129 | (define-minor-mode centaur-tabs-mode 130 | "Toggle display of a tab bar in the header line. 131 | With prefix argument ARG, turn on if positive, otherwise off. 132 | Returns non-nil if the new state is enabled. 133 | 134 | \\{centaur-tabs-mode-map}" 135 | :group 'centaur-tabs 136 | :require 'centaur-tabs 137 | :global t 138 | :keymap centaur-tabs-mode-map 139 | (if centaur-tabs-mode 140 | ;;; ON 141 | (unless (centaur-tabs-mode-on-p) 142 | ;; Save current default value of `centaur-tabs-display-line-format'. 143 | (setq centaur-tabs--global-hlf (default-value centaur-tabs-display-line-format)) 144 | (centaur-tabs-init-tabsets-store) 145 | (set-default centaur-tabs-display-line-format centaur-tabs-header-line-format)) 146 | ;;; OFF 147 | (when (centaur-tabs-mode-on-p) 148 | ;; Turn off Centaur-Tabs-Local mode globally. 149 | (mapc #'(lambda (b) 150 | (condition-case nil 151 | (with-current-buffer b 152 | (and centaur-tabs-local-mode 153 | (centaur-tabs-local-mode -1))) 154 | (error nil))) 155 | (buffer-list)) 156 | ;; Restore previous `centaur-tabs-display-line-format'. 157 | (set-default centaur-tabs-display-line-format centaur-tabs--global-hlf) 158 | (centaur-tabs-free-tabsets-store))) 159 | ;; Make sure it refresh every windows! 160 | (force-window-update)) 161 | 162 | ;; 163 | ;;; Tab bar buffer setup 164 | 165 | (defun centaur-tabs-buffer-init () 166 | "Initialize tab bar buffer data. 167 | Run as `centaur-tabs-init-hook'." 168 | (setq centaur-tabs--buffers nil 169 | centaur-tabs-current-tabset-function 'centaur-tabs-buffer-tabs 170 | centaur-tabs-tab-label-function 'centaur-tabs-buffer-tab-label 171 | centaur-tabs-select-tab-function 'centaur-tabs-buffer-select-tab) 172 | ;; If set, initialize selected overline 173 | (when (eq centaur-tabs-set-bar 'under) 174 | (set-face-attribute 'centaur-tabs-selected nil 175 | :underline (face-background 'centaur-tabs-active-bar-face nil 'default) 176 | :overline nil) 177 | (set-face-attribute 'centaur-tabs-selected-modified nil 178 | :underline (face-background 'centaur-tabs-active-bar-face nil 'default) 179 | :overline nil) 180 | (set-face-attribute 'centaur-tabs-unselected nil 181 | :underline nil 182 | :overline nil) 183 | (set-face-attribute 'centaur-tabs-unselected-modified nil 184 | :underline nil 185 | :overline nil)) 186 | (when (eq centaur-tabs-set-bar 'over) 187 | (set-face-attribute 'centaur-tabs-selected nil 188 | :overline (face-background 'centaur-tabs-active-bar-face nil 'default) 189 | :underline nil) 190 | (set-face-attribute 'centaur-tabs-selected-modified nil 191 | :overline (face-background 'centaur-tabs-active-bar-face nil 'default) 192 | :underline nil) 193 | (set-face-attribute 'centaur-tabs-unselected nil 194 | :overline nil 195 | :underline nil) 196 | (set-face-attribute 'centaur-tabs-unselected-modified nil 197 | :overline nil 198 | :underline nil)) 199 | (add-function :after after-focus-change-function #'centaur-tabs-after-focus) 200 | (add-hook 'window-buffer-change-functions #'centaur-tabs-on-window-buffer-change) 201 | (add-hook 'after-save-hook #'centaur-tabs-on-saving-buffer) 202 | (add-hook 'first-change-hook #'centaur-tabs-on-modifying-buffer) 203 | (add-hook 'kill-buffer-hook #'centaur-tabs-buffer-track-killed) 204 | (advice-add #'undo :after #'centaur-tabs-on-modifying-buffer) 205 | (advice-add #'undo-tree-undo-1 :after #'centaur-tabs-on-modifying-buffer) 206 | (advice-add #'undo-tree-redo-1 :after #'centaur-tabs-on-modifying-buffer) 207 | (advice-add 'load-theme :after #'centaur-tabs--after-load-theme)) 208 | 209 | (defun centaur-tabs-buffer-quit () 210 | "Quit tab bar buffer. 211 | Run as `centaur-tabs-quit-hook'." 212 | (setq centaur-tabs--buffers nil 213 | centaur-tabs-current-tabset-function nil 214 | centaur-tabs-tab-label-function nil 215 | centaur-tabs-select-tab-function nil) 216 | (remove-function after-focus-change-function #'centaur-tabs-after-focus) 217 | (remove-hook 'window-buffer-change-functions #'centaur-tabs-on-window-buffer-change) 218 | (remove-hook 'after-save-hook 'centaur-tabs-on-modifying-buffer) 219 | (remove-hook 'first-change-hook 'centaur-tabs-on-modifying-buffer) 220 | (remove-hook 'kill-buffer-hook 'centaur-tabs-buffer-track-killed) 221 | (advice-remove #'undo #'centaur-tabs-on-modifying-buffer) 222 | (advice-remove #'undo-tree-undo-1 #'centaur-tabs-on-modifying-buffer) 223 | (advice-remove #'undo-tree-redo-1 #'centaur-tabs-on-modifying-buffer) 224 | (advice-remove 'load-theme #'centaur-tabs--after-load-theme)) 225 | 226 | (add-hook 'centaur-tabs-init-hook #'centaur-tabs-buffer-init) 227 | (add-hook 'centaur-tabs-quit-hook #'centaur-tabs-buffer-quit) 228 | 229 | (provide 'centaur-tabs) 230 | ;;; centaur-tabs.el ends here 231 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Centaur tabs 2 | #+CREATOR: Emmanuel Bustos T. 3 | #+OPTIONS: toc:nil 4 | 5 | [[https://melpa.org/#/centaur-tabs][file:https://melpa.org/packages/centaur-tabs-badge.svg]] 6 | [[https://stable.melpa.org/#/centaur-tabs][file:https://stable.melpa.org/packages/centaur-tabs-badge.svg]] 7 | [[https://jcs-emacs.github.io/jcs-elpa/#/centaur-tabs][https://raw.githubusercontent.com/jcs-emacs/badges/master/elpa/v/centaur-tabs.svg]] 8 | [[http://www.gnu.org/licenses/gpl-3.0][file:https://img.shields.io/badge/License-GPL%20v3-blue.svg]] 9 | [[https://github.com/ema2159/centaur-tabs/actions/workflows/test.yml][https://github.com/ema2159/centaur-tabs/actions/workflows/test.yml/badge.svg]] 10 | 11 | [[./images/centaur.png]] 12 | * Contents :TOC: 13 | - [[#what-is-this][What is this?]] 14 | - [[#installation][Installation]] 15 | - [[#customization][Customization]] 16 | - [[#headline-face][Headline face]] 17 | - [[#tab-styles][Tab Styles]] 18 | - [[#tab-height][Tab height]] 19 | - [[#tab-icons][Tab icons]] 20 | - [[#plain-icons][Plain icons]] 21 | - [[#graying-out-icons][Graying out icons]] 22 | - [[#selected-tab-bar][Selected tab bar]] 23 | - [[#customize-the-close-button][Customize the close button]] 24 | - [[#customize-the-modified-marker][Customize the modified marker]] 25 | - [[#change-the-font-family-and-height][Change the font family and height]] 26 | - [[#disable-centaur-tabs-in-selected-buffers][Disable centaur-tabs in selected buffers]] 27 | - [[#buffer-groups][Buffer groups]] 28 | - [[#show-buffer-groups-names-instead-of-buffer-names-in-tabs][Show buffer groups names instead of buffer names in tabs]] 29 | - [[#enable-vim-like-tab-motions][Enable Vim like tab motions]] 30 | - [[#prevent-the-access-to-specified-buffers][Prevent the access to specified buffers]] 31 | - [[#tab-cycling][Tab cycling]] 32 | - [[#buffer-reordering-thanks-to-jixiuf][Buffer reordering (thanks to jixiuf)]] 33 | - [[#alphabetical-buffer-reordering-thanks-to-cburroughs][Alphabetical buffer reordering (thanks to cburroughs)]] 34 | - [[#fixed-tab-length][Fixed tab length]] 35 | - [[#selectrum-integration-revert-to-completing-read][Selectrum integration (revert to ~completing-read~)]] 36 | - [[#helm-integration][Helm integration]] 37 | - [[#ivy-integration][Ivy integration]] 38 | - [[#projectile-integration][Projectile integration]] 39 | - [[#mouse-support-thanks-to-alvarogonzalezsotillo][Mouse support (thanks to alvarogonzalezsotillo)]] 40 | - [[#new-tab-button-thanks-to-lucasgruss][New-tab button (thanks to lucasgruss)]] 41 | - [[#tab-count-thanks-to-kamilwaheed][Tab count (thanks to kamilwaheed)]] 42 | - [[#ace-jump-thanks-to-simon-lin][Ace jump (thanks to Simon-Lin)]] 43 | - [[#key-bindings][Key bindings]] 44 | - [[#to-do-1719][TO DO]] 45 | - [[#my-personal-configuration][My personal configuration]] 46 | - [[#useful-commands][Useful commands]] 47 | - [[#common-issues][Common issues]] 48 | - [[#icons-not-showing][Icons not showing]] 49 | - [[#known-supported-theme-plugins][Known supported theme plugins]] 50 | - [[#how-to-contribute][How to contribute]] 51 | 52 | * What is this? 53 | This projects aims to become an aesthetic, functional and efficient tabs plugin for Emacs with a lot of customization options. 54 | Although this is a fork from [[https://github.com/manateelazycat/awesome-tab][awesome-tab]] (that I forked with the permission from the author and it's also based on [[https://github.com/dholm/tabbar][tabbar]]) it's been heavily modified so now it may be considered a different package. 55 | Also this package integrates functionalities from [[https://github.com/mattfidler/tabbar-ruler.el][tabbar-ruler]]. 56 | 57 | It currently looks like this (although there's a ton of possible configurations): 58 | 59 | [[./screenshot.png]] 60 | * Installation 61 | You can download this package from MELPA. This is a basic ~use-package~ configuration: 62 | #+BEGIN_SRC emacs-lisp :tangle yes 63 | (use-package centaur-tabs 64 | :demand 65 | :config 66 | (centaur-tabs-mode t) 67 | :bind 68 | ("C-" . centaur-tabs-backward) 69 | ("C-" . centaur-tabs-forward)) 70 | #+END_SRC 71 | 72 | Or if you use require: 73 | #+BEGIN_SRC emacs-lisp :tangle yes 74 | (require 'centaur-tabs) 75 | (centaur-tabs-mode t) 76 | (global-set-key (kbd "C-") 'centaur-tabs-backward) 77 | (global-set-key (kbd "C-") 'centaur-tabs-forward) 78 | #+END_SRC 79 | 80 | * Customization 81 | This package is heavily customizable, with many options available to the user. Here are some of them: 82 | ** Headline face 83 | You can make the headline face match the centaur-tabs-default face. This makes the tabbar have an uniform appearance. In your configuration use the following function: 84 | #+BEGIN_SRC emacs-lisp :tangle yes 85 | (centaur-tabs-headline-match) 86 | #+END_SRC 87 | ** Tab Styles 88 | To change the tab style, modify the centaur-tabs-style variable like this: 89 | #+BEGIN_SRC emacs-lisp :tangle yes 90 | (setq centaur-tabs-style "bar") 91 | #+END_SRC 92 | 93 | The options available are: 94 | - "alternate" 95 | 96 | [[./images/alternate.png]] 97 | 98 | - "bar" 99 | 100 | [[./images/bar.png]] 101 | 102 | - "box" 103 | 104 | [[./images/box.png]] 105 | 106 | - "chamfer" 107 | 108 | [[./images/chamfer.png]] 109 | 110 | - "rounded" 111 | 112 | [[./images/rounded.png]] 113 | 114 | - "slant" 115 | 116 | [[./images/slant.png]] 117 | 118 | - "wave" 119 | 120 | [[./images/wave.png]] 121 | 122 | - "zigzag" 123 | 124 | [[./images/zigzag.png]] 125 | 126 | ** Tab height 127 | To change the tab height do 128 | #+BEGIN_SRC emacs-lisp :tangle yes 129 | (setq centaur-tabs-height 32) 130 | #+END_SRC 131 | ** Tab icons 132 | To display themed icons from all the icons 133 | #+BEGIN_SRC emacs-lisp :tangle yes 134 | (setq centaur-tabs-set-icons t) 135 | #+END_SRC 136 | Make sure you have set the icon type 137 | #+BEGIN_SRC emacs-lisp :tangle yes 138 | (setq centaur-tabs-icon-type 'all-the-icons) ; or 'nerd-icons 139 | #+END_SRC 140 | ** Plain icons 141 | To make icons plain (same color as tabs' text): 142 | #+BEGIN_SRC emacs-lisp :tangle yes 143 | (setq centaur-tabs-plain-icons t) 144 | #+END_SRC 145 | ** Graying out icons 146 | To gray out icons for the unselected tabs: 147 | #+BEGIN_SRC emacs-lisp :tangle yes 148 | (setq centaur-tabs-gray-out-icons 'buffer) 149 | #+END_SRC 150 | ** Selected tab bar 151 | To display a colored bar at the left of the selected tab 152 | #+BEGIN_SRC emacs-lisp :tangle yes 153 | (setq centaur-tabs-set-bar 'left) 154 | #+END_SRC 155 | [[./images/bar.png]] 156 | 157 | To display an overline over the selected tab: 158 | #+BEGIN_SRC emacs-lisp :tangle yes 159 | (setq centaur-tabs-set-bar 'over) 160 | #+END_SRC 161 | [[./images/overline.png]] 162 | 163 | To display an underline over the selected tab: 164 | #+BEGIN_SRC emacs-lisp :tangle yes 165 | (setq centaur-tabs-set-bar 'under) 166 | ;; Note: If you're not using Spacmeacs, in order for the underline to display 167 | ;; correctly you must add the following line: 168 | (setq x-underline-at-descent-line t) 169 | #+END_SRC 170 | [[./images/underline.png]] 171 | 172 | The color can be customized via the centaur-tabs-active-bar-face face. 173 | ** Customize the close button 174 | To disable the close button 175 | #+BEGIN_SRC emacs-lisp :tangle yes 176 | (setq centaur-tabs-set-close-button nil) 177 | #+END_SRC 178 | To change the displayed string for the close button 179 | #+BEGIN_SRC emacs-lisp :tangle yes 180 | (setq centaur-tabs-close-button "X") 181 | #+END_SRC 182 | Also there are two faces to customize the close button string: centaur-tabs-close-unselected and centaur-tabs-close-selected 183 | ** Customize the modified marker 184 | To display a marker indicating that a buffer has been modified (atom-style) 185 | #+BEGIN_SRC emacs-lisp :tangle yes 186 | (setq centaur-tabs-set-modified-marker t) 187 | #+END_SRC 188 | To change the displayed string for the modified-marker 189 | #+BEGIN_SRC emacs-lisp :tangle yes 190 | (setq centaur-tabs-modified-marker "*") 191 | #+END_SRC 192 | Also there are two faces to customize the close button string: centaur-tabs-modified-marker-unselected and centaur-tabs-modified-marker-selected 193 | 194 | [[./images/marker.png]] 195 | ** Change the font family and height 196 | To easily customize the tabs font by changing it's height and font family use the following function: 197 | #+BEGIN_SRC emacs-lisp :tangle yes 198 | (centaur-tabs-change-fonts "arial" 160) 199 | #+END_SRC 200 | ** Disable centaur-tabs in selected buffers 201 | To disable the tabs in a buffer just add a hook to the ~centaur-tabs-local-mode~ function like this: 202 | #+BEGIN_SRC emacs-lisp :tangle yes 203 | (add-hook 'dired-mode-hook 'centaur-tabs-local-mode) 204 | #+END_SRC 205 | 206 | or with ~use-package~: 207 | #+BEGIN_SRC emacs-lisp :tangle yes 208 | (use-package centaur-tabs 209 | ... 210 | :hook 211 | (dired-mode . centaur-tabs-local-mode) 212 | ...) 213 | #+END_SRC 214 | 215 | ** Buffer groups 216 | To customize the way that the buffers are grouped modify the ~centaur-tabs-buffer-groups~ function like this: 217 | #+BEGIN_SRC emacs-lisp :tangle yes 218 | (defun centaur-tabs-buffer-groups () 219 | "`centaur-tabs-buffer-groups' control buffers' group rules. 220 | 221 | Group centaur-tabs with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'. 222 | All buffer name start with * will group to \"Emacs\". 223 | Other buffer group by `centaur-tabs-get-group-name' with project name." 224 | (list 225 | (cond 226 | ((or (string-equal "*" (substring (buffer-name) 0 1)) 227 | (memq major-mode '(magit-process-mode 228 | magit-status-mode 229 | magit-diff-mode 230 | magit-log-mode 231 | magit-file-mode 232 | magit-blob-mode 233 | magit-blame-mode 234 | ))) 235 | "Emacs") 236 | ((derived-mode-p 'prog-mode) 237 | "Editing") 238 | ((derived-mode-p 'dired-mode) 239 | "Dired") 240 | ((memq major-mode '(helpful-mode 241 | help-mode)) 242 | "Help") 243 | ((memq major-mode '(org-mode 244 | org-agenda-clockreport-mode 245 | org-src-mode 246 | org-agenda-mode 247 | org-beamer-mode 248 | org-indent-mode 249 | org-bullets-mode 250 | org-cdlatex-mode 251 | org-agenda-log-mode 252 | diary-mode)) 253 | "OrgMode") 254 | (t 255 | (centaur-tabs-get-group-name (current-buffer)))))) 256 | #+END_SRC 257 | 258 | ** Show buffer groups names instead of buffer names in tabs 259 | If you want your tabs to display buffer groups names instead of buffer names you can put the following in your configuration: 260 | #+BEGIN_SRC emacs-lisp :tangle yes 261 | (setq centaur-tabs--buffer-show-groups t) 262 | #+END_SRC 263 | You can toggle between the two options interactively with the ~(centaur-tabs-toggle-groups)~ command. 264 | ** Enable Vim like tab motions 265 | To enable Vim like tab changing binds 266 | #+BEGIN_SRC emacs-lisp :tangle yes 267 | (define-key evil-normal-state-map (kbd "g t") 'centaur-tabs-forward) 268 | (define-key evil-normal-state-map (kbd "g T") 'centaur-tabs-backward) 269 | #+END_SRC 270 | 271 | or with ~use-package~: 272 | #+BEGIN_SRC emacs-lisp :tangle yes 273 | (use-package centaur-tabs 274 | ... 275 | :bind 276 | (:map evil-normal-state-map 277 | ("g t" . centaur-tabs-forward) 278 | ("g T" . centaur-tabs-backward)) 279 | ...) 280 | #+END_SRC 281 | ** Prevent the access to specified buffers 282 | You can prevent the access to some buffers via tab motions changing the following function like this: 283 | #+BEGIN_SRC emacs-lisp :tangle yes 284 | (defun centaur-tabs-hide-tab (x) 285 | "Do no to show buffer X in tabs." 286 | (let ((name (format "%s" x))) 287 | (or 288 | ;; Current window is not dedicated window. 289 | (window-dedicated-p (selected-window)) 290 | 291 | ;; Buffer name not match below blacklist. 292 | (string-prefix-p "*epc" name) 293 | (string-prefix-p "*helm" name) 294 | (string-prefix-p "*Helm" name) 295 | (string-prefix-p "*Compile-Log*" name) 296 | (string-prefix-p "*lsp" name) 297 | (string-prefix-p "*company" name) 298 | (string-prefix-p "*Flycheck" name) 299 | (string-prefix-p "*tramp" name) 300 | (string-prefix-p " *Mini" name) 301 | (string-prefix-p "*help" name) 302 | (string-prefix-p "*straight" name) 303 | (string-prefix-p " *temp" name) 304 | (string-prefix-p "*Help" name) 305 | (string-prefix-p "*mybuf" name) 306 | 307 | ;; Is not magit buffer. 308 | (and (string-prefix-p "magit" name) 309 | (not (file-name-extension name))) 310 | ))) 311 | #+END_SRC 312 | 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. 313 | ** Tab cycling 314 | 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: 315 | #+BEGIN_SRC emacs-lisp :tangle yes 316 | (setq centaur-tabs-cycle-scope 'tabs) 317 | #+END_SRC 318 | 319 | There are three options: 320 | - 'default: (Already described) 321 | - 'tabs: Cycle through visible tabs (that is, the tabs in the current group) 322 | - 'groups: Navigate through tab groups only 323 | ** Buffer reordering (thanks to jixiuf) 324 | To enable an automatic buffer reordering function use the following function in your configuration: 325 | #+BEGIN_SRC emacs-lisp :tangle yes 326 | (centaur-tabs-enable-buffer-reordering) 327 | #+END_SRC 328 | #+BEGIN_SRC emacs-lisp :tangle yes 329 | ;; When the currently selected tab(A) is at the right of the last visited 330 | ;; tab(B), move A to the right of B. When the currently selected tab(A) is 331 | ;; at the left of the last visited tab(B), move A to the left of B 332 | (setq centaur-tabs-adjust-buffer-order t) 333 | 334 | ;; Move the currently selected tab to the left of the the last visited tab. 335 | (setq centaur-tabs-adjust-buffer-order 'left) 336 | 337 | ;; Move the currently selected tab to the right of the the last visited tab. 338 | (setq centaur-tabs-adjust-buffer-order 'right) 339 | #+END_SRC 340 | 341 | This works the following way. If there's a certain group of tabs like the following: 342 | 343 | |tab1.el | tab2.js | tab3.c | tab4.py | 344 | 345 | If you're in a tab and change to another tab in the group (via Ido, Ivy or Helm) the new tab will move to the right side of the tab you were, so if you're on ~tab1.el~ and you clicked ~tab4.py~ the tabs order will be the following: 346 | 347 | | tab1.el | tab4.py | tab2.js | tab3.c | 348 | 349 | And then if you were on ~tab4.py~ and changed to ~tab2.js~, the tabs order will be the following: 350 | 351 | | tab1.el | tab4.py | tab2.js | tab3.c | 352 | 353 | the order doesn't change, because the tabs are already next to each other. 354 | 355 | And now if you were on ~tab2.js~ and changed to ~tab1.el~, the tabs order will be the following: 356 | | tab4.py | tab1.el | tab2.js | tab3.c | 357 | 358 | This functionality doesn't take effect when using centaur-tabs motion functions like ~centaur-tabs-backward/forward~. 359 | ** Alphabetical buffer reordering (thanks to cburroughs) 360 | To enable an automatic alpabetical buffer reordering, put the following lines in your configuration. 361 | #+BEGIN_SRC emacs-lisp :tangle yes 362 | (centaur-tabs-enable-buffer-alphabetical-reordering) 363 | (setq centaur-tabs-adjust-buffer-order t) 364 | #+END_SRC 365 | This function will trigger each time a non centaur-tabs motion command is executed. 366 | NOTE: Given the Emacs behaviour when opening a new file is a little bit funky, when a new tab is opened, it will always be placed at the right of the last visited buffer. This behaviour needs to be investigated in order to see if a possible solution exists. 367 | ** Fixed tab length 368 | If you desire to make the width of your tabs fixed, you have to modify the ~centaur-tabs-label-fixed-length~ custom variable with the maximum length desired (defaults to 0 for dynamic). Example: 369 | #+BEGIN_SRC emacs-lisp :tangle yes 370 | (setq centaur-tabs-label-fixed-length 8) 371 | #+END_SRC 372 | Would render the following tabs: 373 | 374 | |foo.org|a_very_d...|bar.org| 375 | 376 | ** [[https://github.com/raxod502/selectrum][Selectrum]] integration (revert to ~completing-read~) 377 | Turn off default ~ido-mode~ completions by customising ~centaur-tabs-enable-ido-completion~ in order to revert to Emacs' native ~completing-read~. 378 | ** Helm integration 379 | 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). 380 | ** Ivy integration 381 | 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. 382 | ** Projectile integration 383 | You can group your tabs by Projectile's project. Just use the following function in your configuration: 384 | #+BEGIN_SRC emacs-lisp :tangle yes 385 | (centaur-tabs-group-by-projectile-project) 386 | #+END_SRC 387 | 388 | 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: 389 | #+BEGIN_SRC emacs-lisp :tangle yes 390 | (centaur-tabs-group-buffer-groups) 391 | #+END_SRC 392 | ** Mouse support (thanks to alvarogonzalezsotillo) 393 | - Just click in a tab to change the buffer of the current window. 394 | - Click the mouse wheel to close a buffer. 395 | - Right click on empty space to show a tab groups popup. 396 | - Right click on a tab to show a context menu. The options are inspired by the options provided by VSCode. 397 | [[file:images/tab-context-menu.png]] 398 | - Use the mouse wheel to invoke ~centaur-tabs-backward/forward~. 399 | - Set the =centaur-tabs-show-navigation-buttons= custom variable to =t= to display cool navigation buttons. With the CTRL key, the left and right navigation buttons will move the tabs through the tab line. 400 | [[file:images/navigation-buttons.png]] 401 | ** New-tab button (thanks to lucasgruss) 402 | The new-tab button is a button at the right of the tabs that will spawn a new 403 | tab based on the current context. For instance in 404 | ~vterm/eshell/ansi-term~ mode, the new tab will spawn a new buffer 405 | corresponding to the current major mode. In ~eww~, you are prompted for a 406 | search term and the result is displayed in a new buffer. The default 407 | behaviour in other modes is to open a new empty buffer. 408 | 409 | - the variable ~centaur-tabs-show-new-tab-button~ controls whether the button 410 | is shown. 411 | - the variable ~centaur-tabs-new-tab-text~ controls the appearance of the button. 412 | - the function ~centaur-tabs--create-new-tab~ controls the behaviour of the 413 | context-based new tab. 414 | 415 | ** Tab count (thanks to kamilwaheed) 416 | Adds a count of the current tab position in the total number of 417 | tabs in the current window. Controlled by the variable 418 | ~centaur-tabs-show-count~. 419 | 420 | ** Ace jump (thanks to Simon-Lin) 421 | 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. 422 | [[file:images/ace-jump.png]] 423 | 424 | ** Key bindings 425 | 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): 426 | #+BEGIN_SRC emacs-lisp 427 | (setq centaur-tabs-enable-key-bindings t) 428 | #+END_SRC 429 | This will enable a series of key bindings for centaur-tabs prefixed by "C-c t". 430 | * TO DO [17/19] 431 | - [X] Integrate all-the-icons 432 | - [X] Improve all the icons placing 433 | - [X] Fix all the icons background 434 | - [X] Add selected, unselected, selected-modified and unselected-modified faces 435 | - [X] Make function to inherit tabbar faces 436 | - [X] Group tabs by projectile's project (was already implemented but not for projectile) 437 | - [X] Create PR to different theme packages for this package 438 | - [X] Add modified marker icon option 439 | - [X] Add sideline for selected tab (atom style) 440 | - [X] Add overline for selected tab (atom style). It's easy to add to the text, but not to the icon, so for any who figures it out a PR is welcome. 441 | - [ ] Add easy tab style configuration function. (Atom, Sublime, VS Code... like ~(centaur-tabs-tab-theme "atom")~) 442 | - [X] Make icon insert after the separator 443 | - [X] Add a customizable close button 444 | - [X] Explore if ~after-modifying-buffer~ function can be improved 445 | - [X] Fix messages buffer icon an FontAwesome errors 446 | - [X] Check for Elscreen compatibility 447 | - [X] Add this package to MELPA 448 | - [X] Make a configuration to display buffer groups names instead of buffer names in tabs 449 | - [ ] Add full evil-mode support with tab commands 450 | 451 | * My personal configuration 452 | My personal configuration for reference: 453 | 454 | #+BEGIN_SRC emacs-lisp :tangle yes 455 | (use-package centaur-tabs 456 | :init 457 | (setq centaur-tabs-enable-key-bindings t) 458 | :config 459 | (setq centaur-tabs-style "bar" 460 | centaur-tabs-height 32 461 | centaur-tabs-set-icons t 462 | centaur-tabs-show-new-tab-button t 463 | centaur-tabs-set-modified-marker t 464 | centaur-tabs-show-navigation-buttons t 465 | centaur-tabs-set-bar 'under 466 | centaur-tabs-show-count nil 467 | ;; centaur-tabs-label-fixed-length 15 468 | ;; centaur-tabs-gray-out-icons 'buffer 469 | ;; centaur-tabs-plain-icons t 470 | x-underline-at-descent-line t 471 | centaur-tabs-left-edge-margin nil) 472 | (centaur-tabs-change-fonts (face-attribute 'default :font) 110) 473 | (centaur-tabs-headline-match) 474 | ;; (centaur-tabs-enable-buffer-alphabetical-reordering) 475 | ;; (setq centaur-tabs-adjust-buffer-order t) 476 | (centaur-tabs-mode t) 477 | (setq uniquify-separator "/") 478 | (setq uniquify-buffer-name-style 'forward) 479 | (defun centaur-tabs-buffer-groups () 480 | "`centaur-tabs-buffer-groups' control buffers' group rules. 481 | 482 | Group centaur-tabs with mode if buffer is derived from `eshell-mode' `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'. 483 | All buffer name start with * will group to \"Emacs\". 484 | Other buffer group by `centaur-tabs-get-group-name' with project name." 485 | (list 486 | (cond 487 | ;; ((not (eq (file-remote-p (buffer-file-name)) nil)) 488 | ;; "Remote") 489 | ((or (string-equal "*" (substring (buffer-name) 0 1)) 490 | (memq major-mode '(magit-process-mode 491 | magit-status-mode 492 | magit-diff-mode 493 | magit-log-mode 494 | magit-file-mode 495 | magit-blob-mode 496 | magit-blame-mode 497 | ))) 498 | "Emacs") 499 | ((derived-mode-p 'prog-mode) 500 | "Editing") 501 | ((derived-mode-p 'dired-mode) 502 | "Dired") 503 | ((memq major-mode '(helpful-mode 504 | help-mode)) 505 | "Help") 506 | ((memq major-mode '(org-mode 507 | org-agenda-clockreport-mode 508 | org-src-mode 509 | org-agenda-mode 510 | org-beamer-mode 511 | org-indent-mode 512 | org-bullets-mode 513 | org-cdlatex-mode 514 | org-agenda-log-mode 515 | diary-mode)) 516 | "OrgMode") 517 | (t 518 | (centaur-tabs-get-group-name (current-buffer)))))) 519 | :hook 520 | (dashboard-mode . centaur-tabs-local-mode) 521 | (term-mode . centaur-tabs-local-mode) 522 | (calendar-mode . centaur-tabs-local-mode) 523 | (org-agenda-mode . centaur-tabs-local-mode) 524 | :bind 525 | ("C-" . centaur-tabs-backward) 526 | ("C-" . centaur-tabs-forward) 527 | ("C-S-" . centaur-tabs-move-current-tab-to-left) 528 | ("C-S-" . centaur-tabs-move-current-tab-to-right) 529 | (:map evil-normal-state-map 530 | ("g t" . centaur-tabs-forward) 531 | ("g T" . centaur-tabs-backward))) 532 | #+END_SRC 533 | 534 | * Useful commands 535 | Centaur tabs has plenty of useful commands for manipulating tabs and tab groups. Some of them are: 536 | - =(centaur-tabs-kill-all-buffers-in-current-group)=: Kills all buffers in current tab group. 537 | - =(centaur-tabs-kill-match-buffers-in-current-group)=: Kills all buffers in current tab group with the same extension as the current buffer. 538 | - =(centaur-tabs-keep-match-buffers-in-current-group)=: Asks for a file extension and kills all the buffers with a different extension. 539 | - =(centaur-tabs-kill-other-buffers-in-current-group)=: Kills all buffers in current tab group except the current buffer. 540 | - =(centaur-tabs-kill-unmodified-buffers-in-current-group)=: Kills all buffers in current tab group that are unmodified. 541 | - =(centaur-tabs-select-beg-tab)=: Selects the first tab of the group. 542 | - =(centaur-tabs-select-end-tab)=: Selects the last tab of the group. 543 | - =(centaur-tabs-forward-group)=: Go to the next tab group. 544 | - =(centaur-tabs-backward-group)=: Go to the previous tab group. 545 | * Common issues 546 | ** Icons not showing 547 | If the icons in your tabs are not showing, it is likely because of one of the two following reasons: 548 | *** =all-the-icons= / =nerd-icons= not installed 549 | If [[https://github.com/domtronn/all-the-icons.el][all-the-icons]] or [[https://github.com/rainstormstudio/nerd-icons.el][nerd-icons]] is not installed properly, your mode icons won't show up. To solve this issue, you have to install all-the-icons or nerd-icons and follow the instructions indicated in its repository. 550 | *** Font with required unicode symbols missing 551 | If you get something like the following image in your tabs: 552 | 553 | [[./images/font-missing.png]] 554 | 555 | 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. 556 | * Known supported theme plugins 557 | - [[https://github.com/jonathanchu/atom-one-dark-theme][Atom One Dark Theme]] 558 | - [[https://github.com/belak/base16-emacs][Base16]] 559 | - [[https://github.com/SavchenkoValeriy/emacs-chocolate-theme][Chocolate Theme]] 560 | - [[https://github.com/hlissner/emacs-doom-themes][Doom Themes]] 561 | - [[https://github.com/ogdenwebb/emacs-kaolin-themes][Kaolin Themes]] 562 | - [[https://github.com/nashamri/spacemacs-theme][Spacemacs Theme]] 563 | - [[https://github.com/ianpan870102/tron-legacy-emacs-theme][Tron Legacy]] 564 | - [[https://github.com/ianpan870102/wilmersdorf-emacs-theme][Wilmersdorf Theme]] 565 | - [[https://github.com/bbatsov/zenburn-emacs][Zenburn]] 566 | - [[https://github.com/bbatsov/solarized-emacs][Solarized]] 567 | * How to contribute 568 | You can contribute by forking the repo and then creating a pull request with the changes you consider will improve the package. There's a TO DO list with wanted features so you can start from there. I'll be glad to receive help. 569 | Please try to keep the code as clear and documented as possible. 570 | -------------------------------------------------------------------------------- /centaur-tabs-interactive.el: -------------------------------------------------------------------------------- 1 | ;;; centaur-tabs-interactive.el --- centaur-tabs interactive functions and plugins support lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2019-2024 Emmanuel Bustos 4 | ;; Copyright (C) 2024 Jen-Chieh Shen 5 | 6 | ;; This file is not part of GNU Emacs. 7 | 8 | ;; This program is free software; you can redistribute it and/or 9 | ;; modify it under the terms of the GNU General Public License as 10 | ;; published by the Free Software Foundation; either version 2, or 11 | ;; (at your option) any later version. 12 | ;; 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | ;; General Public License for more details. 17 | ;; 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program; see the file COPYING. If not, write to 20 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 21 | ;; Floor, Boston, MA 02110-1301, USA. 22 | 23 | ;;; Commentary: 24 | ;; 25 | ;; This file contains centaur-tabs interactive functions and plugins support 26 | ;; 27 | 28 | ;;; Code: 29 | 30 | (require 'cl-lib) 31 | (require 'centaur-tabs-elements) 32 | 33 | ;; Compiler pacifier 34 | (declare-function ivy-read "ext:ivy.el" t t) 35 | (declare-function helm-build-sync-source "ext:helm-source.el" t t) 36 | (defvar helm-source-centaur-tabs-group) 37 | (declare-function projectile-project-root "ext:projectile.el" t t) 38 | (declare-function projectile-project-name "ext:projectile.el" t t) 39 | 40 | (declare-function centaur-tabs-do-select "centaur-tabs-functions.el") 41 | (declare-function centaur-tabs-get-tab-from-event "centaur-tabs-functions.el") 42 | (declare-function centaur-tabs-tab-value "centaur-tabs-functions.el") 43 | (declare-function centaur-tabs-get-tabset "centaur-tabs-functions.el") 44 | (declare-function centaur-tabs-buffer-show-groups "centaur-tabs-functions.el") 45 | (declare-function centaur-tabs-buffer-close-tab "centaur-tabs-functions.el") 46 | (declare-function centaur-tabs-view "centaur-tabs-functions.el") 47 | (declare-function centaur-tabs-get-extensions "centaur-tabs-functions.el") 48 | (declare-function centaur-tabs-selected-tab "centaur-tabs-functions.el") 49 | (declare-function centaur-tabs-display-update "centaur-tabs-functions.el") 50 | (declare-function centaur-tabs-set-template "centaur-tabs-functions.el") 51 | (declare-function centaur-tabs-buffer-select-tab "centaur-tabs-functions.el") 52 | (declare-function centaur-tabs-tabs "centaur-tabs-functions.el") 53 | (declare-function centaur-tabs-tab-tabset "centaur-tabs-functions.el") 54 | (declare-function centaur-tabs-get-tabsets-tabset "centaur-tabs-functions.el") 55 | (declare-function centaur-tabs-current-tabset "centaur-tabs-functions.el") 56 | (declare-function centaur-tabs-completing-read "centaur-tabs-functions.el") 57 | (declare-function centaur-tabs-get-groups "centaur-tabs-functions.el") 58 | (declare-function centaur-tabs-forward-group "centaur-tabs-functions.el") 59 | (declare-function centaur-tabs-backward-group "centaur-tabs-functions.el") 60 | (declare-function centaur-tabs-forward-tab "centaur-tabs-functions.el") 61 | (declare-function centaur-tabs-backward-tab "centaur-tabs-functions.el") 62 | 63 | (defvar centaur-tabs-cycle-scope) 64 | (defvar centaur-tabs-current-tabset) 65 | (defvar centaur-tabs-last-focused-buffer-group) 66 | (defvar centaur-tabs-buffer-list-function) 67 | (defvar centaur-tabs-buffer-groups-function) 68 | (defvar centaur-tabs--buffer-show-groups) 69 | 70 | ;;;;;;;;;;;;;;;;;;;;;;; Interactive functions ;;;;;;;;;;;;;;;;;;;;;;; 71 | 72 | (defun centaur-tabs-switch-group (&optional groupname) 73 | "Switch tab groups using ido. GROUPNAME can optionaly be provided." 74 | (interactive) 75 | (let* ((tab-buffer-list (mapcar 76 | #'(lambda (b) 77 | (with-current-buffer b 78 | (list (current-buffer) 79 | (buffer-name) 80 | (funcall centaur-tabs-buffer-groups-function) ))) 81 | (funcall centaur-tabs-buffer-list-function))) 82 | (groups (centaur-tabs-get-groups)) 83 | (group-name (or groupname (centaur-tabs-completing-read "Groups: " groups))) ) 84 | (catch 'done 85 | (mapc #'(lambda (group) 86 | (when (equal group-name (car (car (cdr (cdr group))))) 87 | (throw 'done (switch-to-buffer (car (cdr group)))))) 88 | tab-buffer-list) ))) 89 | 90 | (defun centaur-tabs-select-end-tab () 91 | "Select end tab of current tabset." 92 | (interactive) 93 | (centaur-tabs-select-beg-tab t)) 94 | 95 | (defun centaur-tabs-select-beg-tab (&optional backward) 96 | "Select beginning tab of current tabs. 97 | If BACKWARD is non-nil, move backward, otherwise move forward. 98 | TYPE is default option." 99 | (interactive) 100 | (let* ((tabset (centaur-tabs-current-tabset t)) 101 | (ttabset (centaur-tabs-get-tabsets-tabset)) 102 | (_cycle (if (and (eq centaur-tabs-cycle-scope 'groups) 103 | (not (cdr (centaur-tabs-tabs ttabset)))) 104 | 'tabs 105 | centaur-tabs-cycle-scope)) 106 | _selected tab) 107 | (when tabset 108 | (setq tabset (centaur-tabs-tabs tabset) 109 | tab (car (if backward (last tabset) tabset))) 110 | (centaur-tabs-buffer-select-tab tab)))) 111 | 112 | (defun centaur-tabs-backward-tab-other-window (&optional reversed) 113 | "Move to left tab in other window. 114 | Optional argument REVERSED default is move backward, if reversed is non-nil 115 | move forward." 116 | (interactive) 117 | (other-window 1) 118 | (if reversed 119 | (centaur-tabs-forward-tab) 120 | (centaur-tabs-backward-tab)) 121 | (other-window -1)) 122 | 123 | (defun centaur-tabs-forward-tab-other-window () 124 | "Move to right tab in other window." 125 | (interactive) 126 | (centaur-tabs-backward-tab-other-window t)) 127 | 128 | (defun centaur-tabs-move-current-tab-to-right () 129 | "Move current tab one place right, unless it's already the rightmost." 130 | (interactive) 131 | (let* ((bufset (centaur-tabs-current-tabset t)) 132 | (old-bufs (centaur-tabs-tabs bufset)) 133 | (new-bufs (list)) 134 | the-buffer) 135 | (while (and 136 | old-bufs 137 | (not (string= (buffer-name) (format "%s" (car (car old-bufs)))))) 138 | (push (car old-bufs) new-bufs) 139 | (setq old-bufs (cdr old-bufs))) 140 | (if old-bufs ; if this is false, then the current tab's buffer name is mysteriously missing 141 | (progn 142 | (setq the-buffer (car old-bufs)) 143 | (setq old-bufs (cdr old-bufs)) 144 | (if old-bufs ; if this is false, then the current tab is the rightmost 145 | (push (car old-bufs) new-bufs)) 146 | (push the-buffer new-bufs)) ; this is the tab that was to be moved 147 | (error "Error: current buffer's name was not found in Centaur-Tabs's buffer list")) 148 | (setq new-bufs (reverse new-bufs)) 149 | (setq new-bufs (append new-bufs (cdr old-bufs))) 150 | (set bufset new-bufs) 151 | (centaur-tabs-set-template bufset nil) 152 | (centaur-tabs-display-update))) 153 | 154 | (defun centaur-tabs-move-current-tab-to-left () 155 | "Move current tab one place left, unless it's already the leftmost." 156 | (interactive) 157 | (let* ((bufset (centaur-tabs-current-tabset t)) 158 | (old-bufs (centaur-tabs-tabs bufset)) 159 | (first-buf (car old-bufs)) 160 | (new-bufs (list)) 161 | not-yet-this-buf) 162 | (if (string= (buffer-name) (format "%s" (car first-buf))) 163 | old-bufs ; the current tab is the leftmost 164 | (setq not-yet-this-buf first-buf) 165 | (setq old-bufs (cdr old-bufs)) 166 | (while (and 167 | old-bufs 168 | (not (string= (buffer-name) (format "%s" (car (car old-bufs)))))) 169 | (push not-yet-this-buf new-bufs) 170 | (setq not-yet-this-buf (car old-bufs)) 171 | (setq old-bufs (cdr old-bufs))) 172 | (if old-bufs ; if this is false, then the current tab's buffer name is mysteriously missing 173 | (progn 174 | (push (car old-bufs) new-bufs) ; this is the tab that was to be moved 175 | (push not-yet-this-buf new-bufs) 176 | (setq new-bufs (reverse new-bufs)) 177 | (setq new-bufs (append new-bufs (cdr old-bufs)))) 178 | (error "Error: current buffer's name was not found in Centaur-Tabs's buffer list")) 179 | (set bufset new-bufs) 180 | (centaur-tabs-set-template bufset nil) 181 | (centaur-tabs-display-update)))) 182 | 183 | (defmacro centaur-tabs-kill-buffer-match-rule (match-rule) 184 | "If buffer match MATCH-RULE, kill it." 185 | `(save-excursion 186 | (mapc #'(lambda (buffer) 187 | (with-current-buffer buffer 188 | (when (string-equal current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 189 | (when (funcall ,match-rule buffer) 190 | (kill-buffer buffer))))) 191 | (buffer-list)))) 192 | 193 | (defun centaur-tabs-kill-all-buffers-in-current-group () 194 | "Kill all buffers in current group." 195 | (interactive) 196 | (let* ((current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t))))) 197 | ;; Kill all buffers in current group. 198 | (centaur-tabs-kill-buffer-match-rule 199 | (lambda (_buffer) t)) 200 | ;; Switch to next group. 201 | (centaur-tabs-forward-group))) 202 | 203 | (defun centaur-tabs-kill-other-buffers-in-current-group () 204 | "Kill all buffers except current buffer in current group." 205 | (interactive) 206 | (let* ((current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 207 | (currentbuffer (current-buffer))) 208 | ;; Kill all buffers in current group. 209 | (centaur-tabs-kill-buffer-match-rule 210 | (lambda (buffer) (not (equal buffer currentbuffer)))))) 211 | 212 | (defun centaur-tabs-kill-unmodified-buffers-in-current-group () 213 | "Kill all unmodified buffer in current group." 214 | (interactive) 215 | (let* ((current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 216 | (currentbuffer (current-buffer))) 217 | ;; Kill all buffers in current group. 218 | (centaur-tabs-kill-buffer-match-rule 219 | (lambda (buffer) (not (buffer-modified-p buffer)))))) 220 | 221 | (defun centaur-tabs-kill-match-buffers-in-current-group () 222 | "Kill all buffers match extension in current group." 223 | (interactive) 224 | (let* ((current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 225 | (extension-names (centaur-tabs-get-extensions)) 226 | match-extension) 227 | ;; Read extension need to kill. 228 | (setq match-extension (centaur-tabs-completing-read "Kill buffers suffix with: " extension-names)) 229 | ;; Kill all buffers match extension in current group. 230 | (centaur-tabs-kill-buffer-match-rule 231 | (lambda (buffer) 232 | (let ((filename (buffer-file-name buffer))) 233 | (and filename (string-equal (file-name-extension filename) match-extension))))) 234 | ;; Switch to next group if last file killed. 235 | (when (equal (length extension-names) 1) 236 | (centaur-tabs-forward-group)))) 237 | 238 | (defun centaur-tabs-keep-match-buffers-in-current-group () 239 | "Keep all buffers match extension in current group." 240 | (interactive) 241 | (let* ((current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 242 | (extension-names (centaur-tabs-get-extensions)) 243 | match-extension) 244 | ;; Read extension need to kill. 245 | (setq match-extension (centaur-tabs-completing-read "Just keep buffers suffix with: " extension-names)) 246 | ;; Kill all buffers match extension in current group. 247 | (centaur-tabs-kill-buffer-match-rule 248 | (lambda (buffer) 249 | (let ((filename (buffer-file-name buffer))) 250 | (and filename (not (string-equal (file-name-extension filename) match-extension)))))) 251 | ;; Switch to next group if last file killed. 252 | (when (equal (length extension-names) 1) 253 | (centaur-tabs-forward-group)))) 254 | 255 | (defun centaur-tabs-select-visible-nth-tab (tab-index) 256 | "Select visible tab with TAB-INDEX'. 257 | Example, when `tab-index' is 1, this function will select the leftmost label in 258 | the visible area, instead of the first label in the current group. 259 | If `tab-index' more than length of visible tabs, selet the last tab. 260 | 261 | If `tab-index' is 0, select last tab." 262 | (let ((visible-tabs (centaur-tabs-view centaur-tabs-current-tabset))) 263 | (switch-to-buffer 264 | (car 265 | (if (or (equal tab-index 0) 266 | (> tab-index (length visible-tabs))) 267 | (car (last visible-tabs)) 268 | (nth (- tab-index 1) visible-tabs)))))) 269 | 270 | (defun centaur-tabs-select-visible-tab () 271 | "Bind this function with number keystroke, such as s-1, s-2, s-3 ... etc. 272 | 273 | This function automatically recognizes the number at the end of the keystroke 274 | and switches to the tab of the corresponding index. 275 | 276 | Note that this function switches to the visible range, 277 | not the actual logical index position of the current group." 278 | (interactive) 279 | (let* ((event last-command-event) 280 | (key (make-vector 1 event)) 281 | (key-desc (key-description key))) 282 | (centaur-tabs-select-visible-nth-tab 283 | (string-to-number (car (last (split-string key-desc "-"))))))) 284 | 285 | ;; ace-jump style tab switching 286 | 287 | (defvar centaur-tabs-ace-jump-active nil 288 | "Set to t if `centaur-tabs-ace-jump' is invoked.") 289 | 290 | (defvar centaur-tabs-dim-overlay nil 291 | "Holds the overlay for dimming buffer when invoking centaur-tabs-ace-jump.") 292 | 293 | (defun centaur-tabs--dim-window () 294 | "Create a dim background overlay for the current window." 295 | (when centaur-tabs-ace-jump-dim-buffer 296 | (when centaur-tabs-dim-overlay 297 | (delete-overlay centaur-tabs-dim-overlay)) 298 | (setq centaur-tabs-dim-overlay 299 | (let ((ol (make-overlay (window-start) (window-end)))) 300 | (overlay-put ol 'face 'centaur-tabs-dim-buffer-face) 301 | ol)))) 302 | 303 | (defun centaur-tabs-swap-tab (tab) 304 | "Swap the position of current tab with TAB. 305 | TAB has to be in the same group as the current tab." 306 | (if (eq (centaur-tabs-tab-tabset tab) (centaur-tabs-current-tabset t)) 307 | (let* ((group (centaur-tabs-current-tabset t)) 308 | (tabs (cl-copy-list (centaur-tabs-tabs group))) 309 | (current (centaur-tabs-selected-tab group)) 310 | (current-index (cl-position current tabs)) 311 | (target-index (cl-position tab tabs))) 312 | (if (eq tab current) 313 | (message "Can't swap with current tab itself.") 314 | (setcar (nthcdr current-index tabs) tab) 315 | (setcar (nthcdr target-index tabs) current) 316 | (set group tabs) 317 | (centaur-tabs-set-template (centaur-tabs-current-tabset t) nil) 318 | (centaur-tabs-display-update))) 319 | (message "Error: %s is not in the same group as the current tab." tab))) 320 | 321 | (defun centaur-tabs-ace-action (action) 322 | "Preform ACTION on a visible tab. Ace-jump style. 323 | ACTION has to be one of value in `centaur-tabs-ace-dispatch-alist'" 324 | (when (centaur-tabs-current-tabset t) 325 | (when centaur-tabs-ace-jump-dim-buffer 326 | (centaur-tabs--dim-window)) 327 | (cond ((eq action 'jump-to-tab) 328 | (message "Jump to tab: ")) 329 | ((eq action 'close-tab) 330 | (message "Close tab: ")) 331 | ((eq action 'swap-tab) 332 | (message "Swap current tab with: "))) 333 | 334 | (let ((centaur-tabs-ace-jump-active t)) 335 | (catch 'done 336 | (while t 337 | (centaur-tabs-set-template (centaur-tabs-current-tabset t) nil) 338 | (centaur-tabs-display-update) 339 | (let ((char (read-key)) (action-cache)) 340 | (cond 341 | ;; tab keys 342 | ((memq char centaur-tabs-ace-jump-keys) 343 | (let ((sel (nth (cl-position char centaur-tabs-ace-jump-keys) (centaur-tabs-view (centaur-tabs-current-tabset t))))) 344 | (cond ((eq sel nil) 345 | (message "Tab %s does not exist" (key-description (vector char)))) 346 | ((eq action 'jump-to-tab) 347 | (centaur-tabs-buffer-select-tab sel)) 348 | ((eq action 'close-tab) 349 | (centaur-tabs-buffer-close-tab sel)) 350 | ((eq action 'swap-tab) 351 | (centaur-tabs-swap-tab sel)))) 352 | (throw 'done nil)) 353 | ;; actions 354 | ((setq action-cache (assoc char centaur-tabs-ace-dispatch-alist)) 355 | (setq action-cache (cadr action-cache)) 356 | (cond ((eq action-cache 'exit) ; exit 357 | (message "Quit") 358 | (throw 'done nil)) 359 | ((eq action-cache 'forward-group) ; forward group 360 | (message "Forward group") 361 | (centaur-tabs-forward-group) 362 | (centaur-tabs--dim-window)) 363 | ((eq action-cache 'backward-group) ; backward group 364 | (message "Backward group") 365 | (centaur-tabs-backward-group) 366 | (centaur-tabs--dim-window)) 367 | ((eq action-cache 'show-help) ; help menu 368 | (message "%s" (mapconcat 369 | (lambda (elem) (format "%s: %s" 370 | (key-description (vector (car elem))) 371 | (caddr elem))) 372 | centaur-tabs-ace-dispatch-alist 373 | "\n"))) 374 | (t (setq action action-cache) ; other actions 375 | (cond ((eq action-cache 'jump-to-tab) 376 | (message "Jump to tab: ")) 377 | ((eq action-cache 'close-tab) 378 | (message "Close tab: ")) 379 | ((eq action-cache 'swap-tab) 380 | (message "Swap current tab with: ")))))) 381 | ;; no match, repeat 382 | (t 383 | (message "No such candidate: %s, hit ? for help." (key-description (vector char))))))))) 384 | (centaur-tabs-set-template (centaur-tabs-current-tabset t) nil) 385 | (when centaur-tabs-ace-jump-dim-buffer 386 | (delete-overlay centaur-tabs-dim-overlay) 387 | (setq centaur-tabs-dim-overlay nil)) 388 | (centaur-tabs-display-update))) 389 | 390 | (defun centaur-tabs-ace-jump (&optional arg) 391 | "Select a tab and perform an action. Ace-jump style. 392 | If no ARG is provided, select that tab. If prefixed with one 393 | `universal-argument', swap the current tab with the selected tab. 394 | If prefixed with two `universal-argument's, close selected tab." 395 | (interactive "p") 396 | (cond ((eq arg 1) 397 | (centaur-tabs-ace-action 'jump-to-tab)) 398 | ((eq arg 4) 399 | (centaur-tabs-ace-action 'swap-tab)) 400 | ((eq arg 16) 401 | (centaur-tabs-ace-action 'close-tab)) 402 | (t 403 | (centaur-tabs-ace-action 'jump-to-tab)))) 404 | 405 | (defun centaur-tabs-group-buffer-groups () 406 | "Use centaur-tabs's own buffer grouping function." 407 | (interactive) 408 | (setq centaur-tabs-buffer-groups-function 'centaur-tabs-buffer-groups) 409 | (centaur-tabs-display-update)) 410 | 411 | ;; Projectile integration. Taken from tabbar-ruler 412 | (defvar centaur-tabs-projectile-buffer-group-calc nil 413 | "Set buffer groups for projectile. 414 | Should be buffer local and speed up calculation of buffer groups.") 415 | 416 | (defun centaur-tabs-projectile-buffer-groups () 417 | "Return the list of group names BUFFER belongs to." 418 | (if centaur-tabs-projectile-buffer-group-calc 419 | (symbol-value 'centaur-tabs-projectile-buffer-group-calc) 420 | (set (make-local-variable 'centaur-tabs-projectile-buffer-group-calc) 421 | 422 | (cond 423 | ((or (get-buffer-process (current-buffer)) (memq major-mode '(comint-mode compilation-mode))) '("Term")) 424 | ((string-equal "*" (substring (buffer-name) 0 1)) '("Misc")) 425 | ((condition-case _err 426 | (projectile-project-root) 427 | (error nil)) 428 | (list (projectile-project-name))) 429 | ((memq major-mode '(emacs-lisp-mode python-mode emacs-lisp-mode c-mode 430 | c++-mode javascript-mode js-mode 431 | js2-mode makefile-mode 432 | lua-mode vala-mode)) 433 | '("Coding")) 434 | ((memq major-mode '( nxhtml-mode html-mode 435 | mhtml-mode css-mode)) 436 | '("HTML")) 437 | ((memq major-mode '(org-mode calendar-mode diary-mode)) '("Org")) 438 | ((memq major-mode '(dired-mode)) '("Dir")) 439 | (t '("Other")))) 440 | (symbol-value 'centaur-tabs-projectile-buffer-group-calc))) 441 | 442 | (defun centaur-tabs-group-by-projectile-project() 443 | "Group by projectile project." 444 | (interactive) 445 | (setq centaur-tabs-buffer-groups-function 'centaur-tabs-projectile-buffer-groups) 446 | (centaur-tabs-display-update)) 447 | 448 | ;; Show groups instead of tabs 449 | (defun centaur-tabs-toggle-groups () 450 | "Show group names on the tabs instead of buffer names." 451 | (interactive) 452 | (centaur-tabs-buffer-show-groups (not centaur-tabs--buffer-show-groups)) 453 | (centaur-tabs-display-update)) 454 | 455 | ;; Helm source for switching group in helm. 456 | 457 | (defun centaur-tabs-build-helm-source () 458 | "Display a list of current buffer groups in Helm." 459 | (interactive) 460 | (setq helm-source-centaur-tabs-group 461 | (when (featurep 'helm) 462 | (require 'helm) 463 | (helm-build-sync-source "Centaur-Tabs Group" 464 | :candidates #'centaur-tabs-get-groups 465 | :action '(("Switch to group" . centaur-tabs-switch-group)))))) 466 | 467 | ;; Ivy source for switching group in ivy. 468 | 469 | ;;;###autoload 470 | (defun centaur-tabs-counsel-switch-group () 471 | "Display a list of current buffer groups using Counsel." 472 | (interactive) 473 | (when (featurep 'ivy) 474 | (require 'ivy) 475 | (ivy-read 476 | "Centaur Tabs Groups:" 477 | (centaur-tabs-get-groups) 478 | :action #'centaur-tabs-switch-group 479 | :caller 'centaur-tabs-counsel-switch-group))) 480 | 481 | (defun centaur-tabs-extract-window-to-new-frame() 482 | "Kill the current window in the current frame, and open the current buffer 483 | in a new frame." 484 | (interactive) 485 | (unless (centaur-tabs--one-window-p) 486 | (let ((buffer (current-buffer))) 487 | (delete-window) 488 | (display-buffer-pop-up-frame buffer nil)))) 489 | 490 | (defun centaur-tabs--copy-file-name-to-clipboard () 491 | "Copy the current buffer file name to the clipboard." 492 | ;;; From https://emacsredux.com/blog/2013/03/27/copy-filename-to-the-clipboard/ 493 | (interactive) 494 | (let* ((filename (if (equal major-mode 'dired-mode) 495 | default-directory 496 | (buffer-file-name))) 497 | (filename (expand-file-name filename))) 498 | (when filename 499 | (kill-new filename) 500 | (message "Copied buffer file name '%s' to the kill ring." filename)))) 501 | 502 | (defun centaur-tabs-open-directory-in-external-application () 503 | "Open the current directory in a external application." 504 | (interactive) 505 | (centaur-tabs--open-externally default-directory)) 506 | 507 | (defun centaur-tabs-open-in-external-application () 508 | "Open the file of the current buffer according to its mime type." 509 | (interactive) 510 | (let ((path (or (buffer-file-name) default-directory))) 511 | (centaur-tabs--open-externally path))) 512 | 513 | (defun centaur-tabs--open-externally (file-or-path) 514 | "Open FILE-OR-PATH according to its mime type in an external application. 515 | FILE-OR-PATH is expanded with `expand-file-name`. 516 | Modified copy of `treemacs-visit-node-in-external-application`." 517 | (let ((path (expand-file-name file-or-path))) 518 | (pcase system-type 519 | ('windows-nt 520 | (declare-function w32-shell-execute "w32fns.c") 521 | (w32-shell-execute "open" (replace-regexp-in-string "/" "\\" path t t))) 522 | ('darwin 523 | (shell-command (format "open \"%s\"" path))) 524 | ('gnu/linux 525 | (let ((process-connection-type nil)) 526 | (start-process "" nil "xdg-open" path))) 527 | (_ (message "Don't know how to open files on %s." (symbol-name system-type)))))) 528 | 529 | (defun centaur-tabs--copy-directory-name-to-clipboard () 530 | "Copy the current directory name to the clipboard." 531 | (interactive) 532 | (when default-directory 533 | (kill-new default-directory) 534 | (message "Copied directory name '%s' to the kill ring." (expand-file-name default-directory)))) 535 | 536 | (defun centaur-tabs--tab-submenu-groups-definition () 537 | "Menu definition with a list of tab groups." 538 | (let* ((tabset (centaur-tabs-2str (centaur-tabs-current-tabset))) 539 | (tabs (cl-remove-if (lambda (name) 540 | (equal tabset name)) 541 | (centaur-tabs-get-groups))) 542 | (sorted-tabs (sort tabs #'string<))) 543 | (mapcar (lambda (s) `[,s ,s]) 544 | (cons tabset sorted-tabs)))) 545 | 546 | (defun centaur-tabs--tab-submenu-tabs-definition () 547 | "Menu definition with a list of tabs for the current group." 548 | (let* ((tabset (centaur-tabs-get-tabset centaur-tabs-last-focused-buffer-group)) 549 | (tabs-in-group (centaur-tabs-tabs tabset)) 550 | (buffers (mapcar #'centaur-tabs-tab-value tabs-in-group)) 551 | (sorted-tabs (sort (mapcar #'buffer-name buffers) #'string<))) 552 | (mapcar (lambda (s) `[,s ,s]) sorted-tabs))) 553 | 554 | (defvar centaur-tabs--groups-submenu-key "Tab groups") 555 | (defvar centaur-tabs--tabs-submenu-key "Go to tab of group") 556 | 557 | (defun centaur-tabs--kill-this-buffer-dont-ask() 558 | "Kill the current buffer without confirmation." 559 | (interactive) 560 | (kill-buffer (current-buffer)) 561 | (centaur-tabs-display-update) 562 | (redisplay t)) 563 | 564 | (defun centaur-tabs--tab-menu-definition () 565 | "Definition of the context menu of a tab." 566 | `(["Kill this buffer" centaur-tabs--kill-this-buffer-dont-ask] 567 | ["Kill other buffers of group" centaur-tabs-kill-other-buffers-in-current-group] 568 | ["Kill unmodified buffers of group" centaur-tabs-kill-unmodified-buffers-in-current-group] 569 | "----" 570 | ["Split below" split-window-below] 571 | ["Split right" split-window-right] 572 | "----" 573 | ["Maximize tab" delete-other-windows 574 | :active (null (centaur-tabs--one-window-p))] 575 | ["Extract to new frame" centaur-tabs-extract-window-to-new-frame 576 | :active (null (centaur-tabs--one-window-p))] 577 | ["Duplicate in new frame" make-frame-command] 578 | "----" 579 | ["Copy filepath" centaur-tabs--copy-file-name-to-clipboard 580 | :active (buffer-file-name)] 581 | ["Copy directory path" centaur-tabs--copy-directory-name-to-clipboard 582 | :active default-directory] 583 | ["Open in external application" centaur-tabs-open-in-external-application 584 | :active (or (buffer-file-name) default-directory)] 585 | ["Open directory in dired" dired-jump 586 | :active (not (eq major-mode 'dired-mode))] 587 | ["Open directory externally" centaur-tabs-open-directory-in-external-application 588 | :active default-directory] 589 | "----" 590 | ,(append (list centaur-tabs--groups-submenu-key) 591 | (centaur-tabs--tab-submenu-groups-definition)) 592 | ,(append (list centaur-tabs--tabs-submenu-key) 593 | (centaur-tabs--tab-submenu-tabs-definition)))) 594 | 595 | (defun centaur-tabs--one-window-p () 596 | "Like `one-window-p`, but taking into account side windows like treemacs." 597 | (let* ((mainwindow (window-main-window)) 598 | (child-count (window-child-count mainwindow))) 599 | (= 0 child-count))) 600 | 601 | (defun centaur-tabs--get-tab-from-name (tabname) 602 | "Get the tab from the current group given de TABNAME." 603 | (let ((seq (centaur-tabs-tabs (centaur-tabs-get-tabset centaur-tabs-last-focused-buffer-group)))) 604 | (cl-find-if 605 | (lambda (tab) (string= tabname (buffer-name (centaur-tabs-tab-value tab)))) 606 | seq))) 607 | 608 | (defun centaur-tabs--tab-menu (event) 609 | "Show a context menu for the clicked tab or button. 610 | The clicked tab, identified by EVENT, is selected." 611 | (interactive "e" ) 612 | (let ((click-on-tab-p (ignore-errors (centaur-tabs-get-tab-from-event event)))) 613 | (when (not click-on-tab-p) 614 | (centaur-tabs--groups-menu)) 615 | (when click-on-tab-p 616 | (centaur-tabs-do-select event) 617 | (redisplay t) 618 | (let* 619 | ((menu (easy-menu-create-menu nil (centaur-tabs--tab-menu-definition))) 620 | (choice (x-popup-menu t menu)) 621 | (action (lookup-key menu (apply 'vector choice))) 622 | (action-is-command-p (and (commandp action) (functionp action)))) 623 | (when action-is-command-p 624 | (call-interactively action)) 625 | (when (not action-is-command-p) 626 | (let* ((menu-key (cl-first choice)) 627 | (choice-is-group-p (string= centaur-tabs--groups-submenu-key (symbol-name menu-key))) 628 | (name (car (last choice))) 629 | (name-as-string (symbol-name name))) 630 | (if choice-is-group-p 631 | (centaur-tabs-switch-group name-as-string) 632 | (switch-to-buffer name-as-string)))))))) 633 | 634 | (defun centaur-tabs--groups-menu () 635 | "Show a popup menu with the centaur tabs groups." 636 | (interactive) 637 | (let* ((sorted-groups (centaur-tabs--tab-submenu-groups-definition)) 638 | (menu (easy-menu-create-menu "Tab groups" 639 | (centaur-tabs--tab-submenu-groups-definition))) 640 | (choice (x-popup-menu t menu)) 641 | (action (lookup-key menu (apply 'vector choice))) 642 | (action-is-command-p (and (commandp action) (functionp action)))) 643 | (when action-is-command-p 644 | (call-interactively action)) 645 | (when (not action-is-command-p) 646 | (let ((group (car (last choice)))) 647 | (centaur-tabs-switch-group (format "%s" group)))))) 648 | 649 | (provide 'centaur-tabs-interactive) 650 | ;;; centaur-tabs-interactive.el ends here 651 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /centaur-tabs-elements.el: -------------------------------------------------------------------------------- 1 | ;;; centaur-tabs-elements.el --- centaur-tabs visual components and customizations -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2019-2024 Emmanuel Bustos 4 | ;; Copyright (C) 2024 Jen-Chieh Shen 5 | 6 | ;; This file is not part of GNU Emacs. 7 | 8 | ;; This program is free software; you can redistribute it and/or 9 | ;; modify it under the terms of the GNU General Public License as 10 | ;; published by the Free Software Foundation; either version 2, or 11 | ;; (at your option) any later version. 12 | ;; 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | ;; General Public License for more details. 17 | ;; 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program; see the file COPYING. If not, write to 20 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 21 | ;; Floor, Boston, MA 02110-1301, USA. 22 | 23 | ;;; Commentary: 24 | ;; 25 | ;; This file contains the visual components of centaur-tabs 26 | ;; 27 | 28 | ;;; Code: 29 | 30 | (require 'custom) 31 | (require 'color) 32 | (require 'powerline) 33 | 34 | ;; Compiler pacifier 35 | (declare-function all-the-icons-icon-for-file "ext:all-the-icons.el" t t) 36 | (declare-function all-the-icons-icon-for-mode "ext:all-the-icons.el" t t) 37 | (declare-function nerd-icons-icon-for-file "ext:nerd-icons.el" t t) 38 | (declare-function nerd-icons-icon-for-mode "ext:nerd-icons.el" t t) 39 | 40 | ;; 41 | ;;; Faces 42 | 43 | (defface centaur-tabs-default 44 | '((t (:background "black" :foreground "black"))) 45 | "Default face used in the tab bar." 46 | :group 'centaur-tabs) 47 | 48 | (defface centaur-tabs-unselected 49 | '((t (:background "#3D3C3D" :foreground "grey50"))) 50 | "Face used for unselected tabs." 51 | :group 'centaur-tabs) 52 | 53 | (defface centaur-tabs-selected 54 | '((t (:background "#31343E" :foreground "white"))) 55 | "Face used for the selected tab." 56 | :group 'centaur-tabs) 57 | 58 | (defface centaur-tabs-unselected-modified 59 | '((t (:background "#3D3C3D" :foreground "grey50"))) 60 | "Face used for unselected-modified tabs." 61 | :group 'centaur-tabs) 62 | 63 | (defface centaur-tabs-selected-modified 64 | '((t (:background "#31343E" :foreground "white"))) 65 | "Face used for the selected-modified tab." 66 | :group 'centaur-tabs) 67 | 68 | (defface centaur-tabs-close-unselected 69 | '((t (:inherit centaur-tabs-unselected))) 70 | "Face used for unselected close button." 71 | :group 'centaur-tabs) 72 | 73 | (defface centaur-tabs-close-selected 74 | '((t (:inherit centaur-tabs-selected))) 75 | "Face used for selected close button." 76 | :group 'centaur-tabs) 77 | 78 | (defface centaur-tabs-name-mouse-face 79 | '((t nil)) 80 | "Face used for tab name when hovered with the mouse." 81 | :group 'centaur-tabs) 82 | 83 | (defface centaur-tabs-close-mouse-face 84 | '((t (:inherit underline))) 85 | "Face used for close button when hovered with the mouse." 86 | :group 'centaur-tabs) 87 | 88 | (defface centaur-tabs-modified-marker-selected 89 | `((t (:inherit centaur-tabs-selected))) 90 | "Face used for selected modified marker." 91 | :group 'centaur-tabs) 92 | 93 | (defface centaur-tabs-modified-marker-unselected 94 | `((t (:inherit centaur-tabs-unselected))) 95 | "Face used for unselected modified marker." 96 | :group 'centaur-tabs) 97 | 98 | (defface centaur-tabs-active-bar-face 99 | '((t (:background "cyan"))) 100 | "Face used for selected tab bar." 101 | :group 'centaur-tabs) 102 | 103 | (defface centaur-tabs-jump-identifier-selected 104 | '((t (:inherit centaur-tabs-modified-marker-selected :weight extra-bold))) 105 | "Face used for selected tab identifiers when centaur-tabs-ace-jump is invoked." 106 | :group 'centaur-tabs) 107 | 108 | (defface centaur-tabs-jump-identifier-unselected 109 | '((t (:inherit centaur-tabs-modified-marker-unselected :weight extra-bold))) 110 | "Face used for unselected tab identifiers when centaur-tabs-ace-jump is invoked." 111 | :group 'centaur-tabs) 112 | 113 | (defface centaur-tabs-dim-buffer-face 114 | '((t (:foreground "gray40"))) 115 | "Face for the buffer when centaur-tabs-ace-jump is invoked." 116 | :group 'centaur-tabs) 117 | 118 | ;; 119 | ;;; Tabs' display line 120 | 121 | (defvar centaur-tabs-display-line 122 | (if (boundp 'tab-line-format) 123 | 'tab-line 124 | 'header-line)) 125 | 126 | (defvar centaur-tabs-display-line-format 127 | (if (boundp 'tab-line-format) 128 | 'tab-line-format 129 | 'header-line-format)) 130 | 131 | ;; 132 | ;;; Tabs' characteristics 133 | 134 | (defcustom centaur-tabs-style "bar" 135 | "The style of tab." 136 | :group 'centaur-tabs 137 | :type 'string) 138 | 139 | (defcustom centaur-tabs-background-color 140 | (face-background 'centaur-tabs-default nil 'default) 141 | "*Background color of the tab bar. 142 | By default, use the background color specified for the 143 | `centaur-tabs-default' face (or inherited from another face), or the 144 | background color of the `default' face otherwise." 145 | :group 'centaur-tabs 146 | :type 'face) 147 | 148 | (defcustom centaur-tabs-height 22 149 | "The height of tab." 150 | :group 'centaur-tabs 151 | :type 'integer) 152 | 153 | (defcustom centaur-tabs-bar-height (+ 8 centaur-tabs-height) 154 | "The height of bar." 155 | :group 'centaur-tabs 156 | :type 'integer) 157 | 158 | (defcustom centaur-tabs-mouse-pointer 'hand 159 | "Cursor to display when hovering the tabs. 160 | Default is `'hand'. The following scopes are possible: 161 | - arrow 162 | - hand 163 | - vdrag 164 | - hdrag 165 | - modeline 166 | - hourglass" 167 | :group 'centaur-tabs 168 | :type 'variable) 169 | 170 | (defcustom centaur-tabs-set-bar nil 171 | "When non nil, display a bar to show the currently selected tab. 172 | There are three options: 173 | - `'left': displays the bar at the left of the currently selected tab. 174 | - `'under': displays the bar under the currently selected tab. 175 | - `'over': displays the bar over the currently selected tab." 176 | :group 'centaur-tabs 177 | :type '(choice :tag "Display bar at..." 178 | (const :tag "Put bar on the left" left) 179 | (const :tag "Put bar as an underline" under) 180 | (const :tag "Put bar as an overline" over))) 181 | 182 | ;; 183 | ;;; Icons 184 | 185 | (defcustom centaur-tabs-set-icons nil 186 | "When non nil, display an icon based on `centaur-tabs-icon-type' alongside 187 | the tab name." 188 | :group 'centaur-tabs 189 | :type 'boolean) 190 | 191 | (defcustom centaur-tabs-icon-type (and centaur-tabs-set-icons 192 | (or (require 'all-the-icons nil t) 193 | (require 'nerd-icons nil t))) 194 | "Icon type; it should be one of `all-the-icons' and `nerd-icons'." 195 | :group 'centaur-tabs 196 | :type 'symbol 197 | :set 198 | (lambda (k v) 199 | (pcase v 200 | ('all-the-icons 201 | (unless (require 'all-the-icons nil t) 202 | (setq v nil))) 203 | ('nerd-icons 204 | (unless (require 'nerd-icons nil t) 205 | (setq v nil))) 206 | ('type 207 | (if (require 'all-the-icons nil t) 208 | (setq v 'all-the-icons) 209 | (setq v nil)))) 210 | (set k v))) 211 | 212 | (defvar centaur-tabs-icon-scale-factor 1.0 213 | "The base scale factor for the `height' face property of tab icons.") 214 | 215 | (defvar centaur-tabs-icon-v-adjust 0.01 216 | "The vertical adjust for tab icons.") 217 | 218 | (defcustom centaur-tabs-gray-out-icons nil 219 | "When non nil, enable gray icons for unselected buffer." 220 | :group 'centaur-tabs 221 | :type '(choice :tag "Gray out icons for unselected..." 222 | (const :tag "Buffer" buffer))) 223 | 224 | (defcustom centaur-tabs-plain-icons nil 225 | "When non nil, tab icons' color will be the same as tabs' foreground color." 226 | :group 'centaur-tabs 227 | :type 'boolean) 228 | 229 | (defcustom centaur-tabs-icons-prefix " " 230 | "Prefix string before icons." 231 | :group 'centaur-tabs 232 | :type 'string) 233 | 234 | (defun centaur-tabs--icon-for-file (file &rest args) 235 | "Get the formatted icon for FILE. 236 | ARGS should be a plist containing `:height', `:v-adjust', or `:face' properties." 237 | (pcase centaur-tabs-icon-type 238 | ('all-the-icons (apply #'all-the-icons-icon-for-file file args)) 239 | ('nerd-icons (apply #'nerd-icons-icon-for-file file args)))) 240 | 241 | (defun centaur-tabs--icon-for-mode (mode &rest args) 242 | "Get the formatted icon for MODE. 243 | 244 | ARGS should be a plist containining `:height', `:v-adjust' or `:face' properties 245 | like in the normal icon inserting functions." 246 | (pcase centaur-tabs-icon-type 247 | ('all-the-icons (apply #'all-the-icons-icon-for-mode mode args)) 248 | ('nerd-icons (apply #'nerd-icons-icon-for-mode mode args)))) 249 | 250 | (defun centaur-tabs-icon (tab face selected) 251 | "Generate icon for TAB using FACE's background. 252 | If icon gray out option enabled, gray out icon if not SELECTED." 253 | (if centaur-tabs-icon-type 254 | (with-current-buffer (car tab) 255 | (let* ((icon 256 | (or (ignore-errors 257 | (centaur-tabs--icon-for-file 258 | (file-name-nondirectory (buffer-file-name)) 259 | :v-adjust centaur-tabs-icon-v-adjust 260 | :height centaur-tabs-icon-scale-factor)) 261 | (ignore-errors 262 | (centaur-tabs--icon-for-mode 263 | major-mode 264 | :v-adjust centaur-tabs-icon-v-adjust 265 | :height centaur-tabs-icon-scale-factor)))) 266 | (background (face-background face nil 'default)) 267 | (inactive (cond ((and (not selected) 268 | (eq centaur-tabs-gray-out-icons 'buffer)) 269 | (face-foreground 'mode-line-inactive nil 'default)) 270 | (centaur-tabs-plain-icons 271 | (face-foreground 'centaur-tabs-selected nil 'default)) 272 | (t 'unspecified))) 273 | (underline (and (eq (if (display-graphic-p) centaur-tabs-set-bar) 'under) 274 | (face-attribute face :underline))) 275 | (overline (and (eq (if (display-graphic-p) centaur-tabs-set-bar) 'over) 276 | (face-attribute face :overline)))) 277 | (if-let* (((stringp icon)) 278 | (icon-char (string-to-char icon)) 279 | ((char-displayable-p icon-char))) 280 | (propertize icon 'face `( :inherit ,(get-text-property 0 'face icon) 281 | :foreground ,inactive 282 | :background ,background 283 | :underline ,underline 284 | :overline ,overline)) 285 | ""))) 286 | "")) 287 | 288 | ;; 289 | ;;; Ace-window style tab switching 290 | 291 | (defcustom centaur-tabs-show-jump-identifier 'prompted 292 | "Whether to show the tab identifier for centaur-tabs-ace-jump. 293 | It has 3 options: 294 | - `'nil', never show the jump identifier. 295 | - `'prompted', only show it when using centaur-tabs-ace-jump. 296 | - `'always', always show it regardless of the status." 297 | :group 'centaur-tabs 298 | :type '(choice :tag "show identifier when..." 299 | (const :tag "Never" nil) 300 | (const :tag "Only when prompted" prompted) 301 | (const :tag "Always" always))) 302 | 303 | (defcustom centaur-tabs-ace-jump-dim-buffer t 304 | "Whether to dim the current buffer when centaur-ace-jump is activated." 305 | :type 'boolean 306 | :group 'centaur-tabs) 307 | 308 | (defvar centaur-tabs-ace-jump-keys 309 | '(?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9) 310 | "Buffer jump keys used by centaur-tabs-ace-jump.") 311 | 312 | (defvar centaur-tabs-ace-dispatch-alist 313 | '((?q exit "Exit") 314 | (?\C-g exit "Exit") 315 | (?j jump-to-tab "Jump to tab") 316 | (?x close-tab "Close tab") 317 | (?s swap-tab "Swap tab") 318 | (?\[ backward-group "Previous group") 319 | (?\] forward-group "Next group") 320 | (?? show-help "Show dispatch help")) 321 | "Action keys used by centaur-tabs-ace-jump. 322 | The value of each element must be in the form: 323 | \(key keyword docstring), where keyword must be one of the follows: 324 | \(exit, jump-to-tab, close-tab, swap-tab, backward-group, 325 | forward-group, show-help).") 326 | 327 | ;; 328 | ;;; Close buttons, modified marker and edges' margins 329 | 330 | (defun centaur-tabs-char-displayable-p (ch) 331 | "Same as function `char-displayable-p' but accept CH as string." 332 | (cond ((stringp ch) (char-displayable-p (string-to-char ch))) 333 | (t (char-displayable-p ch)))) 334 | 335 | (defun centaur-tabs-choose-char (str1 str2) 336 | "Use STR2 when STR1 is not displayable." 337 | (if (centaur-tabs-char-displayable-p str1) str1 str2)) 338 | 339 | (defcustom centaur-tabs-set-close-button t 340 | "When non nil, display a clickable close button on the right side of the tabs." 341 | :group 'centaur-tabs 342 | :type 'boolean) 343 | 344 | (defcustom centaur-tabs-set-left-close-button nil 345 | "When non nil, display a clickable close button on the left side of the tabs." 346 | :group 'centaur-tabs 347 | :type 'boolean) 348 | 349 | (defcustom centaur-tabs-close-button 350 | (centaur-tabs-choose-char (make-string 1 #x00D7) "x") 351 | "Display appearance of the close buttons, if enabled." 352 | :group 'centaur-tabs 353 | :type 'string) 354 | 355 | (defcustom centaur-tabs-set-modified-marker nil 356 | "When non nil, display a marker when the buffer is modified." 357 | :group 'centaur-tabs 358 | :type 'boolean) 359 | 360 | (defcustom centaur-tabs-modified-marker 361 | (centaur-tabs-choose-char (make-string 1 #x23FA) "*") 362 | "Display appearance of the modified marker, if enabled." 363 | :group 'centaur-tabs 364 | :type 'string) 365 | 366 | (defcustom centaur-tabs-left-edge-margin " " 367 | "Text to display at the left edge of the tabs, or nil for no added margin." 368 | :group 'centaur-tabs 369 | :type 'string) 370 | 371 | (defcustom centaur-tabs-right-edge-margin " " 372 | "Text to display at the right edge of the tabs, or nil for no added margin." 373 | :group 'centaur-tabs 374 | :type 'string) 375 | 376 | ;; 377 | ;;; Selected tab bar 378 | 379 | (defun centaur-tabs--make-xpm (face width height) 380 | "Create an XPM bitmap via FACE WIDTH and HEIGHT. 381 | Taken from `doom-modeline'." 382 | (when (and (display-graphic-p) 383 | (image-type-available-p 'xpm)) 384 | (propertize 385 | " " 'display 386 | (let ((data (make-list height (make-list width 1))) 387 | (color (or (face-background face nil t) "None"))) 388 | (ignore-errors 389 | (create-image 390 | (concat 391 | (format 392 | "/* XPM */\nstatic char * percent[] = {\n\"%i %i 2 1\",\n\". c %s\",\n\" c %s\"," 393 | (length (car data)) (length data) color color) 394 | (apply #'concat 395 | (cl-loop with idx = 0 396 | with len = (length data) 397 | for dl in data 398 | do (cl-incf idx) 399 | collect 400 | (concat 401 | "\"" 402 | (cl-loop for d in dl 403 | if (= d 0) collect (string-to-char " ") 404 | else collect (string-to-char ".")) 405 | (if (eq idx len) "\"};" "\",\n"))))) 406 | 'xpm t :ascent 'center)))))) 407 | 408 | (defvar centaur-tabs-active-bar 409 | (centaur-tabs--make-xpm 'centaur-tabs-active-bar-face 410 | 2 411 | centaur-tabs-bar-height)) 412 | 413 | ;; 414 | ;;; Navigation buttons 415 | 416 | (defcustom centaur-tabs-show-navigation-buttons nil 417 | "When non-nil, show the buttons for backward/forward tabs." 418 | :group 'centaur-tabs 419 | :type 'boolean) 420 | 421 | (defcustom centaur-tabs-down-tab-text " ▾ " 422 | "Text icon to show in the down button tab." 423 | :group 'centaur-tabs 424 | :type 'string) 425 | 426 | (defcustom centaur-tabs-backward-tab-text " ⏴ " 427 | "Text icon to show in the backward button tab." 428 | :group 'centaur-tabs 429 | :type 'string) 430 | 431 | (defcustom centaur-tabs-forward-tab-text " ⏵ " 432 | "Text icon to show in the forward button tab." 433 | :group 'centaur-tabs 434 | :type 'string) 435 | 436 | (defcustom centaur-tabs-show-count nil 437 | "When non-nil, show the current index and count of tabs in the current group." 438 | :group 'centaur-tabs 439 | :type 'boolean) 440 | 441 | (defcustom centaur-tabs-count-format " [%d/%d] " 442 | "Format text to display count." 443 | :group 'centaur-tabs 444 | :type 'string) 445 | 446 | ;; 447 | ;;; New tab button 448 | 449 | (defcustom centaur-tabs-show-new-tab-button t 450 | "When non-nil, show the button to create a new tab." 451 | :group 'centaur-tabs 452 | :type 'boolean) 453 | 454 | (defcustom centaur-tabs-new-tab-text " + " 455 | "Text icon to show in the new-tab button." 456 | :group 'centaur-tabs 457 | :type 'string) 458 | 459 | ;; 460 | ;;; Separators 461 | 462 | (defvar centaur-tabs-style-left nil) 463 | (defvar centaur-tabs-style-right nil) 464 | 465 | (defvar ns-use-srgb-colorspace) 466 | 467 | (defvar centaur-tabs-image-apple-rgb 468 | (and (eq (window-system) 'ns) 469 | ns-use-srgb-colorspace 470 | (< 11 471 | (string-to-number 472 | (and (string-match "darwin\\([0-9]+\\)" system-configuration) 473 | (match-string-no-properties 1 system-configuration))))) 474 | "Boolean variable to determine whether to use Apple RGB colorspace. 475 | used to render images. 476 | 477 | t on macOS 10.7+ and `ns-use-srgb-colorspace' is t, nil otherwise. 478 | 479 | This variable is automatically set, there's no need to modify it.") 480 | 481 | (defun centaur-tabs-separator-interpolate (color1 color2) 482 | "Interpolate between COLOR1 and COLOR2. 483 | 484 | COLOR1 and COLOR2 must be supplied as hex strings with a leading #." 485 | (let* ((c1 (color-name-to-rgb color1)) 486 | (c2 (color-name-to-rgb color2)) 487 | (red (/ (+ (nth 0 c1) (nth 0 c2)) 2)) 488 | (green (/ (+ (nth 1 c1) (nth 1 c2)) 2)) 489 | (blue (/ (+ (nth 2 c1) (nth 2 c2)) 2))) 490 | (color-rgb-to-hex red green blue))) 491 | 492 | (defun centaur-tabs-separator-color-xyz-to-apple-rgb (X Y Z) 493 | "Convert CIE X Y Z colors to Apple RGB color space." 494 | (let ((r (+ (* 3.2404542 X) (* -1.5371385 Y) (* -0.4985314 Z))) 495 | (g (+ (* -0.9692660 X) (* 1.8760108 Y) (* 0.0415560 Z))) 496 | (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z)))) 497 | (list (expt r (/ 1.8)) (expt g (/ 1.8)) (expt b (/ 1.8))))) 498 | 499 | (defun centaur-tabs-separator-color-srgb-to-apple-rgb (red green blue) 500 | "Convert RED GREEN BLUE colors from sRGB color space to Apple RGB. 501 | RED, GREEN and BLUE should be between 0.0 and 1.0, inclusive." 502 | (apply #'centaur-tabs-separator-color-xyz-to-apple-rgb (color-srgb-to-xyz red green blue))) 503 | 504 | (defun centaur-tabs-separator-hex-color (color) 505 | "Get the hexadecimal value of COLOR." 506 | (when color 507 | (let ((srgb-color (color-name-to-rgb color))) 508 | (if centaur-tabs-image-apple-rgb 509 | (apply #'color-rgb-to-hex (apply #'centaur-tabs-separator-color-srgb-to-apple-rgb srgb-color)) 510 | (apply #'color-rgb-to-hex srgb-color))))) 511 | 512 | (defun centaur-tabs-separator-pattern (lst) 513 | "Turn LST into an infinite pattern." 514 | (when lst 515 | (let ((pattern (cl-copy-list lst))) 516 | (setcdr (last pattern) pattern)))) 517 | 518 | (defun centaur-tabs-separator-pattern-to-string (pattern) 519 | "Convert a PATTERN into a string that can be used in an XPM." 520 | (concat "\"" (mapconcat #'number-to-string pattern "") "\",")) 521 | 522 | (defun centaur-tabs-separator-reverse-pattern (pattern) 523 | "Reverse each line in PATTERN." 524 | (mapcar 'reverse pattern)) 525 | 526 | (defun centaur-tabs-separator-row-pattern (fill total &optional fade) 527 | "Make a list that has FILL 0s out of TOTAL 1s with FADE 2s to the right of 528 | the fill." 529 | (unless fade (setq fade 0)) 530 | (let ((fill (min fill total)) 531 | (fade (min fade (max (- total fill) 0)))) 532 | (append (make-list fill 0) 533 | (make-list fade 2) 534 | (make-list (- total fill fade) 1)))) 535 | 536 | (defun centaur-tabs-separator-pattern-bindings-body (patterns height-exp pattern-height-sym 537 | second-pattern-height-sym) 538 | "Create let-var bindings and a function body from PATTERNS. 539 | The `car' and `cdr' parts of the result can be passed to the 540 | function `centaur-tabs-separator-wrap-defun' as its `let-vars' 541 | and `body' arguments,respectively. HEIGHT-EXP is an expression 542 | calculating the image height and it should contain a free variable `height'. 543 | PATTERN-HEIGHT-SYM and SECOND-PATTERN-HEIGHT-SYM are symbols used 544 | for let-var binding variables." 545 | (let* ((pattern (centaur-tabs-separator-pattern (mapcar 'centaur-tabs-separator-pattern-to-string (car patterns)))) 546 | (header (mapcar 'centaur-tabs-separator-pattern-to-string (nth 1 patterns))) 547 | (footer (mapcar 'centaur-tabs-separator-pattern-to-string (nth 2 patterns))) 548 | (second-pattern (centaur-tabs-separator-pattern (mapcar 'centaur-tabs-separator-pattern-to-string (nth 3 patterns)))) 549 | (center (mapcar 'centaur-tabs-separator-pattern-to-string (nth 4 patterns))) 550 | (reserve (+ (length header) (length footer) (length center)))) 551 | (when pattern 552 | (cons `((,pattern-height-sym (max (- ,height-exp ,reserve) 0)) 553 | (,second-pattern-height-sym (/ ,pattern-height-sym 2)) 554 | (,pattern-height-sym ,(if second-pattern `(ceiling ,pattern-height-sym 2) `,pattern-height-sym))) 555 | (list (when header `(mapconcat 'identity ',header "")) 556 | `(mapconcat 'identity 557 | (cl-subseq ',pattern 0 ,pattern-height-sym) "") 558 | (when center `(mapconcat 'identity ',center "")) 559 | (when second-pattern 560 | `(mapconcat 'identity 561 | (cl-subseq ',second-pattern 562 | 0 ,second-pattern-height-sym) "")) 563 | (when footer `(mapconcat 'identity ',footer ""))))))) 564 | 565 | (defun centaur-tabs-separator-pattern-defun (name dir width &rest patterns) 566 | "Create a powerline function of NAME in DIR with WIDTH for PATTERNS. 567 | 568 | PATTERNS is of the form (PATTERN HEADER FOOTER SECOND-PATTERN CENTER 569 | PATTERN-2X HEADER-2X FOOTER-2X SECOND-PATTERN-2X CENTER-2X). 570 | PATTERN is required, all other components are optional. 571 | The first 5 components are for the standard resolution image. 572 | The remaining ones are for the high resolution image where both 573 | width and height are doubled. If PATTERN-2X is nil or not given, 574 | then the remaining components are ignored and the standard 575 | resolution image with magnification and interpolation will be 576 | used in high resolution environments 577 | 578 | All generated functions generate the form: 579 | HEADER 580 | PATTERN ... 581 | CENTER 582 | SECOND-PATTERN ... 583 | FOOTER 584 | 585 | PATTERN and SECOND-PATTERN repeat infinitely to fill the space needed to 586 | generate a full height XPM. 587 | 588 | PATTERN, HEADER, FOOTER, SECOND-PATTERN, CENTER are of the form 589 | \((COLOR ...) (COLOR ...) ...). 590 | 591 | COLOR can be one of 0, 1, or 2, where 0 is the source color, 1 is the 592 | destination color, and 2 is the interpolated color between 0 and 1." 593 | (when (eq dir 'right) 594 | (setq patterns (mapcar 'centaur-tabs-separator-reverse-pattern patterns))) 595 | (let ((bindings-body (centaur-tabs-separator-pattern-bindings-body patterns 596 | 'height 597 | 'pattern-height 598 | 'second-pattern-height)) 599 | (bindings-body-2x (centaur-tabs-separator-pattern-bindings-body (nthcdr 5 patterns) 600 | '(* height 2) 601 | 'pattern-height-2x 602 | 'second-pattern-height-2x))) 603 | (centaur-tabs-separator-wrap-defun name dir width 604 | (append (car bindings-body) (car bindings-body-2x)) 605 | (cdr bindings-body) (cdr bindings-body-2x)))) 606 | 607 | (defun centaur-tabs-separator-background-color (face) 608 | "Set the separator background color using FACE." 609 | (face-attribute face 610 | (if (face-attribute face :inverse-video nil 'default) 611 | :foreground 612 | :background) 613 | nil 614 | 'default)) 615 | 616 | (defun centaur-tabs-separator-wrap-defun (name dir width let-vars body &optional body-2x) 617 | "Generate a powerline function of name NAME in dir DIR. 618 | This is made with WIDTH using LET-VARS and BODY. 619 | BODY-2X is an optional argument." 620 | (let* ((src-face (if (eq dir 'left) 'face1 'face2)) 621 | (dst-face (if (eq dir 'left) 'face2 'face1))) 622 | `(defun ,(intern (format "powerline-%s-%s" name (symbol-name dir))) 623 | (face1 face2 &optional height) 624 | (when window-system 625 | (unless height (setq height centaur-tabs-height)) 626 | (let* ,(append `((color1 (when ,src-face 627 | (centaur-tabs-separator-hex-color (centaur-tabs-separator-background-color ,src-face)))) 628 | (color2 (when ,dst-face 629 | (centaur-tabs-separator-hex-color (centaur-tabs-separator-background-color ,dst-face)))) 630 | (colori (when (and color1 color2) (centaur-tabs-separator-interpolate color1 color2))) 631 | (color1 (or color1 "None")) 632 | (color2 (or color2 "None")) 633 | (colori (or colori "None"))) 634 | let-vars) 635 | (apply #'create-image 636 | ,(append `(concat (format "/* XPM */ static char * %s_%s[] = { \"%s %s 3 1\", \"0 c %s\", \"1 c %s\", \"2 c %s\"," 637 | ,(replace-regexp-in-string "-" "_" name) 638 | (symbol-name ',dir) 639 | ,width 640 | height 641 | color1 642 | color2 643 | colori)) 644 | body 645 | '("};")) 646 | 'xpm t 647 | :ascent 'center 648 | :face (when (and face1 face2) 649 | ,dst-face) 650 | ,(and body-2x 651 | `(and (featurep 'mac) 652 | (list :data-2x 653 | ,(append `(concat (format "/* XPM */ static char * %s_%s_2x[] = { \"%s %s 3 1\", \"0 c %s\", \"1 c %s\", \"2 c %s\"," 654 | ,(replace-regexp-in-string "-" "_" name) 655 | (symbol-name ',dir) 656 | (* ,width 2) 657 | (* height 2) 658 | color1 659 | color2 660 | colori)) 661 | body-2x 662 | '("};"))))))))))) 663 | 664 | (defun centaur-tabs-separator-alternate (dir) 665 | "Generate an alternating pattern XPM function for DIR." 666 | (centaur-tabs-separator-pattern-defun "alternate" dir 4 667 | '((2 2 1 1) 668 | (0 0 2 2)) 669 | nil nil nil nil 670 | ;; 2x 671 | '((2 2 2 2 1 1 1 1) 672 | (2 2 2 2 1 1 1 1) 673 | (0 0 0 0 2 2 2 2) 674 | (0 0 0 0 2 2 2 2)))) 675 | 676 | (defun centaur-tabs-separator-bar (dir) 677 | "Generate a bar XPM function for DIR." 678 | (centaur-tabs-separator-pattern-defun "bar" dir 2 679 | '((2 2)))) 680 | 681 | (defun centaur-tabs-separator-box (dir) 682 | "Generate a box XPM function for DIR." 683 | (centaur-tabs-separator-pattern-defun "box" dir 2 684 | '((0 0) 685 | (0 0) 686 | (1 1) 687 | (1 1)) 688 | nil nil nil nil 689 | ;; 2x 690 | '((0 0 0 0) 691 | (0 0 0 0) 692 | (0 0 0 0) 693 | (0 0 0 0) 694 | (1 1 1 1) 695 | (1 1 1 1) 696 | (1 1 1 1) 697 | (1 1 1 1)))) 698 | 699 | (defun centaur-tabs-separator-chamfer (dir) 700 | "Generate a chamfer XPM function for DIR." 701 | (centaur-tabs-separator-pattern-defun "chamfer" dir 3 702 | '((0 0 0)) 703 | '((1 1 1) 704 | (0 1 1) 705 | (0 0 1)) 706 | nil nil nil 707 | ;; 2x 708 | '((0 0 0 0 0 0)) 709 | '((1 1 1 1 1 1) 710 | (0 1 1 1 1 1) 711 | (0 0 1 1 1 1) 712 | (0 0 0 1 1 1) 713 | (0 0 0 0 1 1) 714 | (0 0 0 0 0 1)))) 715 | 716 | (defun centaur-tabs-separator-rounded (dir) 717 | "Generate a rounded XPM function for DIR." 718 | (centaur-tabs-separator-pattern-defun "rounded" dir 6 719 | '((0 0 0 0 0 0)) 720 | '((2 1 1 1 1 1) 721 | (0 0 2 1 1 1) 722 | (0 0 0 0 1 1) 723 | (0 0 0 0 2 1) 724 | (0 0 0 0 0 1) 725 | (0 0 0 0 0 2)) 726 | nil nil nil 727 | ;; 2x 728 | '((0 0 0 0 0 0 0 0 0 0 0 0)) 729 | '((1 1 1 1 1 1 1 1 1 1 1 1) 730 | (0 0 2 1 1 1 1 1 1 1 1 1) 731 | (0 0 0 0 1 1 1 1 1 1 1 1) 732 | (0 0 0 0 0 0 1 1 1 1 1 1) 733 | (0 0 0 0 0 0 0 2 1 1 1 1) 734 | (0 0 0 0 0 0 0 0 1 1 1 1) 735 | (0 0 0 0 0 0 0 0 0 1 1 1) 736 | (0 0 0 0 0 0 0 0 0 0 1 1) 737 | (0 0 0 0 0 0 0 0 0 0 1 1) 738 | (0 0 0 0 0 0 0 0 0 0 2 1) 739 | (0 0 0 0 0 0 0 0 0 0 0 1) 740 | (0 0 0 0 0 0 0 0 0 0 0 1)))) 741 | 742 | (defun centaur-tabs-separator-slant (dir) 743 | "Generate a slant XPM function for DIR." 744 | (let* ((row-modifier (if (eq dir 'left) 'identity 'reverse))) 745 | (centaur-tabs-separator-wrap-defun "slant" dir 'width 746 | '((width (1- (ceiling height 2)))) 747 | `((cl-loop for i from 0 to (1- height) 748 | concat (centaur-tabs-separator-pattern-to-string (,row-modifier (centaur-tabs-separator-row-pattern (/ i 2) width))))) 749 | `((cl-loop for i from 0 to (1- (* height 2)) 750 | concat (centaur-tabs-separator-pattern-to-string (,row-modifier (centaur-tabs-separator-row-pattern (/ i 2) (* width 2))))))))) 751 | 752 | (defun centaur-tabs-separator-wave (dir) 753 | "Generate a wave XPM function for DIR." 754 | (centaur-tabs-separator-pattern-defun "wave" dir 11 755 | '((0 0 0 0 0 0 1 1 1 1 1)) 756 | '((2 1 1 1 1 1 1 1 1 1 1) 757 | (0 0 1 1 1 1 1 1 1 1 1) 758 | (0 0 0 1 1 1 1 1 1 1 1) 759 | (0 0 0 2 1 1 1 1 1 1 1) 760 | (0 0 0 0 1 1 1 1 1 1 1) 761 | (0 0 0 0 2 1 1 1 1 1 1) 762 | (0 0 0 0 0 1 1 1 1 1 1) 763 | (0 0 0 0 0 1 1 1 1 1 1) 764 | (0 0 0 0 0 2 1 1 1 1 1)) 765 | '((0 0 0 0 0 0 2 1 1 1 1) 766 | (0 0 0 0 0 0 0 1 1 1 1) 767 | (0 0 0 0 0 0 0 1 1 1 1) 768 | (0 0 0 0 0 0 0 2 1 1 1) 769 | (0 0 0 0 0 0 0 0 1 1 1) 770 | (0 0 0 0 0 0 0 0 2 1 1) 771 | (0 0 0 0 0 0 0 0 0 0 2)) 772 | nil nil 773 | ;; 2x 774 | '((0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1)) 775 | '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 776 | (0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 777 | (0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 778 | (0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 779 | (0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 780 | (0 0 0 0 0 0 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 781 | (0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 782 | (0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 783 | (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 784 | (0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1) 785 | (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1) 786 | (0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1) 787 | (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1) 788 | (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1) 789 | (0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1) 790 | (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1) 791 | (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1) 792 | (0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1)) 793 | '((0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1) 794 | (0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1) 795 | (0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1) 796 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1) 797 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1) 798 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1) 799 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1) 800 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1) 801 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1) 802 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1) 803 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 1) 804 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1) 805 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1) 806 | (0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)))) 807 | 808 | (defun centaur-tabs-separator-zigzag (dir) 809 | "Generate a zigzag pattern XPM function for DIR." 810 | (centaur-tabs-separator-pattern-defun "zigzag" dir 3 811 | '((1 1 1) 812 | (0 1 1) 813 | (0 0 1) 814 | (0 0 0) 815 | (0 0 1) 816 | (0 1 1)) 817 | nil nil nil nil 818 | ;; 2x 819 | '((1 1 1 1 1 1) 820 | (0 1 1 1 1 1) 821 | (0 0 1 1 1 1) 822 | (0 0 0 1 1 1) 823 | (0 0 0 0 1 1) 824 | (0 0 0 0 0 1) 825 | (0 0 0 0 0 0) 826 | (0 0 0 0 0 1) 827 | (0 0 0 0 1 1) 828 | (0 0 0 1 1 1) 829 | (0 0 1 1 1 1) 830 | (0 1 1 1 1 1)))) 831 | 832 | (defun centaur-tabs-separator-memoize (func) 833 | "Memoize FUNC. 834 | If argument is a symbol then install the memoized function over 835 | the original function. Use frame-local memoization." 836 | (cl-typecase func 837 | (symbol (fset func (centaur-tabs-separator-memoize-wrap-frame-local (symbol-function func))) func) 838 | (function (centaur-tabs-separator-memoize-wrap-frame-local func)))) 839 | 840 | (defun centaur-tabs-separator-memoize-wrap-frame-local (func) 841 | "Return the memoized version of FUNC. 842 | The memoization cache is frame-local." 843 | (let ((funcid (cl-gensym))) 844 | `(lambda (&rest args) 845 | ,(concat (documentation func) (format "\n(memoized function %s)" funcid)) 846 | (let* ((cache (centaur-tabs-separator-create-or-get-cache)) 847 | (key (cons ',funcid args)) 848 | (val (gethash key cache))) 849 | (or val 850 | (puthash key (apply ,func args) cache)))))) 851 | 852 | (defun centaur-tabs-separator-create-or-get-cache () 853 | "Return a frame-local hash table that acts as a memoization cache. 854 | The cache is for the powerline. 855 | Create one if the frame doesn't have one yet." 856 | (if-let* ((table (frame-parameter nil 'powerline-cache)) 857 | ((hash-table-p table))) 858 | table 859 | (centaur-tabs-separator-reset-cache))) 860 | 861 | (defun centaur-tabs-separator-reset-cache () 862 | "Reset and return the frame-local hash table used for a memoization cache." 863 | (let ((table (make-hash-table :test 'equal))) 864 | ;; Store it as a frame-local variable 865 | (modify-frame-parameters nil `((powerline-cache . ,table))) 866 | table)) 867 | 868 | (centaur-tabs-separator-memoize (centaur-tabs-separator-alternate 'left)) 869 | (centaur-tabs-separator-memoize (centaur-tabs-separator-alternate 'right)) 870 | (centaur-tabs-separator-memoize (centaur-tabs-separator-bar 'left)) 871 | (centaur-tabs-separator-memoize (centaur-tabs-separator-bar 'right)) 872 | (centaur-tabs-separator-memoize (centaur-tabs-separator-box 'left)) 873 | (centaur-tabs-separator-memoize (centaur-tabs-separator-box 'right)) 874 | (centaur-tabs-separator-memoize (centaur-tabs-separator-chamfer 'left)) 875 | (centaur-tabs-separator-memoize (centaur-tabs-separator-chamfer 'right)) 876 | (centaur-tabs-separator-memoize (centaur-tabs-separator-rounded 'left)) 877 | (centaur-tabs-separator-memoize (centaur-tabs-separator-rounded 'right)) 878 | (centaur-tabs-separator-memoize (centaur-tabs-separator-slant 'left)) 879 | (centaur-tabs-separator-memoize (centaur-tabs-separator-slant 'right)) 880 | (centaur-tabs-separator-memoize (centaur-tabs-separator-wave 'left)) 881 | (centaur-tabs-separator-memoize (centaur-tabs-separator-wave 'right)) 882 | (centaur-tabs-separator-memoize (centaur-tabs-separator-zigzag 'left)) 883 | (centaur-tabs-separator-memoize (centaur-tabs-separator-zigzag 'right)) 884 | 885 | (defun centaur-tabs-select-separator-style (tab-style) 886 | "Set the separator style to TAB-STYLE." 887 | (let* ((theme (or (car custom-enabled-themes) "default")) 888 | (name (intern (format "centaur-tabs--%s-%s-face" theme tab-style))) 889 | (face (copy-face 'centaur-tabs-default name))) 890 | (setq centaur-tabs-style-left 891 | (funcall (intern (format "powerline-%s-right" tab-style)) 892 | face nil centaur-tabs-height)) 893 | (setq centaur-tabs-style-right 894 | (funcall (intern (format "powerline-%s-left" tab-style)) 895 | nil face centaur-tabs-height)))) 896 | 897 | (provide 'centaur-tabs-elements) 898 | ;;; centaur-tabs-elements.el ends here 899 | -------------------------------------------------------------------------------- /centaur-tabs-functions.el: -------------------------------------------------------------------------------- 1 | ;;; centaur-tabs-functions.el --- centaur-tabs logic components -*- lexical-binding: t; -*- 2 | 3 | ;; Copyright (C) 2019-2024 Emmanuel Bustos 4 | ;; Copyright (C) 2024 Jen-Chieh Shen 5 | 6 | ;; This file is not part of GNU Emacs. 7 | 8 | ;; This program is free software; you can redistribute it and/or 9 | ;; modify it under the terms of the GNU General Public License as 10 | ;; published by the Free Software Foundation; either version 2, or 11 | ;; (at your option) any later version. 12 | ;; 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | ;; General Public License for more details. 17 | ;; 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program; see the file COPYING. If not, write to 20 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 21 | ;; Floor, Boston, MA 02110-1301, USA. 22 | 23 | ;;; Commentary: 24 | ;; 25 | ;; This file contains functions that control the logic of centaur-tabs 26 | ;; 27 | 28 | ;;; Code: 29 | 30 | (require 'cl-lib) 31 | (require 'seq) 32 | (require 'centaur-tabs-elements) 33 | 34 | ;; Compiler pacifier 35 | (declare-function vterm "ext:vterm.el") 36 | 37 | (declare-function centaur-tabs-move-current-tab-to-right "nerd-icons.el") 38 | (declare-function centaur-tabs-move-current-tab-to-left "nerd-icons.el") 39 | 40 | (defvar centaur-tabs--buffer-show-groups) 41 | (defvar centaur-tabs-ace-jump-active) 42 | 43 | (declare-function centaur-tabs-mode "centaur-tabs.el") 44 | 45 | ;; 46 | ;;; Customs 47 | 48 | (defcustom centaur-tabs-cycle-scope nil 49 | "*Specify the scope of cyclic navigation through tabs. 50 | The following scopes are possible: 51 | 52 | - `tabs' 53 | Navigate through visible tabs only. 54 | - `groups' 55 | Navigate through tab groups only. 56 | - default 57 | Navigate through visible tabs, then through tab groups." 58 | :group 'centaur-tabs 59 | :type '(choice :tag "Cycle through..." 60 | (const :tag "Visible Tabs Only" tabs) 61 | (const :tag "Tab Groups Only" groups) 62 | (const :tag "Visible Tabs then Tab Groups" nil))) 63 | 64 | (defcustom centaur-tabs-auto-scroll-flag t 65 | "*Non-nil means to automatically scroll the tab bar. 66 | That is, when a tab is selected outside of the tab bar visible area, 67 | the tab bar is scrolled horizontally so the selected tab becomes 68 | visible." 69 | :group 'centaur-tabs 70 | :type 'boolean) 71 | 72 | (defcustom centaur-tabs-common-group-name "Common" 73 | "If the current buffer does not belong to any project the group name uses the 74 | name of this variable." 75 | :group 'centaur-tabs 76 | :type 'string) 77 | 78 | (defcustom centaur-tabs-label-fixed-length 0 79 | "Fixed length of label. Set to 0 if dynamic." 80 | :group 'centaur-tabs 81 | :type 'integer) 82 | 83 | (defcustom centaur-tabs-hide-tabs-hooks 84 | '(magit-status-mode-hook 85 | magit-popup-mode-hook 86 | reb-mode-hook 87 | completion-list-mode-hook) 88 | "Set hooks for buffers in which it isn't desired to have tabs." 89 | :type '(repeat symbol) 90 | :group 'centaur-tabs) 91 | 92 | (defcustom centaur-tabs-excluded-prefixes 93 | '("*epc" 94 | "*helm" 95 | "*Helm" 96 | " *which" 97 | "*Compile-Log*" 98 | "*Choices" 99 | "*Process" 100 | "*Calc" 101 | "*lsp" 102 | "*LSP" 103 | "*company" 104 | "*Flycheck" 105 | "*Ediff" 106 | "*ediff" 107 | "*tramp" 108 | " *Mini" 109 | "*straight" 110 | " *temp") 111 | "List of prefixes that indicates which buffers should not be included as tabs. 112 | Buffers that have names that start with any of these strings will be ignored." 113 | :type '(repeat string) 114 | :group 'centaur-tabs) 115 | 116 | (defvar centaur-tabs-hide-predicate #'ignore 117 | "Predicate function to hide the entire tab line. 118 | Ths tab line will hide if this function returns t.") 119 | 120 | (defvar centaur-tabs-hide-tab-function 'centaur-tabs-hide-tab 121 | "Function to hide tabs. 122 | This function filters tabs. The tab will hide if this function returns t.") 123 | 124 | (defvar centaur-tabs-current-tabset-function nil 125 | "Function called with no argument to obtain the current tab set. 126 | This is the tab set displayed on the tab bar.") 127 | 128 | (defvar centaur-tabs-tab-label-function nil 129 | "Function that obtains a tab label displayed on the tab bar. 130 | The function is passed a tab and should return a string.") 131 | 132 | (defvar centaur-tabs-select-tab-function nil 133 | "Function that selects a tab. 134 | The function is passed a tab, and makes it the 135 | selected tab.") 136 | 137 | (defvar centaur-tabs-buffer-list-function 'centaur-tabs-buffer-list 138 | "Function that returns the list of buffers to show in the tab line. 139 | That function is called with no arguments and must return a list of 140 | buffers.") 141 | 142 | (defvar centaur-tabs-buffer-groups-function 'centaur-tabs-buffer-groups 143 | "Function that gives the group names the current buffer belongs to. 144 | It must return a list of group names, or nil if the buffer has no 145 | group. Notice that it is better that a buffer belongs to one group.") 146 | 147 | (defvar centaur-tabs-custom-buffer-groups nil 148 | "Function that runs before any grouping logic inside the function 149 | `centaur-tabs-buffer-groups-function'.") 150 | 151 | (defvar centaur-tabs-adjust-buffer-order-function 'centaur-tabs-adjust-buffer-order 152 | "Function to adjust buffer order after switch tab. 153 | Default is `centaur-tabs-adjust-buffer-order', you can write your own rule.") 154 | 155 | (defcustom centaur-tabs-adjust-buffer-order nil 156 | "Set automatic buffer ordering for buffer changing commands. 157 | The ordering is appliet for non click or tab motion commands. 158 | There are four options: 159 | 1 - nil: No ordering applied 160 | 2 - t: Move the currently selected tab to the side (right or left) of the last 161 | visited tab. 162 | 3 - left: Move the currently selected tab to left of the last visited tab. 163 | 4 - right: Move the currently selected tab to right of the last visited tab." 164 | :group 'centaur-tabs 165 | :type '(choice :tag "Automatic buffer reordering..." 166 | (const :tag "Do not adjust buffer order." nil) 167 | (const :tag "When the currently selected tab(A) is at the right of the last visited 168 | tab(B), move A to the right of B. When the currently selected tab(A) is at the left of the last visited 169 | tab(B), move A to the left of B" t) 170 | (const :tag "Move the currently selected tab to the left of the the last visited tab." left) 171 | (const :tag "Move the currently selected tab to the right of the the last visited tab." right))) 172 | 173 | (defcustom centaur-tabs-enable-key-bindings nil 174 | "Enable a selection of default key bindings for centaur-tabs." 175 | :group 'centaur-tabs 176 | :type 'boolean) 177 | 178 | (defun centaur-tabs-headline-match () 179 | "Make headline use centaur-tabs-default-face." 180 | (set-face-attribute 181 | centaur-tabs-display-line nil 182 | :background (face-background 'centaur-tabs-unselected nil 'default) 183 | :box nil :overline nil :underline nil)) 184 | 185 | ;; Change the font and height for all tab faces 186 | (defun centaur-tabs-change-fonts (family height) 187 | "Change the fonts of all the tabs. 188 | FAMILY is the font family and HEIGHT is the font height." 189 | (dolist (centaur-face '(centaur-tabs-selected 190 | centaur-tabs-selected-modified 191 | centaur-tabs-unselected 192 | centaur-tabs-unselected-modified)) 193 | (set-face-attribute centaur-face nil :family family :height height))) 194 | 195 | ;;; Tabs Redisplay function 196 | ;; 197 | (eval-and-compile 198 | (defalias 'centaur-tabs-display-update 199 | (if (fboundp 'force-window-update) 200 | #'(lambda () (force-window-update (selected-window))) 201 | 'force-mode-line-update))) 202 | 203 | (defun centaur-tabs-2str (obj) 204 | "Convert OBJ to string." 205 | (format "%s" obj)) 206 | 207 | ;;; Name truncation 208 | ;; 209 | ;; Copied from s.el 210 | (defun centaur-tabs-truncate-string (len s &optional ellipsis) 211 | "If S is longer than LEN, cut it down and add ELLIPSIS to the end. 212 | 213 | The resulting string, including ellipsis, will be LEN characters 214 | long. 215 | 216 | When not specified, ELLIPSIS defaults to ‘...’." 217 | (declare (pure t) (side-effect-free t)) 218 | (unless ellipsis 219 | (setq ellipsis (if (char-displayable-p ?…) "…" "..."))) 220 | (if (> (length s) len) 221 | (format "%s%s" (substring s 0 (- len (length ellipsis))) ellipsis) 222 | (concat s (make-string (- len (length s)) ? )))) 223 | 224 | ;; 225 | ;;; Keymaps 226 | (defvar centaur-tabs-prefix-key ["C-c t"] 227 | "The common prefix key used in Centaur-Tabs mode.") 228 | 229 | (defvar centaur-tabs-prefix-map 230 | (let ((km (make-sparse-keymap))) 231 | (define-key km (kbd "") 'centaur-tabs-backward) 232 | (define-key km (kbd "") 'centaur-tabs-forward) 233 | (define-key km (kbd "") 'centaur-tabs-backward-group) 234 | (define-key km (kbd "") 'centaur-tabs-forward-group) 235 | (define-key km (kbd "f10") 'centaur-tabs-local-mode) 236 | (define-key km (kbd "C-5") 'centaur-tabs-extract-window-to-new-frame) 237 | (define-key km (kbd "a") 'centaur-tabs-ace-jump) 238 | (define-key km (kbd "s") 'centaur-tabs-counsel-switch-group) 239 | (define-key km (kbd "p") 'centaur-tabs-group-by-projectile-project) 240 | (define-key km (kbd "g") 'centaur-tabs-group-buffer-groups) 241 | (define-key km (kbd "k") 'centaur-tabs-kill-all-buffers-in-current-group) 242 | (define-key km (kbd "o") 'centaur-tabs-kill-other-buffers-in-current-group) 243 | (define-key km (kbd "d") 'centaur-tabs-open-directory-in-external-application) 244 | km) 245 | "The key bindings provided in Centaur-Tabs mode.") 246 | 247 | (defvar centaur-tabs-mode-map 248 | (let ((map (make-sparse-keymap))) 249 | ;; Optional keybord bindings 250 | (when centaur-tabs-enable-key-bindings 251 | (define-key map centaur-tabs-prefix-key centaur-tabs-prefix-map)) 252 | ;; Use mouse wheel to switch between buffers of same group 253 | (define-key map (vector centaur-tabs-display-line 'mouse-5 ) 'centaur-tabs-forward ) 254 | (define-key map (vector centaur-tabs-display-line 'mouse-4 ) 'centaur-tabs-backward) 255 | (define-key map (vector centaur-tabs-display-line 'wheel-down) 'centaur-tabs-forward ) 256 | (define-key map (vector centaur-tabs-display-line 'wheel-up ) 'centaur-tabs-backward) 257 | ;; Use right click to show the rest of groups 258 | (define-key map (vector centaur-tabs-display-line 'mouse-3) 'centaur-tabs--tab-menu ) 259 | map) 260 | "Keymap to use in Centaur-Tabs mode.") 261 | 262 | (defvar centaur-tabs-close-map 263 | (let ((map (make-sparse-keymap))) 264 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs-do-close) 265 | (define-key map (vector centaur-tabs-display-line 'mouse-2) 'centaur-tabs-do-close) 266 | map) 267 | "Keymap used for setting mouse events for close button.") 268 | 269 | (defvar centaur-tabs-backward-tab-map 270 | (let ((map (make-sparse-keymap))) 271 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs-backward--button) 272 | (define-key map (vector centaur-tabs-display-line 'mouse-3) 'centaur-tabs--groups-menu) 273 | (define-key map (vector centaur-tabs-display-line 'C-mouse-1) 'centaur-tabs-move-current-tab-to-left--button) 274 | map) 275 | "Keymap used for setting mouse events for backward tab button.") 276 | 277 | (defvar centaur-tabs-forward-tab-map 278 | (let ((map (make-sparse-keymap))) 279 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs-forward--button) 280 | (define-key map (vector centaur-tabs-display-line 'mouse-3) 'centaur-tabs--groups-menu) 281 | (define-key map (vector centaur-tabs-display-line 'C-mouse-1) 'centaur-tabs-move-current-tab-to-right--button) 282 | map) 283 | "Keymap used for setting mouse events for forward tab button.") 284 | 285 | (defvar centaur-tabs-down-tab-map 286 | (let ((map (make-sparse-keymap))) 287 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs--groups-menu) 288 | (define-key map (vector centaur-tabs-display-line 'mouse-3) 'centaur-tabs--groups-menu) 289 | map) 290 | "Keymap used for setting mouse events for down tab button.") 291 | 292 | (defvar centaur-tabs-default-map 293 | (let ((map (make-sparse-keymap))) 294 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs-do-select) 295 | (define-key map (vector centaur-tabs-display-line 'mouse-2) 'centaur-tabs-do-close) 296 | map) 297 | "Keymap used for setting mouse events for a tab.") 298 | 299 | (defvar centaur-tabs-new-tab-map 300 | (let ((map (make-sparse-keymap))) 301 | (define-key map (vector centaur-tabs-display-line 'mouse-1) 'centaur-tabs-new-tab--button) 302 | map) 303 | "Keymap used for setting mouse events for new tab button.") 304 | 305 | ;; 306 | ;;; Tab and tab sets 307 | 308 | (defsubst centaur-tabs-make-tab (object tabset) 309 | "Return a new tab with value OBJECT. 310 | TABSET is the tab set the tab belongs to." 311 | (cons object tabset)) 312 | 313 | (defsubst centaur-tabs-tab-value (tab) 314 | "Return the value of tab TAB." 315 | (car tab)) 316 | 317 | (defsubst centaur-tabs-tab-tabset (tab) 318 | "Return the tab set TAB belongs to." 319 | (cdr tab)) 320 | 321 | (defvar centaur-tabs-tabsets nil 322 | "The tab sets store.") 323 | 324 | (defvar centaur-tabs-tabsets-tabset nil 325 | "The special tab set of existing tab sets.") 326 | 327 | (defvar centaur-tabs-current-tabset nil 328 | "The tab set currently displayed on the tab bar.") 329 | (make-variable-buffer-local 'centaur-tabs-current-tabset) 330 | 331 | (defvar centaur-tabs-init-hook nil 332 | "Hook run after tab bar data has been initialized. 333 | You should use this hook to initialize dependent data.") 334 | 335 | (defvar centaur-tabs-display-hash (make-hash-table :test 'equal) 336 | "Display format cache.") 337 | 338 | (defsubst centaur-tabs-init-tabsets-store () 339 | "Initialize the tab set store." 340 | (setq centaur-tabs-tabsets (make-vector 31 0) 341 | centaur-tabs-tabsets-tabset (make-symbol "centaur-tabs-tabsets-tabset")) 342 | (put centaur-tabs-tabsets-tabset 'start 0) 343 | (run-hooks 'centaur-tabs-init-hook)) 344 | 345 | (defvar centaur-tabs-quit-hook nil 346 | "Hook run after tab bar data has been freed. 347 | You should use this hook to reset dependent data.") 348 | 349 | (defsubst centaur-tabs-free-tabsets-store () 350 | "Free the tab set store." 351 | (setq centaur-tabs-tabsets nil 352 | centaur-tabs-tabsets-tabset nil) 353 | (run-hooks 'centaur-tabs-quit-hook)) 354 | 355 | ;; Define an "hygienic" function free of side effect between its local 356 | ;; variables and those of the callee. 357 | (eval-and-compile 358 | (defalias 'centaur-tabs-map-tabsets 359 | (let ((function (make-symbol "function")) 360 | (result (make-symbol "result")) 361 | (tabset (make-symbol "tabset"))) 362 | `(lambda (,function) 363 | "Apply FUNCTION to each tab set, and make a list of the results. 364 | The result is a list just as long as the number of existing tab sets." 365 | (let (,result) 366 | (mapatoms 367 | #'(lambda (,tabset) 368 | (push (funcall ,function ,tabset) ,result)) 369 | centaur-tabs-tabsets) 370 | ,result))))) 371 | 372 | (defun centaur-tabs-make-tabset (name &rest objects) 373 | "Make a new tab set whose name is the string NAME. 374 | It is initialized with tabs build from the list of OBJECTS." 375 | (when name ; some buffers don't have a tabset (e.g. org-agenda) 376 | (let* ((tabset (intern name centaur-tabs-tabsets)) 377 | (tabs (mapcar #'(lambda (object) 378 | (centaur-tabs-make-tab object tabset)) 379 | objects))) 380 | (set tabset tabs) 381 | (centaur-tabs-put-cache tabset 'select (car tabs)) 382 | (put tabset 'start 0) 383 | tabset))) 384 | 385 | (defsubst centaur-tabs-get-tabset (name) 386 | "Return the tab set whose name is the string NAME. 387 | Return nil if not found." 388 | (intern-soft name centaur-tabs-tabsets)) 389 | 390 | (defsubst centaur-tabs-delete-tabset (tabset) 391 | "Delete the tab set TABSET. 392 | That is, remove it from the tab sets store." 393 | (unintern tabset centaur-tabs-tabsets)) 394 | 395 | (defsubst centaur-tabs-tabs (tabset) 396 | "Return the list of tabs in TABSET." 397 | (symbol-value tabset)) 398 | 399 | (defsubst centaur-tabs-tab-values (tabset) 400 | "Return the list of tab values in TABSET." 401 | (mapcar 'centaur-tabs-tab-value (centaur-tabs-tabs tabset))) 402 | 403 | (defun centaur-tabs-get-cache (cache key) 404 | "Return the cached value of KEY in CACHE." 405 | (when-let* ((cache (format "%s" cache)) 406 | (cached-hash (gethash cache centaur-tabs-display-hash)) 407 | ((hash-table-p cached-hash))) 408 | (gethash key cached-hash nil))) 409 | 410 | (defun centaur-tabs-put-cache (cache key value) 411 | "Set the cached value of KEY in CACHE to VALUE." 412 | (let* ((cache (format "%s" cache)) 413 | (cached-hash (gethash cache centaur-tabs-display-hash)) 414 | (hash (if (hash-table-p cached-hash) cached-hash (make-hash-table)))) 415 | (puthash key value hash) 416 | (puthash cache hash centaur-tabs-display-hash)) 417 | value) 418 | 419 | (defsubst centaur-tabs-get-tab (object tabset) 420 | "Search for a tab with value OBJECT in TABSET. 421 | Return the tab found, or nil if not found." 422 | (assoc object (centaur-tabs-tabs tabset))) 423 | 424 | (defsubst centaur-tabs-member (tab tabset) 425 | "Return non-nil if TAB is in TABSET." 426 | (or (eq (centaur-tabs-tab-tabset tab) tabset) 427 | (memq tab (centaur-tabs-tabs tabset)))) 428 | 429 | (defsubst centaur-tabs-template (tabset) 430 | "Return the cached visual representation of TABSET. 431 | That is, a `centaur-tabs-display-line-format' template, or nil if 432 | the cache is empty." 433 | (centaur-tabs-get-cache tabset 'template)) 434 | 435 | (defsubst centaur-tabs-set-template (tabset template) 436 | "Set the cached visual representation of TABSET to TEMPLATE. 437 | TEMPLATE must be a valid `centaur-tabs-display-line-format' template, 438 | or nil to cleanup the cache." 439 | (centaur-tabs-put-cache tabset 'template template)) 440 | 441 | (defsubst centaur-tabs-selected-tab (tabset) 442 | "Return the tab selected in TABSET." 443 | (centaur-tabs-get-cache tabset 'select)) 444 | 445 | (defsubst centaur-tabs-selected-value (tabset) 446 | "Return the value of the tab selected in TABSET." 447 | (centaur-tabs-tab-value (centaur-tabs-selected-tab tabset))) 448 | 449 | (defsubst centaur-tabs-selected-p (tab tabset) 450 | "Return non-nil if TAB is the selected tab in TABSET." 451 | (eq tab (centaur-tabs-selected-tab tabset))) 452 | 453 | (defvar centaur-tabs--track-selected nil) 454 | 455 | (defsubst centaur-tabs-select-tab (tab tabset) 456 | "Make TAB the selected tab in TABSET. 457 | Does nothing if TAB is not found in TABSET. 458 | Return TAB if selected, nil if not." 459 | (when (centaur-tabs-member tab tabset) 460 | (unless (centaur-tabs-selected-p tab tabset) 461 | (centaur-tabs-set-template tabset nil) 462 | (setq centaur-tabs--track-selected centaur-tabs-auto-scroll-flag)) 463 | (centaur-tabs-put-cache tabset 'select tab))) 464 | 465 | (defsubst centaur-tabs-select-tab-value (object tabset) 466 | "Make the tab with value OBJECT, the selected tab in TABSET. 467 | Does nothing if a tab with value OBJECT is not found in TABSET. 468 | Return the tab selected, or nil if nothing was selected." 469 | (centaur-tabs-select-tab (centaur-tabs-get-tab object tabset) tabset)) 470 | 471 | (defsubst centaur-tabs-start (tabset) 472 | "Return the index of the first visible tab in TABSET." 473 | (get tabset 'start)) 474 | 475 | (defsubst centaur-tabs-view (tabset) 476 | "Return the list of visible tabs in TABSET. 477 | That is, the sub-list of tabs starting at the first visible one." 478 | (nthcdr (centaur-tabs-start tabset) (centaur-tabs-tabs tabset))) 479 | 480 | (defun centaur-tabs-add-tab (tabset object) 481 | "Check if OBJECT tab is already open in TABSET. 482 | Otherwise insert it." 483 | (let ((tabs (centaur-tabs-tabs tabset))) 484 | (if (centaur-tabs-get-tab object tabset) 485 | tabs 486 | (let* ((tab (centaur-tabs-make-tab object tabset)) 487 | (selected (centaur-tabs-selected-tab tabset)) 488 | (selected-index (cl-position (car selected) (mapcar 'car tabs)))) 489 | (centaur-tabs-set-template tabset nil) 490 | (set tabset (centaur-tabs-insert-at tabs selected-index tab)))))) 491 | 492 | (defun centaur-tabs-insert-at (list index insert-element) 493 | "Insert INSERT-ELEMENT in LIST at index INDEX." 494 | (let ((counter 0) 495 | result) 496 | (dolist (element list) 497 | (if (equal counter index) 498 | (setq result (append result (list element insert-element))) 499 | (setq result (append result (list element)))) 500 | (setq counter (+ 1 counter))) 501 | result)) 502 | 503 | (defun centaur-tabs-delete-tab (tab) 504 | "Remove TAB from its tab set." 505 | (let* ((tabset (centaur-tabs-tab-tabset tab)) 506 | (tabs (centaur-tabs-tabs tabset)) 507 | (sel (eq tab (centaur-tabs-selected-tab tabset))) 508 | (next (and sel (cdr (memq tab tabs))))) 509 | (centaur-tabs-set-template tabset nil) 510 | (setq tabs (delq tab tabs)) 511 | ;; When the selected tab is deleted, select the next one, if 512 | ;; available, or the last one otherwise. 513 | (and sel (centaur-tabs-select-tab (car (or next (last tabs))) tabset)) 514 | (set tabset tabs))) 515 | 516 | (defun centaur-tabs-scroll (tabset count) 517 | "Scroll the visible tabs in TABSET of COUNT units. 518 | If COUNT is positive move the view on right. If COUNT is negative, 519 | move the view on left." 520 | (let ((start (min (max 0 (+ (centaur-tabs-start tabset) count)) 521 | (1- (length (centaur-tabs-tabs tabset)))))) 522 | (when (/= start (centaur-tabs-start tabset)) 523 | (centaur-tabs-set-template tabset nil) 524 | (put tabset 'start start)))) 525 | 526 | (defun centaur-tabs-tab-next (tabset tab &optional before) 527 | "Search in TABSET for the tab after TAB. 528 | If optional argument BEFORE is non-nil, search for the tab before 529 | TAB. Return the tab found, or nil otherwise." 530 | (let* (last (tabs (centaur-tabs-tabs tabset))) 531 | (while (and tabs (not (eq tab (car tabs)))) 532 | (setq last (car tabs) 533 | tabs (cdr tabs))) 534 | (and tabs (if before last (nth 1 tabs))))) 535 | 536 | (defun centaur-tabs-current-tabset (&optional update) 537 | "Return the tab set currently displayed on the tab bar. 538 | If optional argument UPDATE is non-nil, call the user defined function 539 | `centaur-tabs-current-tabset-function' to obtain it. Otherwise return the 540 | current cached copy." 541 | (and update centaur-tabs-current-tabset-function 542 | (setq centaur-tabs-current-tabset 543 | (funcall centaur-tabs-current-tabset-function))) 544 | centaur-tabs-current-tabset) 545 | 546 | (defun centaur-tabs-get-tabsets-tabset () 547 | "Return the tab set of selected tabs in existing tabsets." 548 | (set centaur-tabs-tabsets-tabset (centaur-tabs-map-tabsets 'centaur-tabs-selected-tab)) 549 | (centaur-tabs-scroll centaur-tabs-tabsets-tabset 0) 550 | (centaur-tabs-set-template centaur-tabs-tabsets-tabset nil) 551 | centaur-tabs-tabsets-tabset) 552 | 553 | (defun centaur-tabs-after-focus (&rest _) 554 | "Focus hook." 555 | (when (frame-focus-state) 556 | (ignore-errors (centaur-tabs-buffer-update-groups)) 557 | (ignore-errors (centaur-tabs-display-update)))) 558 | 559 | (defun centaur-tabs-on-window-buffer-change (frame &rest _) 560 | "Function to be run after window buffer is changed in FRAME." 561 | (unless (frame-parent frame) 562 | (ignore-errors (centaur-tabs-buffer-update-groups)))) 563 | 564 | ;; Functions for modification hooks and advices 565 | (defun centaur-tabs-on-saving-buffer () 566 | "Function to be run after the buffer is saved." 567 | (centaur-tabs-set-template centaur-tabs-current-tabset nil) 568 | (centaur-tabs-display-update)) 569 | 570 | (defun centaur-tabs-on-modifying-buffer (&rest _) 571 | "Function to be run after the buffer is first changed." 572 | (set-buffer-modified-p (buffer-modified-p)) 573 | (centaur-tabs-set-template centaur-tabs-current-tabset nil) 574 | (centaur-tabs-display-update)) 575 | 576 | (defun centaur-tabs--after-load-theme (&rest _) 577 | "Function to be run after the theme changed." 578 | (dolist (buffer (and centaur-tabs-buffer-list-function 579 | (funcall centaur-tabs-buffer-list-function))) 580 | (with-current-buffer buffer 581 | (centaur-tabs-set-template centaur-tabs-current-tabset nil) 582 | (setq centaur-tabs-style-right nil 583 | centaur-tabs-style-left nil))) 584 | (centaur-tabs-display-update)) 585 | 586 | ;; 587 | ;;; Events and event functions 588 | 589 | (defun centaur-tabs-buffer-close-tab (tab) 590 | "Function for closing TAB." 591 | (let ((buffer (centaur-tabs-tab-value tab))) 592 | (kill-buffer buffer) 593 | (centaur-tabs-buffer-update-groups) 594 | (centaur-tabs-display-update))) 595 | 596 | (defun centaur-tabs-get-tab-from-event (event) 597 | "Given a mouse EVENT, extract the tab at the mouse point." 598 | (let ((pos (posn-string (event-start event)))) 599 | (get-text-property (cdr pos) 'centaur-tabs-tab (car pos)))) 600 | 601 | (defun centaur-tabs-do-select (event) 602 | "Given a mouse EVENT, select the tab at the mouse point." 603 | (interactive "e") 604 | (select-window (posn-window (event-start event))) 605 | (centaur-tabs-buffer-select-tab `,(centaur-tabs-get-tab-from-event event))) 606 | 607 | (defun centaur-tabs-do-close (event) 608 | "Given a mouse EVENT, close the tab at the mouse point." 609 | (interactive "e") 610 | (let ((window (posn-window (event-start event)))) 611 | (with-selected-window window 612 | (select-window window) 613 | (let ((foreground-buffer-name (buffer-name))) 614 | (centaur-tabs-buffer-select-tab `,(centaur-tabs-get-tab-from-event event)) 615 | 616 | (let* ((buffer (window-buffer window)) 617 | (target-buffer-name (buffer-name)) 618 | (same-target-check (string-equal foreground-buffer-name target-buffer-name)) 619 | (window-num (- (length (get-buffer-window-list buffer)) 620 | (if same-target-check 0 1)))) 621 | (if (> window-num 1) 622 | (delete-window window) 623 | (centaur-tabs-buffer-close-tab `,(centaur-tabs-get-tab-from-event event)))))))) 624 | 625 | (defun centaur-tabs-backward--button (event) 626 | "Same as centaur-tabs-backward, but changing window to EVENT source." 627 | (interactive "e") 628 | (select-window (posn-window (event-start event))) 629 | (centaur-tabs-backward)) 630 | 631 | (defun centaur-tabs-forward--button (event) 632 | "Same as centaur-tabs-forward, but changing window to EVENT source." 633 | (interactive "e") 634 | (select-window (posn-window (event-start event))) 635 | (centaur-tabs-forward)) 636 | 637 | (defun centaur-tabs-new-tab--button (event) 638 | "Same as centaur-tabs--create-new-tab, but changing window to EVENT source." 639 | (interactive "e") 640 | (select-window (posn-window (event-start event))) 641 | (centaur-tabs--create-new-tab)) 642 | 643 | (defun centaur-tabs-move-current-tab-to-left--button (evt) 644 | "Same as centaur-tabs-move-current-tab-to-left, but ensuring the tab will 645 | remain visible. The active window will the the EVT source." 646 | (interactive "e") 647 | (centaur-tabs-move-current-tab-to-left) 648 | (centaur-tabs--button-ensure-selected-tab-is-visible evt)) 649 | 650 | (defun centaur-tabs-move-current-tab-to-right--button (evt) 651 | "Same as centaur-tabs-move-current-tab-to-right, but ensuring the tab will 652 | remain visible. The active window will the the EVT source." 653 | (interactive "e") 654 | (centaur-tabs-move-current-tab-to-right) 655 | (centaur-tabs--button-ensure-selected-tab-is-visible evt)) 656 | 657 | (defun centaur-tabs--button-ensure-selected-tab-is-visible (evt) 658 | "This is a nasty trick to make the current tab visible, since 659 | `centaur-tabs--track-selected' or `centaur-tabs-auto-scroll-flag' seems not 660 | to work. EVT is used to change the active window." 661 | ;; This works if the tab has not reached the last position 662 | (centaur-tabs-forward--button evt) 663 | (centaur-tabs-backward--button evt) 664 | ;; Just in case the tab has the tab reached the last position 665 | (centaur-tabs-backward--button evt) 666 | (centaur-tabs-forward--button evt)) 667 | 668 | (defun centaur-tabs-refill-tabs () 669 | "Refill current tab line." 670 | (centaur-tabs-buffer-update-groups) 671 | (force-window-update (selected-window)) 672 | (centaur-tabs--button-ensure-selected-tab-is-visible nil)) 673 | 674 | ;; 675 | ;;; Tabs display 676 | 677 | (defsubst centaur-tabs-line-tab (tab) 678 | "Return the display representation of tab TAB. 679 | That is, a propertized string used as an `centaur-tabs-display-line-format' 680 | template element. 681 | Call `centaur-tabs-tab-label-function' to obtain a label for TAB." 682 | (let* ((buf (centaur-tabs-tab-value tab)) 683 | (buf-file-name (buffer-file-name buf)) 684 | (selected-p (centaur-tabs-selected-p tab (centaur-tabs-current-tabset))) 685 | (not-read-only-p (with-current-buffer buf (not buffer-read-only))) 686 | (modified-p (and not-read-only-p (buffer-modified-p buf))) 687 | (use-mod-mark-p (and centaur-tabs-set-modified-marker modified-p)) 688 | (mod-mark-face (if selected-p 689 | 'centaur-tabs-modified-marker-selected 690 | 'centaur-tabs-modified-marker-unselected)) 691 | (face (if selected-p 692 | (if modified-p 693 | 'centaur-tabs-selected-modified 694 | 'centaur-tabs-selected) 695 | (if modified-p 696 | 'centaur-tabs-unselected-modified 697 | 'centaur-tabs-unselected))) 698 | (bar (if (and selected-p (eq (if (display-graphic-p) centaur-tabs-set-bar) 'left)) 699 | (propertize 700 | centaur-tabs-active-bar 701 | 'centaur-tabs-tab tab 702 | 'pointer centaur-tabs-mouse-pointer 703 | 'local-map centaur-tabs-default-map) 704 | "")) 705 | (icon (if (and centaur-tabs-set-icons 706 | (not centaur-tabs--buffer-show-groups)) 707 | (propertize 708 | (centaur-tabs-icon tab face selected-p) 709 | 'centaur-tabs-tab tab 710 | 'pointer centaur-tabs-mouse-pointer 711 | 'help-echo (with-current-buffer buf (format-mode-line mode-name)) 712 | 'local-map centaur-tabs-default-map) 713 | ""))) 714 | (when (or (not centaur-tabs-style-left) 715 | (not centaur-tabs-style-right)) 716 | (centaur-tabs-select-separator-style centaur-tabs-style)) 717 | (concat (centaur-tabs-separator-render centaur-tabs-style-left face) 718 | bar 719 | 720 | ;; left margin 721 | (when centaur-tabs-left-edge-margin 722 | (propertize centaur-tabs-left-edge-margin 723 | 'face face 724 | 'centaur-tabs-tab tab 725 | 'pointer centaur-tabs-mouse-pointer 726 | 'local-map centaur-tabs-default-map)) 727 | 728 | ;; left close button 729 | (when centaur-tabs-set-left-close-button 730 | (propertize centaur-tabs-close-button 731 | 'face (if selected-p 732 | 'centaur-tabs-close-selected 733 | 'centaur-tabs-close-unselected) 734 | 'pointer centaur-tabs-mouse-pointer 735 | 'help-echo "Close buffer" 736 | 'centaur-tabs-tab tab 737 | 'mouse-face 'centaur-tabs-close-mouse-face 738 | 'local-map centaur-tabs-close-map)) 739 | 740 | ;; icon 741 | (if (= (length icon) 0) "" 742 | (concat (propertize centaur-tabs-icons-prefix 743 | 'face face 744 | 'centaur-tabs-tab tab 745 | 'pointer centaur-tabs-mouse-pointer 746 | 'local-map centaur-tabs-default-map) 747 | icon)) 748 | 749 | ;; tab name 750 | (propertize (concat 751 | (if centaur-tabs-tab-label-function 752 | (funcall centaur-tabs-tab-label-function tab) 753 | (buffer-name buf)) 754 | " ") 755 | 'centaur-tabs-tab tab 756 | 'face face 757 | 'mouse-face 'centaur-tabs-name-mouse-face 758 | 'pointer centaur-tabs-mouse-pointer 759 | 'help-echo buf-file-name 760 | 'local-map centaur-tabs-default-map) 761 | 762 | ;; tab identifier 763 | (when centaur-tabs-show-jump-identifier 764 | (when (or (eq centaur-tabs-show-jump-identifier 'always) 765 | centaur-tabs-ace-jump-active) 766 | (when-let* ((position (nth (cl-position tab (centaur-tabs-view (centaur-tabs-current-tabset t))) 767 | centaur-tabs-ace-jump-keys))) 768 | (propertize 769 | (format "%c" position) 770 | 'centaur-tabs-tab tab 771 | 'face (if selected-p 772 | 'centaur-tabs-jump-identifier-selected 773 | 'centaur-tabs-jump-identifier-unselected) 774 | 'pointer centaur-tabs-mouse-pointer 775 | 'help-echo buf-file-name 776 | 'local-map centaur-tabs-default-map)))) 777 | 778 | ;; close button and/or modified marker 779 | (unless centaur-tabs-ace-jump-active 780 | (if centaur-tabs-set-close-button 781 | (propertize (if use-mod-mark-p 782 | centaur-tabs-modified-marker 783 | centaur-tabs-close-button) 784 | 'face (if use-mod-mark-p 785 | mod-mark-face 786 | (if selected-p 787 | 'centaur-tabs-close-selected 788 | 'centaur-tabs-close-unselected)) 789 | 'pointer centaur-tabs-mouse-pointer 790 | 'help-echo "Close buffer" 791 | 'centaur-tabs-tab tab 792 | 'mouse-face 'centaur-tabs-close-mouse-face 793 | 'local-map centaur-tabs-close-map) 794 | (if (and centaur-tabs-set-modified-marker modified-p) 795 | (propertize centaur-tabs-modified-marker 796 | 'face mod-mark-face 797 | 'pointer centaur-tabs-mouse-pointer 798 | 'centaur-tabs-tab tab 799 | 'help-echo buf-file-name 800 | 'local-map centaur-tabs-default-map) 801 | "" ))) 802 | 803 | ;; right margin 804 | (when centaur-tabs-right-edge-margin 805 | (propertize centaur-tabs-right-edge-margin 806 | 'face face 807 | 'centaur-tabs-tab tab 808 | 'pointer centaur-tabs-mouse-pointer 809 | 'local-map centaur-tabs-default-map)) 810 | 811 | (centaur-tabs-separator-render centaur-tabs-style-right face)))) 812 | 813 | (defsubst centaur-tabs-button-tab (button) 814 | "Return the display representation of button BUTTON. 815 | That is, a propertized string used as an `centaur-tabs-display-line-format' 816 | template element." 817 | (let* ((face 'centaur-tabs-unselected)) 818 | (concat (propertize button 819 | 'face face 820 | 'mouse-face 'highlight)))) 821 | 822 | (defun centaur-tabs-line-format (tabset) 823 | "Return the `centaur-tabs-display-line-format' value to display TABSET." 824 | (let* ((sel (centaur-tabs-selected-tab tabset)) 825 | (tabs (centaur-tabs-view tabset)) 826 | (padcolor centaur-tabs-background-color) 827 | (all-tabs (centaur-tabs-tabs tabset)) 828 | (total-tabs (length all-tabs)) 829 | (sel-index (+ (cl-position (car sel) (mapcar 'car all-tabs)) 1)) 830 | atsel elts) 831 | ;; Track the selected tab to ensure it is always visible. 832 | (when centaur-tabs--track-selected 833 | (while (not (memq sel tabs)) 834 | (centaur-tabs-scroll tabset -1) 835 | (setq tabs (centaur-tabs-view tabset))) 836 | (while (and tabs (not atsel)) 837 | (setq elts (cons (centaur-tabs-line-tab (car tabs)) elts) 838 | atsel (eq (car tabs) sel) 839 | tabs (cdr tabs))) 840 | (setq elts (nreverse elts)) 841 | ;; At this point the selected tab is the last elt in ELTS. 842 | ;; Scroll TABSET and ELTS until the selected tab becomes 843 | ;; visible. 844 | (let (buffer-list-update-hook) 845 | (with-temp-buffer 846 | (let ((truncate-partial-width-windows nil) 847 | (inhibit-modification-hooks t) 848 | deactivate-mark ;; Prevent deactivation of the mark! 849 | start) 850 | (setq truncate-lines nil 851 | buffer-undo-list t) 852 | (setq start (point)) 853 | (while (and (cdr elts) ;; Always show the selected tab! 854 | (progn 855 | (delete-region start (point-max)) 856 | (goto-char (point-max)) 857 | (apply #'insert elts) 858 | (goto-char (point-min)) 859 | (> (vertical-motion 1) 0))) 860 | (centaur-tabs-scroll tabset -1) 861 | (setq elts (cdr elts)))))) 862 | (setq elts (nreverse elts)) 863 | (setq centaur-tabs--track-selected nil)) 864 | ;; Format remaining tabs. 865 | (while tabs 866 | (setq elts (cons (centaur-tabs-line-tab (car tabs)) elts) 867 | tabs (cdr tabs))) 868 | ;; Cache and return the new tab bar. 869 | (centaur-tabs-set-template 870 | tabset 871 | (list 872 | (centaur-tabs-count sel-index total-tabs) 873 | (centaur-tabs-line-format--buttons) 874 | (nreverse elts) 875 | (propertize "% " 876 | 'face (list :background padcolor) 877 | 'pointer 'arrow) 878 | (centaur-tabs-line-format--new-button))))) 879 | 880 | (defun centaur-tabs-count (index count) 881 | "Return a centaur-tabs-button-tab with the current tab INDEX and the total 882 | tabs COUNT." 883 | (if centaur-tabs-show-count 884 | (propertize (centaur-tabs-button-tab (format centaur-tabs-count-format 885 | index count)) 886 | 'help-echo "Tabs count") 887 | "")) 888 | 889 | (defun centaur-tabs-line-format--buttons () 890 | "Return the buttons fragment of the header line." 891 | (if (and centaur-tabs-show-navigation-buttons (display-graphic-p)) 892 | (list 893 | (propertize (centaur-tabs-button-tab centaur-tabs-down-tab-text) 894 | 'local-map centaur-tabs-down-tab-map 895 | 'help-echo "Change tab group") 896 | (propertize (centaur-tabs-button-tab centaur-tabs-backward-tab-text) 897 | 'local-map centaur-tabs-backward-tab-map 898 | 'help-echo "Previous tab") 899 | (propertize (centaur-tabs-button-tab centaur-tabs-forward-tab-text) 900 | 'local-map centaur-tabs-forward-tab-map 901 | 'help-echo "Next tab")) 902 | "")) 903 | 904 | (defun centaur-tabs-line-format--new-button () 905 | "Return the new-tab button fragment at the right end of the header line." 906 | (if centaur-tabs-show-new-tab-button 907 | (concat 908 | (propertize (centaur-tabs-button-tab centaur-tabs-new-tab-text) 909 | 'local-map centaur-tabs-new-tab-map 910 | 'help-echo "Create new tab") 911 | ""))) 912 | 913 | (defun centaur-tabs-line () 914 | "Return the header line templates that represent the tab bar. 915 | Inhibit display of the tab bar in current window where 916 | `centaur-tabs-hide-tab-function' return t." 917 | (cond ((or (centaur-tabs-hide-tab-cached (current-buffer)) 918 | (and centaur-tabs-hide-predicate 919 | (funcall centaur-tabs-hide-predicate))) 920 | ;; Don't show the tab bar. 921 | (set centaur-tabs-display-line-format nil)) 922 | ((centaur-tabs-current-tabset t) 923 | ;; When available, use a cached tab bar value, else recompute it. 924 | (or (centaur-tabs-template centaur-tabs-current-tabset) 925 | (centaur-tabs-line-format centaur-tabs-current-tabset))))) 926 | 927 | (defconst centaur-tabs-header-line-format '(:eval (centaur-tabs-line)) 928 | "The tab bar header line format.") 929 | 930 | ;; 931 | ;;; Cyclic navigation through tabs 932 | 933 | (defun centaur-tabs-cycle (&optional backward) 934 | "Cycle to the next available tab. 935 | The scope of the cyclic navigation through tabs is specified by the 936 | option `centaur-tabs-cycle-scope'. 937 | If optional argument BACKWARD is non-nil, cycle to the previous tab 938 | instead." 939 | (let* ((tabset (centaur-tabs-current-tabset t)) 940 | (ttabset (centaur-tabs-get-tabsets-tabset)) 941 | ;; If navigation through groups is requested, and there is 942 | ;; only one group, navigate through visible tabs. 943 | (cycle (if (and (eq centaur-tabs-cycle-scope 'groups) 944 | (not (cdr (centaur-tabs-tabs ttabset)))) 945 | 'tabs 946 | centaur-tabs-cycle-scope)) 947 | selected tab) 948 | (when tabset 949 | (setq selected (centaur-tabs-selected-tab tabset)) 950 | (cond 951 | ;; Cycle through visible tabs only. 952 | ((eq cycle 'tabs) 953 | (setq tab (centaur-tabs-tab-next tabset selected backward)) 954 | ;; When there is no tab after/before the selected one, cycle 955 | ;; to the first/last visible tab. 956 | (unless tab 957 | (setq tabset (centaur-tabs-tabs tabset) 958 | tab (car (if backward (last tabset) tabset))))) 959 | ;; Cycle through tab groups only. 960 | ((eq cycle 'groups) 961 | (setq tab (centaur-tabs-tab-next ttabset selected backward)) 962 | ;; When there is no group after/before the selected one, cycle 963 | ;; to the first/last available group. 964 | (unless tab 965 | (setq tabset (centaur-tabs-tabs ttabset) 966 | tab (car (if backward (last tabset) tabset))))) 967 | (t 968 | ;; Cycle through visible tabs then tab groups. 969 | (setq tab (centaur-tabs-tab-next tabset selected backward)) 970 | ;; When there is no visible tab after/before the selected one, 971 | ;; cycle to the next/previous available group. 972 | (unless tab 973 | (setq tab (centaur-tabs-tab-next ttabset selected backward)) 974 | ;; When there is no next/previous group, cycle to the 975 | ;; first/last available group. 976 | (unless tab 977 | (setq tabset (centaur-tabs-tabs ttabset) 978 | tab (car (if backward (last tabset) tabset)))) 979 | ;; Select the first/last visible tab of the new group. 980 | (setq tabset (centaur-tabs-tabs (centaur-tabs-tab-tabset tab)) 981 | tab (car (if backward (last tabset) tabset)))))) 982 | (centaur-tabs-buffer-select-tab tab)))) 983 | 984 | ;;;###autoload 985 | (defun centaur-tabs-backward () 986 | "Select the previous available tab. 987 | Depend on the setting of the option `centaur-tabs-cycle-scope'." 988 | (interactive) 989 | (if (centaur-tabs-current-tabset t) 990 | (centaur-tabs-cycle t) 991 | (previous-buffer))) 992 | 993 | ;;;###autoload 994 | (defun centaur-tabs-forward () 995 | "Select the next available tab. 996 | Depend on the setting of the option `centaur-tabs-cycle-scope'." 997 | (interactive) 998 | (if (centaur-tabs-current-tabset t) 999 | (centaur-tabs-cycle) 1000 | (next-buffer))) 1001 | 1002 | ;;;###autoload 1003 | (defun centaur-tabs-backward-group () 1004 | "Go to selected tab in the previous available group." 1005 | (interactive) 1006 | (let ((centaur-tabs-cycle-scope 'groups)) 1007 | (centaur-tabs-cycle t))) 1008 | 1009 | ;;;###autoload 1010 | (defun centaur-tabs-forward-group () 1011 | "Go to selected tab in the next available group." 1012 | (interactive) 1013 | (let ((centaur-tabs-cycle-scope 'groups)) 1014 | (centaur-tabs-cycle))) 1015 | 1016 | ;;;###autoload 1017 | (defun centaur-tabs-backward-tab () 1018 | "Select the previous visible tab." 1019 | (interactive) 1020 | (let ((centaur-tabs-cycle-scope 'tabs)) 1021 | (centaur-tabs-cycle t))) 1022 | 1023 | ;;;###autoload 1024 | (defun centaur-tabs-forward-tab () 1025 | "Select the next visible tab." 1026 | (interactive) 1027 | (let ((centaur-tabs-cycle-scope 'tabs)) 1028 | (centaur-tabs-cycle))) 1029 | 1030 | ;; 1031 | ;;; Buffer tabs 1032 | 1033 | (defgroup centaur-tabs-buffer nil 1034 | "Display buffers in the tab bar." 1035 | :group 'centaur-tabs) 1036 | 1037 | (defun centaur-tabs-buffer-list () 1038 | "Return the list of buffers to show in tabs. 1039 | Exclude buffers whose name starts with a space, when they are not 1040 | visiting a file." 1041 | (seq-filter (lambda (b) 1042 | (cond ((eq (current-buffer) b) b) 1043 | ((buffer-file-name b) b) 1044 | ((char-equal ?\ (aref (buffer-name b) 0)) nil) 1045 | ((buffer-live-p b) b))) 1046 | (buffer-list))) 1047 | 1048 | (defun centaur-tabs-buffer-mode-derived-p (mode parents) 1049 | "Return non-nil if MODE derives from a mode in PARENTS." 1050 | (let (derived) 1051 | (while (and (not derived) mode) 1052 | (if (memq mode parents) 1053 | (setq derived t) 1054 | (setq mode (get mode 'derived-mode-parent)))) 1055 | derived)) 1056 | 1057 | ;; 1058 | ;;; Group buffers in tab sets. 1059 | 1060 | (defvar centaur-tabs--buffers nil) 1061 | 1062 | (defun centaur-tabs-buffer-groups-result () 1063 | "Return the first group the current buffer belongs to." 1064 | (car (nth 2 (assq (current-buffer) centaur-tabs--buffers)))) 1065 | 1066 | (defun centaur-tabs-buffer-update-groups () 1067 | "Update tabsets from groups of existing buffers. 1068 | Return the the first group where the current buffer is." 1069 | (let ((bl (sort 1070 | (mapcar 1071 | #'(lambda (b) 1072 | (with-current-buffer b 1073 | (list (current-buffer) 1074 | (buffer-name) 1075 | (if centaur-tabs-buffer-groups-function 1076 | (funcall centaur-tabs-buffer-groups-function) 1077 | '(centaur-tabs-common-group-name))))) 1078 | (and centaur-tabs-buffer-list-function 1079 | (funcall centaur-tabs-buffer-list-function))) 1080 | #'(lambda (e1 e2) 1081 | (string-lessp (nth 1 e1) (nth 1 e2)))))) 1082 | ;; If the cache has changed, update the tab sets. 1083 | (unless (equal bl centaur-tabs--buffers) 1084 | ;; Add new buffers, or update changed ones. 1085 | (dolist (e bl) 1086 | (dolist (g (nth 2 e)) 1087 | (let ((tabset (centaur-tabs-get-tabset g))) 1088 | (if tabset 1089 | (unless (equal e (assq (car e) centaur-tabs--buffers)) 1090 | ;; This is a new buffer, or a previously existing 1091 | ;; buffer that has been renamed, or moved to another 1092 | ;; group. Update the tab set, and the display. 1093 | (centaur-tabs-add-tab tabset (car e)) 1094 | (centaur-tabs-set-template tabset nil)) 1095 | (centaur-tabs-make-tabset g (car e)))))) 1096 | ;; Remove tabs for buffers not found in cache or moved to other 1097 | ;; groups, and remove empty tabsets. 1098 | (mapc 'centaur-tabs-delete-tabset 1099 | (centaur-tabs-map-tabsets 1100 | #'(lambda (tabset) 1101 | (dolist (tab (centaur-tabs-tabs tabset)) 1102 | (let ((e (assq (centaur-tabs-tab-value tab) bl))) 1103 | (or (and e (memq tabset 1104 | (mapcar 'centaur-tabs-get-tabset 1105 | (nth 2 e)))) 1106 | (centaur-tabs-delete-tab tab)))) 1107 | ;; Return empty tab sets 1108 | (unless (centaur-tabs-tabs tabset) 1109 | tabset)))) 1110 | ;; The new cache becomes the current one. 1111 | (setq centaur-tabs--buffers bl)))) 1112 | 1113 | (defun centaur-tabs-buffer-update-groups-cache () 1114 | "Don't call function `centaur-tabs-buffer-update-groups' too often." 1115 | (let ((result (centaur-tabs-buffer-groups-result))) 1116 | (when (or (null result) 1117 | (null centaur-tabs--buffers)) 1118 | (centaur-tabs-buffer-update-groups)) 1119 | (centaur-tabs-buffer-groups-result))) 1120 | 1121 | ;; 1122 | ;;; Tab bar callbacks 1123 | 1124 | (defsubst centaur-tabs-buffer-show-groups (flag) 1125 | "Set display of tabs for groups of buffers to FLAG." 1126 | (setq centaur-tabs--buffer-show-groups flag)) 1127 | 1128 | (defun centaur-tabs-buffer-tabs () 1129 | "Return the buffers to display on the tab bar, in a tab set." 1130 | (let ((tabset (centaur-tabs-get-tabset (centaur-tabs-buffer-update-groups-cache)))) 1131 | (centaur-tabs-select-tab-value (current-buffer) tabset) 1132 | (when centaur-tabs--buffer-show-groups 1133 | (setq tabset (centaur-tabs-get-tabsets-tabset)) 1134 | (centaur-tabs-select-tab-value (current-buffer) tabset)) 1135 | tabset)) 1136 | 1137 | (defun centaur-tabs-buffer-tab-label (tab) 1138 | "Return a label for TAB. 1139 | That is, a string used to represent it on the tab bar." 1140 | ;; Init tab style. 1141 | ;; Render tab. 1142 | (format " %s" 1143 | (let ((bufname (if centaur-tabs--buffer-show-groups 1144 | (centaur-tabs-tab-tabset tab) 1145 | (buffer-name (car tab))))) 1146 | (if (> centaur-tabs-label-fixed-length 0) 1147 | (centaur-tabs-truncate-string centaur-tabs-label-fixed-length bufname) 1148 | bufname)))) 1149 | 1150 | (defvar centaur-tabs-last-scroll-y 0 1151 | "Holds the scroll y of window from the last run of post-command-hooks.") 1152 | 1153 | (defun centaur-tabs-separator-render (item face) 1154 | "Render ITEM using FACE." 1155 | (cond ((and (listp item) (eq 'image (car item))) 1156 | (propertize " " 'display item 'face face)) 1157 | (t item))) 1158 | 1159 | (defvar centaur-tabs-last-focused-buffer nil 1160 | "The last focused buffer.") 1161 | 1162 | (defvar centaur-tabs-last-focused-buffer-group nil 1163 | "The group name of last focused buffer.") 1164 | 1165 | (defun centaur-tabs-buffer-select-tab (tab) 1166 | "Select TAB." 1167 | (let ((buffer (centaur-tabs-tab-value tab)) 1168 | (group (centaur-tabs-tab-tabset tab))) 1169 | (switch-to-buffer buffer) 1170 | (setq centaur-tabs-last-focused-buffer buffer) 1171 | (setq centaur-tabs-last-focused-buffer-group group) 1172 | ;;(centaur-tabs-buffer-show-groups nil) 1173 | (centaur-tabs-display-update))) 1174 | 1175 | (defun centaur-tabs-buffer-track-killed () 1176 | "Hook run just before actually killing a buffer. 1177 | In Centaur-Tabs mode, try to switch to a buffer in the current tab bar, 1178 | after the current buffer has been killed. Try first the buffer in tab 1179 | after the current one, then the buffer in tab before. On success, put 1180 | the sibling buffer in front of the buffer list, so it will be selected 1181 | first." 1182 | (and (eq (eval centaur-tabs-display-line-format) centaur-tabs-header-line-format) 1183 | (eq centaur-tabs-current-tabset-function 'centaur-tabs-buffer-tabs) 1184 | (eq (current-buffer) (window-buffer (selected-window))) 1185 | (let ((bl (centaur-tabs-tab-values (centaur-tabs-current-tabset))) 1186 | (b (current-buffer)) 1187 | found sibling) 1188 | (while (and bl (not found)) 1189 | (if (eq b (car bl)) 1190 | (setq found t) 1191 | (setq sibling (car bl))) 1192 | (setq bl (cdr bl))) 1193 | (when (and (setq sibling (or (car bl) sibling)) 1194 | (buffer-live-p sibling)) 1195 | ;; Move sibling buffer in front of the buffer list. 1196 | (save-current-buffer 1197 | (switch-to-buffer sibling)))))) 1198 | 1199 | ;; Buffer reordering 1200 | (defun centaur-tabs-remove-nth-element (nth list) 1201 | "Remove NTH element from LIST." 1202 | (if (zerop nth) (cdr list) 1203 | (let ((last (nthcdr (1- nth) list))) 1204 | (setcdr last (cddr last)) 1205 | list))) 1206 | 1207 | (defun centaur-tabs-insert-after (list aft-el el) 1208 | "Insert EL after AFT-EL in LIST." 1209 | (push el (cdr (member aft-el list))) 1210 | list) 1211 | 1212 | (defun centaur-tabs-insert-before (list bef-el el) 1213 | "Insert EL before BEF-EL in LIST." 1214 | (nreverse (centaur-tabs-insert-after (nreverse list) bef-el el))) 1215 | 1216 | (defun centaur-tabs-adjust-buffer-order () 1217 | "Put the two buffers switched to the adjacent position after current 1218 | buffer changed." 1219 | ;; Don't trigger by centaur-tabs command, it's annoying. 1220 | ;; This feature should be trigger by search plugins, such as ibuffer, helm or ivy. 1221 | (unless (or (string-prefix-p "centaur-tabs" (format "%s" this-command)) 1222 | (string-prefix-p "mouse-drag-header-line" (format "%s" this-command)) 1223 | (string-prefix-p "mouse-drag-tab-line" (format "%s" this-command)) 1224 | (string-prefix-p "(lambda (event) (interactive e)" (format "%s" this-command))) 1225 | ;; Just continue when the buffer has changed. 1226 | (when (and centaur-tabs-adjust-buffer-order 1227 | (not (eq (current-buffer) centaur-tabs-last-focused-buffer)) 1228 | (not (minibufferp))) 1229 | (let* ((current (current-buffer)) 1230 | (previous centaur-tabs-last-focused-buffer) 1231 | (current-group (cl-first (funcall centaur-tabs-buffer-groups-function)))) 1232 | ;; Record the last focused buffer. 1233 | (setq centaur-tabs-last-focused-buffer current) 1234 | 1235 | ;; Just continue if two buffers are in the same group. 1236 | (when (string= current-group centaur-tabs-last-focused-buffer-group) 1237 | (let* ((bufset (centaur-tabs-get-tabset current-group)) 1238 | (current-group-tabs (centaur-tabs-tabs bufset)) 1239 | (current-group-buffers (mapcar 'car current-group-tabs)) 1240 | (current-buffer-index (cl-position current current-group-buffers)) 1241 | (previous-buffer-index (cl-position previous current-group-buffers))) 1242 | 1243 | ;; If the tabs are not adjacent, swap their positions. 1244 | (when (and current-buffer-index 1245 | previous-buffer-index 1246 | (> (abs (- current-buffer-index previous-buffer-index)) 1)) 1247 | (let* ((copy-group-tabs (cl-copy-list current-group-tabs)) 1248 | (previous-tab (nth previous-buffer-index copy-group-tabs)) 1249 | (current-tab (nth current-buffer-index copy-group-tabs)) 1250 | (base-group-tabs (centaur-tabs-remove-nth-element current-buffer-index copy-group-tabs)) 1251 | new-group-tabs) 1252 | (cond 1253 | ((eq centaur-tabs-adjust-buffer-order 'left) 1254 | (setq new-group-tabs (centaur-tabs-insert-before base-group-tabs previous-tab current-tab))) 1255 | ((eq centaur-tabs-adjust-buffer-order 'right) 1256 | (setq new-group-tabs (centaur-tabs-insert-after base-group-tabs previous-tab current-tab))) 1257 | (t 1258 | (if (> current-buffer-index previous-buffer-index) 1259 | (setq new-group-tabs (centaur-tabs-insert-after base-group-tabs previous-tab current-tab)) 1260 | (setq new-group-tabs (centaur-tabs-insert-before base-group-tabs previous-tab current-tab))))) 1261 | (set bufset new-group-tabs) 1262 | (centaur-tabs-set-template bufset nil) 1263 | (centaur-tabs-display-update))))) 1264 | 1265 | ;; Update the group name of the last accessed tab. 1266 | (setq centaur-tabs-last-focused-buffer-group current-group))))) 1267 | 1268 | (defun centaur-tabs-adjust-buffer-order-alphabetically () 1269 | "Order tabs in group alphabetically." 1270 | ;; Don't trigger by centaur-tabs command, it's annoying. 1271 | (unless (or (string-prefix-p "centaur-tabs" (format "%s" this-command)) 1272 | (string-prefix-p "mouse-drag-header-line" (format "%s" this-command)) 1273 | (string-prefix-p "mouse-drag-tab-line" (format "%s" this-command)) 1274 | (string-prefix-p "(lambda (event) (interactive e)" (format "%s" this-command))) 1275 | ;; Just continue when the buffer has changed. 1276 | (when (and centaur-tabs-adjust-buffer-order 1277 | (not (eq (current-buffer) centaur-tabs-last-focused-buffer)) ;;??? 1278 | (not (minibufferp))) 1279 | (let* ((current (current-buffer)) 1280 | (current-group (cl-first (funcall centaur-tabs-buffer-groups-function)))) 1281 | (setq centaur-tabs-last-focused-buffer current) 1282 | ;; Just continue if two buffers are in the same group. 1283 | (when (string= current-group centaur-tabs-last-focused-buffer-group) 1284 | (let* ((bufset (centaur-tabs-get-tabset current-group)) 1285 | (current-group-tabs (centaur-tabs-tabs bufset)) 1286 | (new-group-tabs (sort current-group-tabs 1287 | (lambda (x y) 1288 | (string< (buffer-name (car x)) (buffer-name (car y))))))) 1289 | (set bufset new-group-tabs) 1290 | (centaur-tabs-set-template bufset nil) 1291 | (centaur-tabs-display-update))) 1292 | (setq centaur-tabs-last-focused-buffer-group current-group))))) 1293 | 1294 | (defun centaur-tabs-enable-buffer-reordering () 1295 | "Enable the buffer reordering functionality, according to buffer usage." 1296 | (add-hook 'post-command-hook centaur-tabs-adjust-buffer-order-function)) 1297 | 1298 | (defun centaur-tabs-enable-buffer-alphabetical-reordering () 1299 | "Enable the buffer alphabetical reordering functionality." 1300 | (setq centaur-tabs-adjust-buffer-order-function 'centaur-tabs-adjust-buffer-order-alphabetically) 1301 | (add-hook 'post-command-hook centaur-tabs-adjust-buffer-order-function)) 1302 | 1303 | ;; 1304 | ;;; Buffer grouping and tab hiding 1305 | 1306 | (defun centaur-tabs-project-name () 1307 | "Get project name for tabs." 1308 | (when-let* (((buffer-file-name)) 1309 | (project-current (project-current)) 1310 | (project-name (if (proper-list-p project-current) 1311 | (car (last project-current)) 1312 | (cdr project-current)))) 1313 | (format "Project: %s" (expand-file-name project-name)))) 1314 | 1315 | ;; Rules to control buffer's group rules. 1316 | (defvar centaur-tabs-groups-hash (make-hash-table :test 'equal)) 1317 | (defvar centaur-tabs-hide-hash (make-hash-table :test 'equal)) 1318 | 1319 | (defun centaur-tabs-get-group-name (buf) 1320 | "Get group name of buffer BUF." 1321 | (let ((group-name (gethash buf centaur-tabs-groups-hash))) 1322 | ;; Return group name cache if it exists for improve performance. 1323 | (or group-name 1324 | centaur-tabs-common-group-name))) 1325 | 1326 | (defun centaur-tabs-buffer-groups () 1327 | "`centaur-tabs-buffer-groups' control buffers' group rules. 1328 | 1329 | Group centaur-tabs with mode if buffer is derived from `eshell-mode' 1330 | `emacs-lisp-mode' `dired-mode' `org-mode' `magit-mode'. 1331 | All buffer name start with * will group to \"Emacs\". 1332 | Other buffer group by `centaur-tabs-get-group-name' with project name." 1333 | (list 1334 | (cond 1335 | ((when-let* ((project-name (centaur-tabs-project-name))) 1336 | project-name)) 1337 | ((memq major-mode '( magit-process-mode 1338 | magit-status-mode 1339 | magit-log-mode 1340 | magit-file-mode 1341 | magit-blob-mode 1342 | magit-blame-mode 1343 | magit-diff-mode 1344 | magit-revision-mode 1345 | magit-stash-mode)) 1346 | "Magit") 1347 | ((derived-mode-p 'shell-mode) "Shell") 1348 | ((derived-mode-p 'eshell-mode) "EShell") 1349 | ((derived-mode-p 'dired-mode) "Dired") 1350 | ((memq major-mode '( org-mode org-agenda-mode diary-mode)) "OrgMode") 1351 | ((and centaur-tabs-custom-buffer-groups 1352 | (funcall centaur-tabs-custom-buffer-groups))) 1353 | ((derived-mode-p 'emacs-lisp-mode) "Elisp") 1354 | ((string-equal "*" (substring (buffer-name) 0 1)) 1355 | "Emacs") 1356 | (t 1357 | (centaur-tabs-get-group-name (current-buffer)))))) 1358 | 1359 | (defun centaur-tabs--create-new-empty-buffer () 1360 | "Open an Untitled buffer." 1361 | (interactive) 1362 | (let ((buf (generate-new-buffer "Untitled"))) 1363 | (switch-to-buffer buf) 1364 | (funcall (and initial-major-mode)) 1365 | (setq buffer-offer-save t))) 1366 | 1367 | (defun centaur-tabs--create-new-tab () 1368 | "Create a context-aware new tab." 1369 | (interactive) 1370 | (cond 1371 | ((eq major-mode 'eshell-mode) 1372 | (eshell t)) 1373 | ((eq major-mode 'vterm-mode) 1374 | (vterm t)) 1375 | ((eq major-mode 'term-mode) 1376 | (ansi-term "/bin/bash")) 1377 | ((derived-mode-p 'eww-mode) 1378 | (let ((current-prefix-arg 4)) 1379 | (call-interactively #'eww))) 1380 | (t 1381 | (centaur-tabs--create-new-empty-buffer)))) 1382 | 1383 | (defun centaur-tabs-hide-tab (x) 1384 | "Do no to show buffer X in tabs." 1385 | (let ((name (format "%s" x))) 1386 | (or 1387 | ;; Current window is not dedicated window. 1388 | (window-dedicated-p (selected-window)) 1389 | 1390 | ;; Buffer name not match below blacklist. 1391 | (cl-dolist (prefix centaur-tabs-excluded-prefixes) 1392 | (when (string-prefix-p prefix name) 1393 | (cl-return t))) 1394 | 1395 | ;; Is not magit buffer. 1396 | (and (string-prefix-p "magit" name) 1397 | (not (file-name-extension name)))))) 1398 | 1399 | (defun centaur-tabs-hide-tab-cached (buf) 1400 | "Cached vesion of `centaur-tabs-hide-tab' to improve performance. 1401 | Operates over buffer BUF" 1402 | (let ((hide (gethash buf centaur-tabs-hide-hash 'not-found))) 1403 | (when (eq hide 'not-found) 1404 | (setq hide (funcall centaur-tabs-hide-tab-function buf)) 1405 | (puthash buf hide centaur-tabs-hide-hash)) 1406 | hide)) 1407 | 1408 | ;;;;;;;;;;;;;;;;;;;;;;; Utils functions ;;;;;;;;;;;;;;;;;;;;;;; 1409 | (defun centaur-tabs-get-groups () 1410 | "Refresh tabs groups." 1411 | (set centaur-tabs-tabsets-tabset (centaur-tabs-map-tabsets 'centaur-tabs-selected-tab)) 1412 | (mapcar #'(lambda (group) 1413 | (format "%s" (cdr group))) 1414 | (centaur-tabs-tabs centaur-tabs-tabsets-tabset))) 1415 | 1416 | (defun centaur-tabs-get-extensions () 1417 | "Get file extension of tabs." 1418 | (set centaur-tabs-tabsets-tabset (centaur-tabs-map-tabsets 'centaur-tabs-selected-tab)) 1419 | (let (extension-names) 1420 | (mapc #'(lambda (buffer) 1421 | (with-current-buffer buffer 1422 | (when (string-equal 'current-group-name (cdr (centaur-tabs-selected-tab (centaur-tabs-current-tabset t)))) 1423 | (when (buffer-file-name buffer) 1424 | (add-to-list 'extension-names (file-name-extension (buffer-file-name buffer))))))) 1425 | (buffer-list)) 1426 | extension-names)) 1427 | 1428 | (defcustom centaur-tabs-enable-ido-completion t 1429 | "Non-nil means use `ido-completing-read' for completing reads 1430 | else `completing-read'." 1431 | :group 'centaur-tabs 1432 | :type 'boolean) 1433 | 1434 | (defun centaur-tabs-completing-read (prompt choices) 1435 | "Prompt user with PROMPT to select from CHOICES using a completing read. 1436 | Refer to the variable `centaur-tabs-enable-ido-completion'." 1437 | (interactive) 1438 | (if centaur-tabs-enable-ido-completion 1439 | (ido-completing-read prompt choices) 1440 | (completing-read prompt choices))) 1441 | 1442 | ;;;;;;;;;;;;;;;;;;;;;;; Default configurations ;;;;;;;;;;;;;;;;;;;;;;; 1443 | 1444 | (mapc (lambda (hook) 1445 | (add-hook hook (lambda () 1446 | (if (boundp 'tab-line-format) 1447 | (setq-local tab-line-format nil) 1448 | (setq-local header-line-format nil))))) 1449 | centaur-tabs-hide-tabs-hooks) 1450 | 1451 | (provide 'centaur-tabs-functions) 1452 | ;;; centaur-tabs-functions.el ends here 1453 | --------------------------------------------------------------------------------