branch: externals/bufferlo
commit f8f269035fe1099e1b278453682c10dcc5f6ca4d
Author: shipmints <shipmi...@gmail.com>
Commit: shipmints <shipmi...@gmail.com>

    Add bufferlo-set-list-interactive and docs
    
    This command allows the user to enumerate the bookmarks within one or
    more active bookmark sets. The current actions supported are raising
    the selected bookmark via mouse or <RET>, or quitting.
    
    Until now, there was no easy way to inspect a bookmark set.
---
 README.org  | 19 ++++++++++++-----
 bufferlo.el | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/README.org b/README.org
index 48edfb18e3..8232e01a03 100644
--- a/README.org
+++ b/README.org
@@ -337,6 +337,13 @@ rename or delete references to those bookmarks within 
bookmark sets.
   the specified bookmark sets. This closes their constituent bookmarks
   and kills their buffers.
 
+- ~bufferlo-set-list-interactive~ (alias ~bufferlo-set-list~): List
+  the constituent bookmarks of the selected active sets in a
+  ~special-mode~ buffer and pop to it. The display shows each
+  bookmark's name, its type, the frame it's currently on, and, if a
+  tab bookmark, its tab number. Typing ~<RET>~ or clicking ~mouse-1~
+  will raise the selected bookmark. Type "q" to quit.
+
 Notes:
 
 - To curate a saved bookmark set, invoke
@@ -1015,11 +1022,11 @@ remain in force until they are saved if this policy is 
set to t.
      ("C-z C-b" . bufferlo-ibuffer)
      ("C-z M-C-b" . bufferlo-ibuffer-orphans)
      ("C-z b -" . bufferlo-remove)
-     ;; interactive
-     ("C-z i l" . bufferlo-bms-load)
-     ("C-z i s" . bufferlo-bms-save)
-     ("C-z i c" . bufferlo-bms-close)
-     ("C-z i r" . bufferlo-bm-raise)
+     ;; general bookmark (interactive)
+     ("C-z b l" . bufferlo-bms-load)
+     ("C-z b s" . bufferlo-bms-save)
+     ("C-z b c" . bufferlo-bms-close)
+     ("C-z b r" . bufferlo-bm-raise)
      ;; dwim frame or tab bookmarks
      ("C-z d s" . bufferlo-bm-save)
      ("C-z d l" . bufferlo-bm-load)
@@ -1043,6 +1050,7 @@ remain in force until they are saved if this policy is 
set to t.
      ("C-z s l" . bufferlo-set-load)                  ; load
      ("C-z s 0" . bufferlo-set-close)                 ; kill
      ("C-z s c" . bufferlo-set-clear)                 ; clear
+     ("C-z s L" . bufferlo-set-list)                  ; list contents of 
selected active sets
      )
     :init
     ;; these must be set before the bufferlo package is loaded
@@ -1081,6 +1089,7 @@ remain in force until they are saved if this policy is 
set to t.
                   "\\)\\*\\)"
                   "\\|" (rx "*" (1+ anything) " Ibuffer*")
                   "\\|" (rx "*helpful " (1+ anything) "*")
+                  "\\|" (rx "*tramp" (1+ anything) "*")
                   "\\|" (rx "magit" (* anything) ": " (1+ anything))
                   "\\'"))
     (setq bufferlo-kill-buffers-prompt t)
diff --git a/bufferlo.el b/bufferlo.el
index a8df352085..dbd82ecaab 100644
--- a/bufferlo.el
+++ b/bufferlo.el
@@ -972,6 +972,7 @@ string, FACE is the face for STR."
      ["Save Current..."     bufferlo-set-save-curr       :help "Save the 
specified bookmark sets"]
      ["Close/Kill..."       bufferlo-set-close           :help "Close the 
specified bookmark sets (kills frames, tabs, buffers)"]
      ["Clear..."            bufferlo-set-clear           :help "Clear the 
specified bookmark set (does not kill frames, tabs, buffers)"]
+     ["List..."             bufferlo-set-list            :help "List the 
bookmarks in specified active bookmark sets"]
      )
     ;; "--"
     ;; ["Bookmark Management" :active nil]
@@ -2802,6 +2803,70 @@ This closes their associated bookmarks and kills their 
buffers."
       (bufferlo--close-active-bookmarks abm-names-to-close abms)
       (bufferlo--set-clear comps))))
 
