Skip to content

Commit

Permalink
popper-tab-line: Use a stable tab ordering
Browse files Browse the repository at this point in the history
popper-echo.el (popper-tab-line--ensure, popper-tab-line--format):
Apply the correct face to the tab numbers, and stabilize the order
of popup tabs in the tab-line when using popper-tab-line-mode.
  • Loading branch information
karthink committed Mar 24, 2024
1 parent 73dc34e commit 28f1882
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions popper-echo.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ NOTE: This feature is experimental."
:type 'boolean
:group 'popper)

(defcustom popper-echo-dispatch-keys '("M-0" "M-1" "M-2" "M-3" "M-4"
"M-5" "M-6" "M-7" "M-8" "M-9")
(defcustom popper-echo-dispatch-keys '("M-1" "M-2" "M-3" "M-4"
"M-5" "M-6" "M-7" "M-8" "M-9" "M-0")
"List of keys used for dispatching to popup buffers.
The first element is bound to the currently open popup.
Expand Down Expand Up @@ -279,21 +279,29 @@ To define buffers as popups and customize popup display, see
(defun popper-tab-line--format (tab tabs)
(let ((name (tab-line-tab-name-format-default tab tabs))
(idx (cl-position tab tabs)))
(concat (propertize (char-to-string (+ idx #x2460))
'face 'tab-line-tab-inactive) ;; #x2776
name)))
(concat
(propertize
(char-to-string (+ idx #x2460)) ;; #x2776
'face (if (eq tab (current-buffer))
(if (mode-line-window-selected-p)
'tab-line-tab-current 'tab-line-tab)
'tab-line-tab-inactive))
name)))

(defun popper-tab-line--ensure ()
(pcase-let ((`(_ . ,buried-popups) (popper-echo--popup-info))
(open-popup (buffer-name)))
(pcase-let ((`(_ . ,buried-popups) (popper-echo--popup-info)))
(if (not buried-popups)
(tab-line-mode -1)
(unless tab-line-mode
(setq-local tab-line-tabs-function (lambda () (cdr (popper-echo--popup-info)))
(setq-local tab-line-tabs-function
(lambda ()
(cl-sort (cons (current-buffer) (cdr (popper-echo--popup-info)))
#'string< :key #'buffer-name))
tab-line-tab-name-format-function #'popper-tab-line--format)
(tab-line-mode 1)))
(popper-echo--activate-keymap (cons open-popup buried-popups)
#'popper-tab-line--ensure)))
(popper-echo--activate-keymap
(cl-sort (cons (current-buffer) buried-popups) #'string< :key #'buffer-name)
#'popper-tab-line--ensure)))

;;;###autoload
(define-minor-mode popper-tab-line-mode
Expand Down

0 comments on commit 28f1882

Please sign in to comment.