Skip to content

Popup decoration

karthink edited this page Feb 6, 2023 · 5 revisions

Better popper-echo display

If you use popper-echo and want a prettier echo-area display when you toggle or cycle through popups:

(defvar popper-echo--propertized-names nil
  "Alist of popup buffer names and their shortened, propertized
display names.")

(defun popper-message-shorten (full-name)
  (let ((name (file-name-nondirectory full-name)))
    (or (alist-get name popper-echo--propertized-names nil nil #'string=)
        (let ((short-name
               (cond
                ((string= "*Messages*" name)
                 (concat (propertize "LOG " 'face 'default)
                         (propertize name 'face 'popper-echo-area-buried)))
                ((string-match "^\\*[hH]elpful.*?: \\(.*\\)\\*$" name)
                 (concat (propertize "HLP " 'face '(:inherit link :underline nil))
                         (propertize (match-string 1 name) 'face 'popper-echo-area-buried)))
                ((string-match "^\\*Help:?\\(.*\\)\\*$" name)
                 (concat (propertize "HLP" 'face
                                     '(:inherit link :underline nil))
                         (propertize (match-string 1 name)
                                     'face 'popper-echo-area-buried)))
                ((string-match "^\\*\\(e?\\)shell:? ?\\(.*\\)\\*$" name)
                 (concat (if (string-empty-p (match-string 1 name))
                             (propertize "SH" 'face 'success)
                           (propertize "ESH" 'face 'success))
                         (unless (string-empty-p (match-string 2 name)) " ")
                         (propertize (match-string 2 name)
                                     'face 'popper-echo-area-buried)))
                ((string-match "^\\*\\(.*?\\)-\\(e?\\)shell\\*$" name)
                 (concat (if (string-empty-p (match-string 2 name))
                             (propertize "SH" 'face 'success)
                           (propertize "ESH" 'face 'success))
                         (unless (string-empty-p (match-string 1 name)) " ")
                         (propertize (match-string 1 name)
                                     'face 'popper-echo-area-buried)))
                ((string-match "^[*]?\\(.*?\\) *\\(?:[Oo]utput\\|Command\\)\\*$" name)
                 (concat (propertize "OUT "
                                     'face '(:inherit warning))
                         (propertize (match-string 1 name)
                                     'face 'popper-echo-area-buried)))
                ((string-match "^\\*\\(.*?\\)[ -][Ll]og\\*$" name)
                 (concat (propertize "LOG "
                                     ;; '(:inherit link-visited :underline nil)
                                     'face 'default)
                         (propertize (match-string 1 name)
                                     'face 'popper-echo-area-buried)))
                ((or (string-match "^\\*[Cc]ompil\\(?:e\\|ation\\)\\(.*\\)\\*$" name)
                     (string-match
                      "^\\*\\(.*?\\)[ -]?\\(?:byte\\)?[ -]?[Cc]ompil\\(?:e\\|ation\\)\\*$" name))
                 (concat (propertize "COM "
                                     'face '(:inherit link-visited :underline nil :weight normal))
                         (propertize (match-string 1 name) 'face 'popper-echo-area-buried)))
                ((string-match "^[*]?\\(?:e?shell.*\\|v?term\\).*\\*$" name)
                 (concat (propertize "RPL " 'face 'success) name))
                (t (propertize name 'face 'popper-echo-area-buried)))))
          (cdar (push (cons name short-name) popper-echo--propertized-names))))))

(setq popper-echo-transform-function #'popper-message-shorten)
Clone this wiki locally