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

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

[elpa] externals-release/activities a337656530 014/103: WIP


From: ELPA Syncer
Subject: [elpa] externals-release/activities a337656530 014/103: WIP
Date: Tue, 30 Jan 2024 03:57:46 -0500 (EST)

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

    WIP
---
 activity-tabs.el | 24 ++++++++++++++++----
 activity.el      | 69 +++++++++++++++++++++++++++++++++++---------------------
 2 files changed, 63 insertions(+), 30 deletions(-)

diff --git a/activity-tabs.el b/activity-tabs.el
index e47e9b9902..3be864d36a 100644
--- a/activity-tabs.el
+++ b/activity-tabs.el
@@ -30,6 +30,8 @@
 
 (require 'activity)
 
+(require 'tab-bar)
+
 ;;;; Customization
 
 (defgroup activity-tabs nil
@@ -59,12 +61,20 @@ accordingly."
       (progn
         (tab-bar-mode 1)
         (advice-add #'activity-resume :before #'activity-tabs-before-resume)
-        (advice-add #'activity-active-p :override 
#'activity-tabs-activity-active-p))
+        (advice-add #'activity-active-p :override 
#'activity-tabs-activity-active-p)
+        (advice-add #'activity--set :override #'activity-tabs-activity--set))
     (advice-remove #'activity-resume #'activity-tabs-before-resume)
-    (advice-remove #'activity-active-p #'activity-tabs-activity-active-p)))
+    (advice-remove #'activity-active-p #'activity-tabs-activity-active-p)
+    (advice-remove #'activity--set #'activity-tabs-activity--set)))
 
 ;;;; Functions
 
+(defun activity-tabs-activity--set (activity)
+  "Set the current activity.
+Sets the current tab's `activity' parameter to ACTIVITY."
+  (let ((tab (tab-bar--current-tab-find)))
+    (setf (alist-get 'activity tab) activity)))
+
 (defun activity-tabs-activity-active-p (activity)
   "Return non-nil if ACTIVITY is active.
 That is, if any tabs have an `activity' parameter whose
@@ -82,8 +92,14 @@ activity's name is NAME."
 (defun activity-tabs-switch-to-tab (activity)
   "Switch to a tab for ACTIVITY."
   (pcase-let* (((cl-struct activity name) activity)
-               (name (string-remove-prefix activity-bookmark-prefix name))
-               (tab-name (concat activity-tabs-prefix name)))
+               (tab (cl-find-if (lambda (tab)
+                                  (when-let ((tab-activity (alist-get 
'activity tab)))
+                                    (equal name (activity-name tab-activity))))
+                                (funcall tab-bar-tabs-function))) 
+               (tab-name (if tab
+                             (alist-get 'name tab)
+                           (concat activity-tabs-prefix
+                                   (string-remove-prefix 
activity-bookmark-prefix name)))))
     (tab-bar-switch-to-tab tab-name)))
 
 ;;;; Footer
diff --git a/activity.el b/activity.el
index 55bfcda9e5..acfe1afef2 100644
--- a/activity.el
+++ b/activity.el
@@ -201,6 +201,17 @@ Called with one argument, the activity."
 
 ;;;; Commands
 
+(defun activity-new (name)
+  "Switch to a new, empty activity named NAME."
+  ;; Not sure if this is needed, but let's experiment.
+  (interactive (list (read-string "New activity name: ")))
+  (when (member name (activity-names))
+    (user-error "Activity named %S already exists" name))
+  (scratch-buffer)
+  (delete-other-windows)
+  (let ((activity (make-activity :name name)))
+    (run-hook-with-args 'activity-after-resume-functions activity)))
+
 (cl-defun activity-resume (activity &key resetp)
   "Resume ACTIVITY.
 If RESETP (interactively, with universal prefix), reset to
@@ -219,31 +230,6 @@ closed."
   (activity-save activity :lastp t)
   (activity-close activity))
 
-(cl-defun activity-open (activity &key (state 'last))
-  "Open ACTIVITY.
-Its STATE is loaded into the current frame."
-  (pcase-let (((cl-struct activity name default last) activity))
-    (pcase state
-      ('default (activity--windows-set (activity-state-window-state default)))
-      ('last (if last
-                 (activity--windows-set (activity-state-window-state last))
-               (activity--windows-set (activity-state-window-state default))
-               (message "Activity %S has no last state.  Resuming default." 
name))))))
-
-(cl-defun activity-close (activity)
-  "Close ACTIVITY.
-Its state is not saved, and its frames, windows, and tabs are
-closed."
-  (pcase-let* (((cl-struct activity name) activity)
-               (frame (cl-find-if
-                       (lambda (frame)
-                         (equal name (activity-name (frame-parameter frame 
'activity))))
-                       (frame-list))))
-    ;; TODO: Set frame parameter when resuming.
-    (unless (length= 1 (frame-list))
-      ;; Not only frame: delete it.
-      (delete-frame frame))))
-
 (cl-defun activity-save (activity &key defaultp lastp)
   "Save ACTIVITY's states.
 If DEFAULTP, save its default state; if LASTP, its last."
@@ -297,8 +283,39 @@ accordingly."
 
 ;;;; Functions
 
+(cl-defun activity-open (activity &key (state 'last))
+  "Open ACTIVITY.
+Its STATE is loaded into the current frame."
+  (pcase-let (((cl-struct activity name default last) activity))
+    (pcase state
+      ('default (activity--windows-set (activity-state-window-state default)))
+      ('last (if last
+                 (activity--windows-set (activity-state-window-state last))
+               (activity--windows-set (activity-state-window-state default))
+               (message "Activity %S has no last state.  Resuming default." 
name))))
+    (activity--set activity)))
+
+(defun activity--set (activity)
+  "Set the current activity.
+Sets the current frame's `activity' parameter to ACTIVITY."
+  (set-frame-parameter nil 'activity activity))
+
+(cl-defun activity-close (activity)
+  "Close ACTIVITY.
+Its state is not saved, and its frames, windows, and tabs are
+closed."
+  (pcase-let* (((cl-struct activity name) activity)
+               (frame (cl-find-if
+                       (lambda (frame)
+                         (equal name (activity-name (frame-parameter frame 
'activity))))
+                       (frame-list))))
+    ;; TODO: Set frame parameter when resuming.
+    (unless (length= 1 (frame-list))
+      ;; Not only frame: delete it.
+      (delete-frame frame))))
+
 (defun activity-state ()
-  "Return the current activity's state."
+  "Return an activity state for the current frame."
   (make-activity-state
    :window-state (activity--window-state (selected-frame))))
 



reply via email to

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