emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/popper 9a6af01f00 064/102: Dispatch keymap added to pop


From: ELPA Syncer
Subject: [elpa] externals/popper 9a6af01f00 064/102: Dispatch keymap added to popper-echo-names
Date: Fri, 8 Sep 2023 15:58:54 -0400 (EDT)

branch: externals/popper
commit 9a6af01f00c54ce98047e09d9b0c14bb7120c3ab
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>

    Dispatch keymap added to popper-echo-names
    
    Customize popper-dispatch-keys to configure.
    
    You can also kill popups by prepending the dispatch key with k.
---
 popper.el | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 84 insertions(+), 8 deletions(-)

diff --git a/popper.el b/popper.el
index 70570f0379..68d15c3b4e 100644
--- a/popper.el
+++ b/popper.el
@@ -224,6 +224,10 @@ This function should accept a
   '((t :inherit shadow))
   "Echo area face for buried popups.")
 
+(defface popper-dispatch-hint
+  '((t :inherit highlight))
+  "Echo area face for popper dispatch key hints.")
+
 (defvar popper--reference-names nil
   "List of buffer names whose windows are treated as popups.")
 
@@ -254,6 +258,19 @@ should be considered a popup")
 If `popper-group-function' is non-nil, these are
 grouped by the predicate `popper-group-function'.")
 
+(defvar popper-dispatch-keys nil
+  "List of keys used for dispatching to popup buffers.
+
+Each entry in the list can be a character or a string suitable
+for the kbd macro.
+
+Examples:
+'(?q ?w ?e ?r ?t ?y ?u ?i ?o ?p)
+'(\"M-1\" \"M-2\" \"M-3\" \"M-4\" \"M-5\")
+
+This variable has no effect when echo-area display of
+popups (using popper-echo-names) is turned off.")
+
 (defvar-local popper-popup-status nil
   "Identifies a buffer as a popup by its buffer-local value.
   Valid values are 'popup, 'raised, 'user-popup or nil.
@@ -661,13 +678,18 @@ If BUFFER is not specified act on the current buffer 
instead."
 ;; Notify in echo area:
 (defun popper-echo-names ()
   "Show popup list in echo area when cycling popups."
-  (let* ((group (when popper-group-function
+  (let* ((message-log-max nil)          ;No logging of these messages
+         (group (when popper-group-function
                   (funcall popper-group-function)))
          (buried-popups (thread-last (alist-get group 
popper-buried-popup-alist nil nil 'equal)
                           (mapcar #'cdr)
                           (cl-remove-if-not #'buffer-live-p)
                           (mapcar #'buffer-name)))
          (open-popup (buffer-name))
+         (dispatch-keys-extended (append popper-dispatch-keys
+                                     (make-list (max 0 (- (length 
buried-popups)
+                                                          (length 
popper-dispatch-keys)))
+                                                nil)))
          (popup-strings
           (cl-reduce #'concat
                      (cons
@@ -675,15 +697,69 @@ If BUFFER is not specified act on the current buffer 
instead."
                        (funcall (or popper-message-transform-function 
#'identity)
                                 open-popup)
                        'face 'popper-echo-area)
-                      (mapcar (lambda (b) (propertize
-                                      (concat ", " (funcall (or 
popper-message-transform-function
-                                                                #'identity)
-                                                            b))
-                                      'face 'popper-echo-area-buried))
-                              buried-popups)))))
+                      (cl-mapcar (lambda (key buf)
+                                   (concat
+                                    (propertize ", " 'face 
'popper-echo-area-buried)
+                                    (when key
+                                      (concat 
+                                       (propertize "[" 'face 
'popper-echo-area-buried)
+                                       (propertize (if (characterp key)
+                                                       (char-to-string key)
+                                                     key)
+                                                   'face 'popper-dispatch-hint)
+                                       (propertize "]" 'face 
'popper-echo-area-buried)))
+                                    (propertize (funcall (or 
popper-message-transform-function
+                                                             #'identity)
+                                                         buf)
+                                                'face 
'popper-echo-area-buried)))
+                                 dispatch-keys-extended
+                                 buried-popups)))))
     (if group
         (message "Group (%s): %s" group popup-strings)
-      (message "Popups: %s" popup-strings))))
+      (message "Popups: %s" popup-strings))
+    (set-transient-map (let ((map (make-sparse-keymap))
+                             (i 0))
+                         (dolist (keybind popper-dispatch-keys map)
+                           (define-key map (cond
+                                            ((characterp keybind)
+                                             (make-vector 1 keybind))
+                                            ((stringp keybind)
+                                             (kbd keybind)))
+                             (popper--dispatch-toggle i buried-popups))
+
+                           (define-key map
+                             (kbd
+                              (concat "k " (cond
+                                            ((characterp keybind)
+                                             (char-to-string keybind))
+                                            ((stringp keybind)
+                                             keybind))))
+                             (popper--dispatch-kill i buried-popups))
+                           (setq i (1+ i))))
+                       t)))
+
+(defun popper--dispatch-toggle (i buf-list)
+  "Returns a function to switch to buffer I in list BUF-LIST.
+
+This is used to create functions for switching between popups
+quickly."
+  (lambda ()
+    (interactive)
+    (popper-close-latest)
+    (display-buffer (nth i buf-list))
+    (popper--update-popups)
+    (popper-echo-names)))
+
+(defun popper--dispatch-kill (i buf-list)
+  "Kill buffer I in list BUF-LIST."
+  (lambda ()
+    (interactive)
+    (let* ((buf (nth i buf-list))
+           (win (get-buffer-window buf)))
+      (kill-buffer buf)
+      (popper--delete-popup win))
+    (popper--update-popups)
+    (popper-echo-names)))
 
 ;;;###autoload
 (define-minor-mode popper-mode



reply via email to

[Prev in Thread] Current Thread [Next in Thread]