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

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

[elpa] externals-release/activities 970ec6c377 042/103: Add: Bookmark su


From: ELPA Syncer
Subject: [elpa] externals-release/activities 970ec6c377 042/103: Add: Bookmark support
Date: Tue, 30 Jan 2024 03:57:49 -0500 (EST)

branch: externals-release/activities
commit 970ec6c37756f36e33f859683e9de91e7c1cfc4f
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>

    Add: Bookmark support
---
 README.org  |  4 ++++
 activity.el | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/README.org b/README.org
index 6b2c7368f5..21a2502fa3 100644
--- a/README.org
+++ b/README.org
@@ -68,6 +68,10 @@ If you choose to install it otherwise, you'll need to load 
both the ~activity~ a
 6. Return to the original activity state with ~activity-revert~ (~C-x C-a g~).
 7. Suspend the activity with ~activity-suspend~ (~C-x C-a s~) (which saves its 
last state and closes its frame/tab).
 
+** Bookmarks
+
+When option ~activity-bookmark-store~ is enabled, an Emacs bookmark is stored 
when a new activity is made.  This allows the command ~bookmark-jump~ (~C-x r 
b~) to be used to resume an activity (helping to universalize the bookmark 
system).
+
 * FAQ
 
 + How is this different from 
[[https://github.com/alphapapa/burly.el][Burly.el]] or 
[[https://github.com/alphapapa/bufler.el/][Bufler.el]]? :: Burly is a 
well-polished tool for restoring window and frame configurations, which could 
be considered an incubator for some of the ideas furthered here.  Bufler's 
~bufler-workspace~ library uses Burly to provide some similar functionality, 
which is at an exploratory stage.  ~activity~ hopes to provide a longer-term 
solution more suitable for inte [...]
diff --git a/activity.el b/activity.el
index e264fab880..6ed4425f65 100644
--- a/activity.el
+++ b/activity.el
@@ -208,6 +208,22 @@ persisted."
   "Prefix applied to activity names in frames/tabs."
   :type 'string)
 
+(defcustom activity-bookmark-store t
+  "Store a bookmark when making a new activity.
+This is merely for convenience, offering a way to help unify the
+`bookmark' and `activity' interfaces (i.e. allowing
+`bookmark-jump' to open an activity rather than requiring the use
+of `activity-resume').
+
+Such bookmarks merely point to an activity name; they do not
+contain the actual activity metadata, so if an activity is
+discarded, such a bookmark could become stale."
+  :type 'boolean)
+
+(defcustom activity-bookmark-name-prefix "Activity: "
+  "Prefix for activity bookmark names."
+  :type 'string)
+
 (defcustom activity-window-persistent-parameters
   (list (cons 'header-line-format 'writable)
         (cons 'mode-line-format 'writable)
@@ -253,6 +269,8 @@ Called with one argument, the activity."
   (let ((activity (make-activity :name name)))
     (activity--set activity)
     (activity-save activity :defaultp t :lastp t)
+    (when activity-bookmark-store
+      (activity-bookmark-store activity))
     (activity--switch activity)
     activity))
 
@@ -308,6 +326,7 @@ In order to be safe for `kill-emacs-hook', this demotes 
errors."
 (defun activity-discard (activity)
   "Discard ACTIVITY and its state.
 It will not be recoverable."
+  ;; TODO: Discard relevant bookmarks when `activity-bookmark-store' is 
enabled.
   (interactive (list (activity-completing-read :prompt "Discard activity: ")))
   (ignore-errors
     ;; FIXME: After fixing all the bugs, remove ignore-errors.
@@ -602,22 +621,25 @@ PROMPT is passed to `completing-read', which see."
     (or (map-elt activity-activities name)
         (make-activity :name name))))
 
-;; (defun activity--bookmarks ()
-;;   "Return list of activity bookmarks."
-;;   (bookmark-maybe-load-default-file)
-;;   (mapcar (lambda (bookmark)
-;;             (bookmark-prop-get bookmark 'activity))
-;;           (cl-remove-if-not (pcase-lambda (`(,_name . ,(map handler)))
-;;                               (equal #'activity-bookmark-handler handler))
-;;                             bookmark-alist)))
-
 (cl-defun activity-names (&optional (activities activity-activities))
   "Return list of names of ACTIVITIES."
   (map-keys activities))
 
+;;;; Bookmark support
+
+(require 'bookmark)
+
+(defun activity-bookmark-store (activity)
+  "Store a `bookmark' record for ACTIVITY."
+  (bookmark-maybe-load-default-file)
+  (let* ((activity-name (activity-name activity))
+         (bookmark-name (concat activity-bookmark-name-prefix activity-name))
+         (props `((activity-name . ,activity-name))))
+    (bookmark-store bookmark-name props nil)))
+
 (defun activity-bookmark-handler (bookmark)
   "Switch to BOOKMARK's activity."
-  (activity--switch (map-elt activity-activities (car bookmark))))
+  (activity-resume (map-elt activity-activities (bookmark-prop-get bookmark 
'activity-name))))
 
 (defun activity--buffer-local-variables (variables)
   "Return alist of buffer-local VARIABLES for current buffer.



reply via email to

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