branch: externals/popper commit c6b78fdd546e19582fa2195cf51f6753c45e7c03 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
popper-echo: Add popper-tab-line-mode popper-echo.el (popper-tab-line-format, popper-tab-line-ensure, popper-tab-line-mode): Add an alternative to `popper-echo-mode` to display other popups in the tab-line of a popup. Popper-echo's dispatch keys will still work the same. To use this feature turn on `popper-tab-line-mode`. Update commentary. --- popper-echo.el | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 89 insertions(+), 9 deletions(-) diff --git a/popper-echo.el b/popper-echo.el index b0401d76b1..ef80f8f92e 100644 --- a/popper-echo.el +++ b/popper-echo.el @@ -25,13 +25,16 @@ ;;; Commentary: -;; Popper-echo is a minor-mode to display a list of popup names in the echo area -;; when toggling or cycling popups. These popups can be accessed directly using -;; dispatch keybinds. See Popper for how to classify a buffer as a popup. - -;; COMMANDS: - -;; popper-echo-mode : Turn on the echo area display +;; This library provides two minor-modes to preview the list of relevant popup +;; names when toggling or cycling popups. These popups can be accessed directly +;; using dispatch keybinds. See Popper for how to classify a buffer as a popup. +;; +;; `popper-echo-mode' displays the list of popups in the echo area when toggling +;; or cycling popups. +;; +;; `popper-tab-line-mode' displays the list of popups in the tab-line of the +;; active popup when toggling or cycling them. NOTE: This feature is +;; experimental. ;; CUSTOMIZATION: @@ -39,10 +42,10 @@ ;; showing a list of popups ;; ;; `popper-echo-dispatch-keys': A list of strings or characters representing the -;; keybindings to access popups shown in the echo area. +;; keybindings to access popups shown in the echo area or tab-line. ;; ;; `popper-echo-dispatch-persist': A boolean to control whether the dispatch -;; menu stays open after choosing a popup. +;; keymap stays active after using a dispatch key. ;; ;; `popper-echo-transform-function': A function to transform the display of ;; these popups, such as by truncating buffer names, etc. @@ -245,6 +248,8 @@ Each command in the keymap calls the function REPEAT afterwards." (propertize "..." 'face 'popper-echo-area-buried))))) (popper-echo--activate-keymap (cons open-popup buried-popups) #'popper-echo))) +(defvar popper-tab-line-mode "popper-echo") + ;;;###autoload (define-minor-mode popper-echo-mode "Toggle Popper Echo mode. @@ -260,9 +265,84 @@ To define buffers as popups and customize popup display, see :group 'popper (if popper-echo-mode (progn + (when popper-tab-line-mode + (message "`popper-echo-mode'. is incompatible with `popper-tab-line-mode' Disabling `popper-tab-line-mode'.") + (popper-tab-line-mode -1)) (add-hook 'popper-open-popup-hook 'popper-echo) (unless popper-mode (popper-mode 1))) (remove-hook 'popper-open-popup-hook 'popper-echo))) +;;; Notify using tab-line +(declare-function tab-line-mode "tab-line") +(declare-function tab-line-tab-name-format-default "tab-line") +(defvar tab-line-tab-name-format-function) +(defvar tab-line-tabs-function) +(defvar tab-line-mode) + +(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)) ;; #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))) + (if (not buried-popups) + (tab-line-mode -1) + (unless tab-line-mode + (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) + (when popper-echo-transform-function + (setq-local tab-line-tab-name-function + (lambda (buf _) (funcall popper-echo-transform-function + (buffer-name buf))))) + (tab-line-mode 1))) + (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 + "Toggle Popper Tab Line Mode. +Show popup names in cycling order in the tab-line of the popup +window when performing an action that involves showing a popup. +These popups can be accessed directly or acted upon by using +quick keys (see `popper-echo-dispatch-keys'). + +To define buffers as popups and customize popup display, see +`popper-mode'." + :global t + :lighter "" + :group 'popper + (if popper-tab-line-mode + (progn + (require 'tab-line) + (when popper-echo-mode + (message "`popper-tab-line-mode' is incompatible with `popper-echo-mode'. Disabling `popper-echo-mode'.") + (popper-echo-mode -1)) + (add-hook 'popper-open-popup-hook #'popper-tab-line--ensure) + (unless popper-mode (popper-mode 1))) + (remove-hook 'popper-open-popup-hook #'popper-tab-line--ensure) + ;; Clear tab-lines + (mapc + (pcase-lambda (`(_ . ,buf)) + (when (buffer-live-p buf) + (with-current-buffer buf + (kill-local-variable 'tab-line-tabs-function) + (kill-local-variable 'tab-line-tab-name-format-function) + (unless global-tab-line-mode (tab-line-mode -1))))) + (mapcan #'cdr (cons (cons nil popper-open-popup-alist) + popper-buried-popup-alist))) + (force-mode-line-update))) + (provide 'popper-echo) ;;; popper-echo.el ends here