[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dtache 4751b4d812 046/158: Implement a general timer fu
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dtache 4751b4d812 046/158: Implement a general timer function |
Date: |
Wed, 19 Jan 2022 18:57:45 -0500 (EST) |
branch: externals/dtache
commit 4751b4d8121a6f295f5e14d7f7ad09830d926332
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Implement a general timer function
This patch implements the dtache--session-timer function, which is a
general function that can be configured through the
dtache-timer-configuration variable. This function replaces the
previous solution for remote sessions, and at the same time provides a
function that can be reused to replace the notification function for
MacOS users.
---
README.org | 10 +++-------
dtache.el | 44 +++++++++++++++++---------------------------
2 files changed, 20 insertions(+), 34 deletions(-)
diff --git a/README.org b/README.org
index 5c7890231e..485cb7456d 100644
--- a/README.org
+++ b/README.org
@@ -166,13 +166,9 @@ Add the following to the configuration in order to take
advantage of this featur
#+begin_src elisp
(defun dtache--add-end-of-session-notification-advice (session)
"Trigger an event when SESSION transition to inactive."
- (let* ((timer)
- (callback
- (lambda ()
- (when (dtache--session-deactivated-p session)
- (dtache--session-final-update session)
- (cancel-timer timer)))))
- (setq timer (run-with-idle-timer 0.5 0.5 callback))))
+ (let ((dtache-timer-configuration
+ '(:seconds 0.5 :repeat 0.5 :function run-with-idle-timer)))
+ (dtache--session-timer session)))
(advice-add 'dtache--add-end-of-session-notification :override
#'dtache--add-end-of-session-notification-advice)
#+end_src
diff --git a/dtache.el b/dtache.el
index f89d5f0bed..538fe5b7f2 100644
--- a/dtache.el
+++ b/dtache.el
@@ -79,6 +79,8 @@
"Hooks to run when compiling a session.")
(defvar dtache-metadata-annotators-alist nil
"An alist of annotators for metadata.")
+(defvar dtache-timer-configuration '(:seconds 10 :repeat 60 :function
run-with-timer)
+ "A property list defining how often to run a timer.")
(defvar dtache-annotation-format
`((:width 3 :function dtache--active-str :face dtache-active-face)
@@ -156,8 +158,6 @@
"Mode of operation for dtach.")
(defvar dtache--sessions nil
"A list of sessions.")
-(defvar dtache--remote-session-timer nil
- "Timer object for remote polling.")
;;;; Data structures
@@ -504,24 +504,6 @@ Sessions running on current host or localhost are
updated."
(seq-filter #'dtache--session-active)
(seq-do #'dtache-setup-notification))))
-(defun dtache-update-remote-sessions ()
- "Update active remote sessions."
- (let ((predicate
- (lambda (s) (and (not (string= "localhost" (dtache--session-host s)))
- (dtache--session-active s)))))
-
- ;; Update sessions
- (thread-last (dtache--db-get-sessions)
- (seq-do (lambda (it)
- (if (funcall predicate it)
- (dtache-update-session it)
- it))))
-
- ;; Cancel timer if no active remote sessions
- (unless (> (seq-count predicate (dtache--db-get-sessions)) 0)
- (cancel-timer dtache--remote-session-timer)
- (setq dtache--remote-session-timer nil))))
-
(defun dtache-cleanup-host-sessions (host)
"Run cleanuup on HOST sessions."
(seq-do
@@ -600,7 +582,7 @@ Sessions running on current host or localhost are updated."
(defun dtache-setup-notification (session)
"Setup notification for SESSION."
(if (file-remote-p (dtache--session-working-directory session))
- (dtache--create-remote-session-timer)
+ (dtache--session-timer session)
(dtache--add-end-of-session-notification session)))
(defun dtache-dtach-command (session)
@@ -732,12 +714,6 @@ Sessions running on current host or localhost are
updated."
(file-exists-p
(dtache-session-file session 'log))))
-(defun dtache--create-remote-session-timer ()
- "Create a new remote session and trigger timer."
- (unless dtache--remote-session-timer
- (setq dtache--remote-session-timer
- (run-with-timer 10 60 #'dtache-update-remote-sessions))))
-
(defun dtache--session-header (session)
"Return header for SESSION."
(mapconcat
@@ -752,6 +728,20 @@ Sessions running on current host or localhost are
updated."
"")
"\n"))
+(defun dtache--session-timer (session)
+ "Create a timmer for SESSION according to `dtache-timer-configuration'."
+ (let* ((timer)
+ (callback
+ (lambda ()
+ (when (dtache--session-deactivated-p session)
+ (dtache--session-final-update session)
+ (cancel-timer timer)))))
+ (setq timer
+ (funcall (plist-get dtache-timer-configuration :function)
+ (plist-get dtache-timer-configuration :seconds)
+ (plist-get dtache-timer-configuration :repeat)
+ callback))))
+
;;;;; Database
(defun dtache--db-initialize ()
- [elpa] externals/dtache 763246bffe 026/158: Remove explicit dependency on dtache-env, (continued)
- [elpa] externals/dtache 763246bffe 026/158: Remove explicit dependency on dtache-env, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 087e8f4c73 019/158: Update README, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d574161815 042/158: Simplify buffer handling, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 1878cefb2f 038/158: Remove embark dependency, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 3c61776c7f 014/158: Fix dtache initialization, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 7c07950642 043/158: Implement better encapsulation of database, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 42569d1c5f 036/158: Update broken tests, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache ddf9bb6ade 039/158: Add action map example, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache c70c9366a5 028/158: Update test to test with/without dtache-env, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d5aa90356a 029/158: Add CHANGELOG to project, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4751b4d812 046/158: Implement a general timer function,
ELPA Syncer <=
- [elpa] externals/dtache 1bc60af5a0 040/158: Update changelog and readme, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d32b5752d6 034/158: Implement new deduplication strategy, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 36be431e18 032/158: Add workaround solution for MacOS users, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 80fca01eae 037/158: Update CHANGELOG, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 8769db2acb 051/158: Fix error in dtache-shell-attach, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache a36e89486f 055/158: Add package dtache-eshell, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache eab014faad 050/158: Version 0.2, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9a2f4a4d43 057/158: Introduce caching variable for candidates, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 02b93a3778 060/158: Minor cleanup, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache d693d4c386 065/158: Update README with links to blog posts, ELPA Syncer, 2022/01/19