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

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

[elpa] externals-release/activities 9de2334d94 011/103: Tabs WIP


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

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

    Tabs WIP
---
 activity-tabs.el | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 activity.el      | 55 ++++++++++-----------------------------
 2 files changed, 92 insertions(+), 42 deletions(-)

diff --git a/activity-tabs.el b/activity-tabs.el
new file mode 100644
index 0000000000..5492ee97bc
--- /dev/null
+++ b/activity-tabs.el
@@ -0,0 +1,79 @@
+;;; activity-tabs.el --- Integrate activities with tabs  -*- lexical-binding: 
t; -*-
+
+;; Copyright (C) 2024  Free Software Foundation, Inc.
+
+;; Author: Adam Porter <adam@alphapapa.net>
+;; Keywords: convenience
+;; Version: 0.1-pre
+;; Package-Requires: ((emacs "29.1"))
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This library integrates activities with `tab-bar-mode' tabs.
+
+;;; Code:
+
+;;;; Requirements
+
+(require 'activity)
+
+;;;; Customization
+
+(defgroup activity-tabs nil
+  "Integrates activities and tabs."
+  :group 'activity)
+
+(defcustom activity-tabs-before-resume-functions
+  '(activity-tabs-switch-to-tab)
+  "Functions called before resuming an activity.
+Each is called with one argument, the activity."
+  :type 'hook)
+
+(defcustom activity-tabs-prefix "α:"
+  "Prepended to activity names in tabs."
+  :type 'string)
+
+;;;; Mode
+
+;;;###autoload
+(define-minor-mode activity-tabs-mode
+  "Integrate Activity with `tab-bar-mode'.
+When active, activities are opened in new tabs and named
+accordingly."
+  :global t
+  :group 'activity
+  (if activity-tabs-mode
+      (progn
+        (advice-add #'activity-resume :before #'activity-tabs-before-resume))
+    (advice-remove #'activity-resume #'activity-tabs-before-resume)))
+
+;;;; Functions
+
+(defun activity-tabs-before-resume (activity)
+  "Called before resuming ACTIVITY."
+  (run-hook-with-args activity-tabs-before-resume-functions activity))
+
+(defun activity-tabs-switch-to-tab (activity)
+  "Switch to a tab for ACTIVITY."
+  (pcase-let* (((cl-struct activity name) activity)
+               (tab-name (concat activity-tabs-prefix name)))
+    (tab-bar-switch-to-tab tab-name)))
+
+;;;; Footer
+
+(provide 'activity-tabs)
+
+;;; activity-tabs.el ends here
diff --git a/activity.el b/activity.el
index 27a2bb9718..371c3f7491 100644
--- a/activity.el
+++ b/activity.el
@@ -181,6 +181,16 @@ See Info node `(elisp)Window Parameters'.  See also option
                 :value-type (choice (const :tag "Not saved" nil)
                                     (const :tag "Saved" writable))))
 
+(defcustom activity-after-resume-functions nil
+  "Functions called after resuming an activity.
+Called with one argument, the activity."
+  :type 'hook)
+
+(defcustom activity-before-resume-functions nil
+  "Functions called before resuming an activity.
+Called with one argument, the activity."
+  :type 'hook)
+
 (cl-defstruct activity
   "FIXME: Docstring."
   name default last etc)
@@ -197,7 +207,9 @@ If RESETP (interactively, with universal prefix), reset to
 ACTIVITY's default state; otherwise, resume its last state, if
 available."
   (interactive (list (activity-completing-read) :resetp current-prefix-arg))
-  (activity-open activity :state (if resetp 'default 'last)))
+  (run-hook-with-args 'activity-before-resume-functions activity)
+  (activity-open activity :state (if resetp 'default 'last))
+  (run-hook-with-args 'activity-after-resume-functions activity))
 
 (defun activity-suspend (activity)
   "Suspend ACTIVITY.
@@ -474,47 +486,6 @@ ignored."
            when (buffer-local-boundp variable (current-buffer))
            collect (cons variable (buffer-local-value variable 
(current-buffer)))))
 
-;;;; Tabs mode
-
-;; When this mode is active, activities are loaded into `tab-bar-mode'
-;; tabs.
-
-;;;###autoload
-(define-minor-mode activity-tabs-mode
-  "Integrate Activity with `tab-bar-mode'.
-When active, activities are opened in new tabs and named
-accordingly."
-  :global t
-  :group 'activity)
-
-(cl-defmethod activity-open (activity &context (activity-tabs-mode (eql t))
-                                      &key (state 'last))
-  "Open ACTIVITY.
-Its STATE is loaded into the current frame.  Used when
-ACTIVITY-TABS-MODE is active."
-  ;; TODO: Use a hook to optionally open a new frame.
-  ;; TODO: Deduplicate this with the method for when the mode is inactive.
-  (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-defmethod activity-close (activity &context (activity-tabs-mode (eql t)))
-  "Close ACTIVITY.
-Its state is not saved, and its frames, windows, and tabs are
-closed.  Used when ACTIVITY-TABS-MODE is active."
-  (pcase-let* (((cl-struct activity name) activity)
-               (tab (cl-find-if
-                     (lambda (tab)
-                       (equal name (activity-name (alist-get 'activity tab))))
-                     (funcall tab-bar-tabs-function)))
-               (tab-name (alist-get 'name tab)))
-    ;; TODO: Set tab parameter when resuming.
-    (tab-bar-close-tab-by-name tab-name)))
-
 ;;;; Footer
 
 (provide 'activity)



reply via email to

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