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

    Add bookmark handler post-load callback functions and docs
---
 README.org  | 17 +++++++++++++++++
 bufferlo.el | 46 ++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/README.org b/README.org
index 09140ffbb6..16d463dbdb 100644
--- a/README.org
+++ b/README.org
@@ -637,6 +637,23 @@ bookmark set is loaded.
   (setq bufferlo-set-restore-tabs-reuse-init-frame nil) ; always make new 
frames
 #+end_src
 
+*** Bookmark handler hooks
+
+You can add your own functions to the following abnormal hooks to be
+called upon successful loading of tab, frame, and set bookmarks. See
+the docstrings for each function for its calling conventions.
+
+Example: You could use a tab handler function to set the tab-bar group
+for each loaded tab to its source bookmark name. While tab-bar does
+have ~tab-bar-tab-post-open-functions~, the bookmark context will not
+be available when those functions are called.
+
+#+begin_src emacs-lisp
+  (add-hook 'bufferlo-bookmark-tab-handler-functions #'tab-bookmark-fun)
+  (add-hook 'bufferlo-bookmark-frame-handler-functions #'frame-bookmark-fun)
+  (add-hook 'bufferlo-bookmark-set-handler-functions #'set-bookmark-fun)
+#+end_src
+
 *** Frame geometry options
 
 Bufferlo provides wrappers around Emacs frame functions to provide
diff --git a/bufferlo.el b/bufferlo.el
index 6561cd829e..3cff1722a2 100644
--- a/bufferlo.el
+++ b/bufferlo.el
@@ -515,6 +515,30 @@ These functions are also called when creating a frame 
bookmark, since a
 frame bookmark is a collection of tab bookmarks."
   :type 'hook)
 
+(defcustom bufferlo-bookmark-tab-handler-functions nil
+  "Abnormal hooks to call after a bookmark tab is handled.
+Each function takes the following arguments:
+  bookmark-name: source bookmark name
+  effective-bookmark-name: nil, if tab bookmark cleared
+  tab: the handled tab"
+  :type 'hook)
+
+(defcustom bufferlo-bookmark-frame-handler-functions nil
+  "Abnormal hooks to call after a bookmark frame is handled.
+Each function takes the following arguments:
+  bookmark-name: source bookmark name
+  effective-bookmark-name: nil, if frame bookmark cleared
+  new-frame-p: t if this is a new frame, nil if a reused frame
+  frame: the handled frame"
+  :type 'hook)
+
+(defcustom bufferlo-bookmark-set-handler-functions nil
+  "Abnormal hooks to call after a bookmark set is handled.
+Each function takes the following arguments:
+  bookmark-name: source bookmark name
+  set-bookmark-names: bookmark names handled"
+  :type 'hook)
+
 (defvar bufferlo--desktop-advice-active nil)
 (defvar bufferlo--desktop-advice-active-force nil)
 
@@ -2331,7 +2355,13 @@ this bookmark is embedded in a frame bookmark."
         (set-frame-parameter nil 'buried-buffer-list nil)
         (setf (alist-get 'bufferlo-bookmark-tab-name
                          (cdr (bufferlo--current-tab)))
-              (unless disconnect-tbm-p bookmark-name)))
+              (unless disconnect-tbm-p bookmark-name))
+
+        (run-hook-with-args
+         'bufferlo-bookmark-tab-handler-functions
+         bookmark-name
+         (unless disconnect-tbm-p bookmark-name)
+         (bufferlo--current-tab)))
 
       ;; Log message
       (unless (or no-message bufferlo--bookmark-handler-no-message)
@@ -2494,7 +2524,14 @@ the message after successfully restoring the bookmark."
 
          ;; Select and raise the restored frame outside the context
          ;; of with-selected-frame
-         (select-frame-set-input-focus frame)))
+         (select-frame-set-input-focus frame)
+
+         (run-hook-with-args
+          'bufferlo-bookmark-frame-handler-functions
+          bookmark-name
+          fbm
+          new-frame-p
+          frame)))
 
       (unless (or new-frame-p pop-up-frames)
         ;; Switch to the to-be-selected buffer in the current frame.
@@ -2844,6 +2881,11 @@ the message after successfully restoring the bookmark."
     (push `(,bookmark-name (bufferlo-bookmark-names . 
,bufferlo-bookmark-names))
           bufferlo--active-sets)
 
+    (run-hook-with-args
+     'bufferlo-bookmark-set-handler-functions
+     bookmark-name
+     bufferlo-bookmark-names)
+
     (unless (or no-message bufferlo--bookmark-handler-no-message)
       (message "Restored bufferlo bookmark set %s %s"
                bookmark-name bufferlo-bookmark-names))))

Reply via email to