aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bard-elisp/bard-window.el81
-rw-r--r--bard-emacs-modules/bard-emacs-window.el11
2 files changed, 92 insertions, 0 deletions
diff --git a/bard-elisp/bard-window.el b/bard-elisp/bard-window.el
index 8860310..1670312 100644
--- a/bard-elisp/bard-window.el
+++ b/bard-elisp/bard-window.el
@@ -63,4 +63,85 @@ This as the action function in a `display-buffer-alist' entry."
(when (apply fn args)
(throw 'success fn))))))
+;; taken from https://github.com/hylophile/.files/blob/1f3f01e4e25b00f7b61eca286fcf4f865885090c/.config/doom/config.org#fancy-tab-bar
+
+(defun hy/tab-bar-format-align-center ()
+ "Align the rest of tab bar items centered."
+ (let* ((rest (cdr (memq 'hy/tab-bar-format-align-center tab-bar-format)))
+ (rest (tab-bar-format-list rest))
+ (rest (mapconcat (lambda (item) (nth 2 item)) rest ""))
+ (hpos (progn
+ (add-face-text-property 0 (length rest) 'tab-bar t rest)
+ (string-pixel-width rest)))
+ (hpos (+ hpos (/ (- (frame-inner-width) hpos) 2)))
+ (str (propertize "​" 'display
+ ;; The `right' spec doesn't work on TTY frames
+ ;; when windows are split horizontally (bug#59620)
+ (if (window-system)
+ `(space :align-to (- right (,hpos)))
+ `(space :align-to (,(- (frame-inner-width) hpos)))))))
+ `((align-center menu-item ,str ignore))))
+
+(setq tab-bar-tab-name-format-function #'hy/tab-bar-tab-name-format-default)
+(defun hy/tab-bar-tab-name-format-default (tab i)
+ (let* ((hint (format "%d" i))
+ (name (alist-get 'name tab))
+ (dir (concat "(" (alist-get 'dir tab "") ")"))
+ (name-format (concat
+ " "
+ (propertize hint 'face 'tab-bar-hint)
+ " "
+ name
+ " ")))
+ (add-face-text-property
+ 0 (length name-format)
+ (funcall tab-bar-tab-face-function tab)
+ 'append name-format)
+ name-format))
+
+
+(setq tab-bar-tab-name-function #'hy/tab-bar-tab-name-current)
+(defun hy/tab-bar-tab-name-current ()
+ (hy/shorten-string
+ (hy/abbreviate-tab-name
+ (buffer-name (window-buffer (or (minibuffer-selected-window)
+ (and (window-minibuffer-p)
+ (get-mru-window))))))
+ 25))
+
+(defun hy/set-tab-dir ()
+ (setf (alist-get 'dir (cdr (tab-bar--current-tab-find)))
+ (hy/tab-bar-dir)))
+
+(defun hy/abbreviate-directory-path (path)
+ "Turns `~/code/test/t` into `~/c/t/project`."
+ (let* ((directories (seq-filter (lambda (s) (not (string= s ""))) (split-string path "/")))
+ (last-dir (car (last directories)))
+ (abbreviated-dirs (mapcar (lambda (dir)
+ (if (string= dir last-dir)
+ dir
+ (substring dir 0 (if (string-prefix-p "." dir) 2 1))))
+ directories)))
+ (mapconcat 'identity abbreviated-dirs "/")))
+
+(defun hy/tab-bar-dir ()
+ (hy/shorten-string (hy/abbreviate-directory-path
+ (abbreviate-file-name
+ (or (projectile-project-root) default-directory)))
+ 10
+ t))
+
+(defun hy/shorten-string (string max-length &optional at-start)
+ (let ((len (length string)))
+ (if (> len max-length)
+ (if at-start
+ (concat "…" (substring string (- len max-length) len))
+ (concat (substring string 0 max-length) "…"))
+ string)))
+
+(defun hy/abbreviate-tab-name (name)
+ (string-trim (replace-regexp-in-string
+ (rx (or "*" "helpful" "Org Src"))
+ "" name)))
+
(provide 'bard-window)
diff --git a/bard-emacs-modules/bard-emacs-window.el b/bard-emacs-modules/bard-emacs-window.el
index 665b0b3..130ab6c 100644
--- a/bard-emacs-modules/bard-emacs-window.el
+++ b/bard-emacs-modules/bard-emacs-window.el
@@ -141,5 +141,16 @@
:bind
("C-x w t" . tear-off-window))
+(use-package tab-bar
+ :ensure nil
+ :config
+ (tab-bar-mode +1)
+
+ (setq tab-bar-tab-hints t
+ tab-bar-close-button-show nil
+ tab-bar-new-button-show nil
+ tab-bar-separator " "
+ tab-bar-auto-width nil))
+
(provide 'bard-emacs-window)
;;; bard-emacs-window.el ends here