+(defvar-keymap bufferlo-set-list-mode-map
+  :parent special-mode-map
+  "<mouse-1>" #'bufferlo--set-list-raise-bookmark-mouse
+  "RET"       #'bufferlo--set-list-raise-bookmark-kb)
+
+(define-derived-mode bufferlo-set-list-mode special-mode "bufferlo set list"
+  "Major mode for bufferlo set list.")
+
+(defun bufferlo--set-list-raise-bookmark-mouse (event)
+  (interactive "e")
+  (let* ((pos (event-start event))
+         (bname (get-text-property (posn-point pos) 'bookmark-name)))
+    (quit-window)
+    (bufferlo--bookmark-raise-by-name bname)))
+
+(defun bufferlo--set-list-raise-bookmark-kb ()
+  (interactive)
+  (let ((bname (get-text-property (point) 'bookmark-name)))
+    (quit-window)
+    (bufferlo--bookmark-raise-by-name bname)))
+
+(defconst bufferlo--set-list-buffer-name " *bufferlo set list*")
+
+(defun bufferlo-set-list-interactive ()
+  "Enumerate the bookmarks in active bookmark sets."
+  (interactive)
+  (let* ((candidates (mapcar #'car bufferlo--active-sets))
+         (comps (bufferlo--bookmark-completing-read "Select sets to enumerate: 
" candidates)))
+    (let* ((abms (bufferlo--active-bookmarks))
+           (abm-names (mapcar #'car abms)))
+      (with-current-buffer (get-buffer-create bufferlo--set-list-buffer-name)
+        (let ((buffer-undo-list t))
+          (read-only-mode -1)
+          (erase-buffer))
+        (insert "----- Bufferlo Bookmarks Sets -----"
+                "\n"
+                "(RET or mouse-1 to raise a bookmark, q to quit)"
+                "\n" "\n")
+        (dolist (set-name (sort comps #'string<))
+          (insert (format "Set \"%s\"" set-name) ":"
+                  "\n")
+          (dolist (bname (sort
+                          (alist-get 'bufferlo-bookmark-names
+                                     (assoc set-name bufferlo--active-sets))
+                          #'string<))
+            (when-let* ((abm (cadr (assoc bname abms))))
+              (let* ((type (alist-get 'type abm))
+                     (frame (alist-get 'frame abm))
+                     (fname (or (frame-parameter frame 'explicit-name)
+                                (frame-parameter frame 'name)))
+                     (tab-number (alist-get 'tab-number abm))
+                     (text (format "  %-20s %-8s %-25s %s"
+                                   (truncate-string-to-width bname 20 nil nil 
t)
+                                   (alist-get type 
bufferlo--bookmark-type-names)
+                                   (truncate-string-to-width fname 25 nil nil 
t)
+                                   (if tab-number (format "tab:%d" tab-number) 
""))))
+                (put-text-property 0 (length text) 'bookmark-name bname text)
+                (insert text "\n"))))
+          (insert "\n"))
+        (insert "----- END -----")
+        (bufferlo-set-list-mode)
+        (goto-char (point-min))
+        (pop-to-buffer (current-buffer) nil 'norecord)))))
+
 (defvar bufferlo--bookmark-handlers
   (list
    #'bufferlo--bookmark-tab-handler
@@ -2809,6 +2874,11 @@ This closes their associated bookmarks and kills their 
buffers."
    #'bufferlo--bookmark-set-handler)
   "Bufferlo bookmark handlers.")
 
+(defconst bufferlo--bookmark-type-names
+  '((tbm . "B-Tab")
+    (fbm . "B-Frame")
+    (sbm . "B-Set")))
+
 (defun bufferlo--bookmark-get-names (&rest handlers)
   "Get the names of all existing bookmarks for HANDLERS."
   (bookmark-maybe-load-default-file)
@@ -3646,6 +3716,7 @@ OLDFN BOOKMARK-NAME BATCH"
 (defalias 'bufferlo-set-load            'bufferlo-set-load-interactive)
 (defalias 'bufferlo-set-close           'bufferlo-set-close-interactive)
 (defalias 'bufferlo-set-clear           'bufferlo-set-clear-interactive)
+(defalias 'bufferlo-set-list            'bufferlo-set-list-interactive)
 
 (provide 'bufferlo)
 

Reply via email to