Created
May 7, 2022 20:19
-
-
Save michaelmrose/cbd95f3f055b3040b8d47462bc767662 to your computer and use it in GitHub Desktop.
Emacs Powerline Tabs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; package -- Summary | |
;;; my tabs settings and configuration | |
;;; mytabs.el | |
;;; Commentary: | |
;;; Code: | |
;; Global Bindings | |
(require 'evil) | |
(global-set-key (kbd "C-t") 'tab-bar-new-tab) | |
(evil-global-set-key 'normal (kbd "C-t") 'tab-bar-new-tab ) | |
(evil-global-set-key 'insert (kbd "C-t") 'tab-bar-new-tab ) | |
(global-set-key (kbd "C-q") 'tab-bar-close-tab) | |
(global-set-key (kbd "<print>") 'tab-bar-switch-to-prev-tab) | |
(global-set-key (kbd "<f26>") 'tab-bar-switch-to-prev-tab) | |
(global-set-key (kbd "<f27>") 'tab-bar-switch-to-next-tab) | |
(global-set-key (kbd "<s-tab>") 'mmr/tear-off-buffer-to-new-tab) | |
(global-set-key (kbd "s-<left>") (lambda ()(interactive) (tab-bar-move-tab -1))) | |
(global-set-key (kbd "s-<right>") (lambda () (interactive)(tab-bar-move-tab 1))) | |
(global-set-key (kbd "s-<f26>") (lambda ()(interactive) (tab-bar-move-tab -1))) | |
(global-set-key (kbd "s-<f27>") (lambda () (interactive)(tab-bar-move-tab 1))) | |
(use-package powerline) | |
(require 'powerline) | |
(require 's) | |
(setq tab-bar-new-tab-to 'rightmost | |
tab-bar-close-tab-select 'left | |
tab-bar-new-tab-choice "*scratch*" | |
tab-bar-show t | |
tab-bar-close-button-show nil | |
tab-bar-close-last-tab-choice 'delete-frame | |
tab-bar-mode t | |
tab-bar-tab-hints t | |
tab-bar-tab-name-function 'iconified-buffer-name) | |
(evil-global-set-key 'normal (kbd "g !") '(lambda ()(interactive)(tab-bar-select-tab 1)) ) | |
(evil-global-set-key 'normal (kbd "g @") '(lambda ()(interactive)(tab-bar-select-tab 2)) ) | |
(evil-global-set-key 'normal (kbd "g #") '(lambda ()(interactive)(tab-bar-select-tab 3)) ) | |
(evil-global-set-key 'normal (kbd "g $") '(lambda ()(interactive)(tab-bar-select-tab 4)) ) | |
(evil-global-set-key 'normal (kbd "g %") '(lambda ()(interactive)(tab-bar-select-tab 5)) ) | |
(evil-global-set-key 'normal (kbd "g ^") '(lambda ()(interactive)(tab-bar-select-tab 6)) ) | |
(evil-global-set-key 'normal (kbd "g &") '(lambda ()(interactive)(tab-bar-select-tab 7)) ) | |
(evil-global-set-key 'normal (kbd "g *") '(lambda ()(interactive)(tab-bar-select-tab 8)) ) | |
(evil-global-set-key 'normal (kbd "g (") '(lambda ()(interactive)(tab-bar-select-tab 9)) ) | |
(evil-global-set-key 'normal (kbd "g )") '(lambda ()(interactive)(tab-bar-select-tab 10)) ) | |
(evil-global-set-key 'motion (kbd "g !") '(lambda ()(interactive)(tab-bar-select-tab 1)) ) | |
(evil-global-set-key 'motion (kbd "g @") '(lambda ()(interactive)(tab-bar-select-tab 2)) ) | |
(evil-global-set-key 'motion (kbd "g #") '(lambda ()(interactive)(tab-bar-select-tab 3)) ) | |
(evil-global-set-key 'motion (kbd "g $") '(lambda ()(interactive)(tab-bar-select-tab 4)) ) | |
(evil-global-set-key 'motion (kbd "g %") '(lambda ()(interactive)(tab-bar-select-tab 5)) ) | |
(evil-global-set-key 'motion (kbd "g ^") '(lambda ()(interactive)(tab-bar-select-tab 6)) ) | |
(evil-global-set-key 'motion (kbd "g &") '(lambda ()(interactive)(tab-bar-select-tab 7)) ) | |
(evil-global-set-key 'motion (kbd "g *") '(lambda ()(interactive)(tab-bar-select-tab 8)) ) | |
(evil-global-set-key 'motion (kbd "g (") '(lambda ()(interactive)(tab-bar-select-tab 9)) ) | |
(evil-global-set-key 'motion (kbd "g )") '(lambda ()(interactive)(tab-bar-select-tab 10)) ) | |
;; Iconified Tabs | |
(defun buffer-icon () | |
(cond ((minibufferp) "") | |
((string-suffix-p "py" (buffer-name)) "") | |
((string-suffix-p "fish" (buffer-name)) "") | |
((string-suffix-p "el" (buffer-name)) "") | |
((string-suffix-p "org" (buffer-name)) "") | |
((string-suffix-p ".clj" buffer-file-name) "") | |
((buffer-file-name) (all-the-icons-icon-for-file buffer-file-name)) | |
((string-prefix-p "*elfeed" (buffer-name)) "") | |
((string-prefix-p "#" (buffer-name)) "") | |
((string-prefix-p "*mu4e" (buffer-name)) "") | |
((string-prefix-p "*mpdel" (buffer-name)) "") | |
((string-prefix-p "*Calc" (buffer-name)) "") | |
((string-prefix-p "*scratch" (buffer-name)) "") | |
((string-prefix-p "*Org" (buffer-name)) "") | |
((string-prefix-p "*cider" (buffer-name)) "") | |
(t ""))) | |
(defun format-tab-name (tab) | |
(->> | |
(replace-regexp-in-string "\*\\|>" "" tab) | |
(replace-regexp-in-string "<" " in "))) | |
(defun strip-leading-non-letter-characters (s) | |
(replace-regexp-in-string "^[0-9]+[_ -]" "" s)) | |
(defun mmr/simple-truncate (l s) | |
(let* ((stripped (strip-leading-non-letter-characters (file-name-sans-extension s))) | |
(ext (file-name-extension s))) | |
(if (> (length stripped) l ) | |
(concat (s-left l stripped) " … ." (file-name-extension s)) | |
(if (= 0 (length ext)) | |
stripped | |
(concat stripped "." ext))))) | |
(defun mmr/tear-off-buffer-to-new-tab () | |
"Create new frame with buffer buffer and close current tab needs to be extended to all buffers in tab" | |
(interactive) | |
(let ((b (current-buffer))) | |
(if (one-window-p) | |
(tab-bar-close-tab) | |
(delete-window)) | |
(make-frame) | |
(switch-to-buffer b) | |
)) | |
(defun iconified-buffer-name () | |
(let* ((my/tab-height 35) | |
(my/tab-left (powerline-zigzag-right 'tab-bar nil my/tab-height)) | |
(my/tab-right (powerline-arrow-fade-left nil 'tab-bar my/tab-height))) | |
(powerline-render (list (format-tab-name (concat " " (buffer-icon) " " (mmr/simple-truncate 25 (tab-bar-tab-name-current)) " ")) my/tab-right)))) | |
(defhydra tab-switch-hydra (:hint nil :quit-key "<escape>") | |
"Switch Tabs" | |
("h" tab-bar-switch-to-prev-tab "Left") | |
("l" tab-bar-switch-to-next-tab "Right") | |
("j" previous-buffer "Previous") | |
("k" next-buffer "Next") | |
("!" (lambda ()(interactive)(tab-bar-select-tab 1)) :color blue ) | |
("@" (lambda ()(interactive)(tab-bar-select-tab 2)) :color blue ) | |
("#" (lambda ()(interactive)(tab-bar-select-tab 3)) :color blue ) | |
("$" (lambda ()(interactive)(tab-bar-select-tab 4)) :color blue ) | |
("%" (lambda ()(interactive)(tab-bar-select-tab 5)) :color blue ) | |
("^" (lambda ()(interactive)(tab-bar-select-tab 6)) :color blue ) | |
("&" (lambda ()(interactive)(tab-bar-select-tab 7)) :color blue ) | |
("*" (lambda ()(interactive)(tab-bar-select-tab 8)) :color blue ) | |
("(" (lambda ()(interactive)(tab-bar-select-tab 9)) :color blue ) | |
(")" (lambda ()(interactive)(tab-bar-select-tab 0)) :color blue ) | |
("<Ret>" nil "Quit" :color blue) | |
("q" nil "Quit" :color blue)) | |
(provide 'mytabs) | |
;;; mytabs.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment