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

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

[elpa] externals/detached 3510b3b9cf 2/5: Add variable for if database s


From: ELPA Syncer
Subject: [elpa] externals/detached 3510b3b9cf 2/5: Add variable for if database should be updated
Date: Fri, 23 Sep 2022 05:57:29 -0400 (EDT)

branch: externals/detached
commit 3510b3b9cf3d05294cbe6b07d90aa97025999951
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>

    Add variable for if database should be updated
    
    This variable makes it possible to disable the updating of the
    database by let binding the detached--update-database. This allows for
    smarter code when for example deleting multiple sessions through the
    detached list interface. Then updating the database can be done
    explicitly at after all sessions have been deleted.
---
 detached-list.el      | 12 +++++++-----
 detached.el           | 36 +++++++++++++++++++++---------------
 test/detached-test.el |  2 +-
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/detached-list.el b/detached-list.el
index b9770abf57..d001477803 100644
--- a/detached-list.el
+++ b/detached-list.el
@@ -308,11 +308,13 @@ If prefix-argument is provided unmark instead of mark."
   (when (y-or-n-p (if detached-list--marked-sessions
                       "Delete all marked sessions? "
                     "Delete session at point? "))
-    (seq-do
-     (lambda (session)
-       (detached-list--unmark-session session)
-       (detached-delete-session session))
-     (detached-list--get-marked-or-current-sessions))
+    (let ((detached--update-database nil))
+      (seq-do
+       (lambda (session)
+         (detached-list--unmark-session session)
+         (detached-delete-session session))
+       (detached-list--get-marked-or-current-sessions)))
+    (detached--db-update-sessions)
     (detached-list-revert)))
 
 (defun detached-list-mark-session ()
diff --git a/detached.el b/detached.el
index 82c64d7195..2ee30b7cdb 100644
--- a/detached.el
+++ b/detached.el
@@ -298,6 +298,9 @@ This version is encoded as [package-version].[revision].")
 (defvar detached--annotation-widths nil
   "An alist of widths to use for annotation.")
 
+(defvar detached--update-database t
+  "Update the database when value is t.")
+
 (defconst detached--shell-command-buffer "*Detached Shell Command*"
   "Name of the `detached-shell-command' buffer.")
 
@@ -736,9 +739,10 @@ Optionally SUPPRESS-OUTPUT."
     ;; Initialize accessible sessions
     (let ((detached--current-emacsen (detached--active-detached-emacsen)))
       (detached--update-detached-emacsen)
-      (thread-last (detached--db-get-sessions)
-                   (seq-filter #'detached--session-accessible-p)
-                   (seq-do #'detached--initialize-session))
+      (let ((detached--update-database nil))
+        (thread-last (detached--db-get-sessions)
+                     (seq-filter #'detached--session-accessible-p)
+                     (seq-do #'detached--initialize-session)))
       (detached--db-update-sessions))))
 
 (defun detached-valid-session (session)
@@ -802,10 +806,11 @@ This function uses the `notifications' library."
 (defun detached-get-sessions ()
   "Return as initialized sessions as possible."
   ;; Try to initialize unknown sessions
-  (when-let ((initialized-sessions
-              (thread-last (detached--uninitialized-sessions)
-                           (seq-filter #'detached--session-accessible-p)
-                           (seq-do #'detached--initialize-session))))
+  (when-let* ((detached--update-database nil)
+              (initialized-sessions
+               (thread-last (detached--uninitialized-sessions)
+                            (seq-filter #'detached--session-accessible-p)
+                            (seq-do #'detached--initialize-session))))
     (detached--db-update-sessions))
   (detached--db-get-sessions))
 
@@ -1203,7 +1208,8 @@ Optionally make the path LOCAL to host."
 (defun detached--db-insert-entry (session)
   "Insert SESSION into `detached--sessions' and update database."
   (push `(,(detached--session-id session) . ,session) detached--sessions)
-  (detached--db-update-sessions))
+  (when detached--update-database
+    (detached--db-update-sessions)))
 
 (defun detached--db-remove-entry (session)
   "Remove SESSION from `detached--sessions', delete log and update database."
@@ -1212,12 +1218,13 @@ Optionally make the path LOCAL to host."
       (delete-file log)))
   (setq detached--sessions
         (assq-delete-all (detached--session-id session) detached--sessions))
-  (detached--db-update-sessions))
+  (when detached--update-database
+    (detached--db-update-sessions)))
 
-(defun detached--db-update-entry (session &optional update)
-  "Update SESSION in `detached--sessions' optionally UPDATE database."
+(defun detached--db-update-entry (session)
+  "Update SESSION in `detached--sessions' and the database."
   (setf (alist-get (detached--session-id session) detached--sessions) session)
-  (when update
+  (when detached--update-database
     (detached--db-update-sessions)))
 
 (defun detached--db-get-session (id)
@@ -1329,7 +1336,7 @@ Optionally make the path LOCAL to host."
   (funcall detached-notification-function session)
 
   ;; Update session in database
-  (detached--db-update-entry session t)
+  (detached--db-update-entry session)
 
   ;; Execute callback
   (when-let ((callback (plist-get (detached--session-action session) 
:callback)))
@@ -1523,8 +1530,7 @@ If event is cased by an update to the `detached' 
database, re-initialize
                 (unless (gethash (detached--session-id session) 
detached--hashed-sessions)
                   (if (not (detached--session-accessible-p session))
                       (puthash (detached--session-id session) 'uninitialized 
detached--hashed-sessions)
-                    (detached--initialize-session session)
-                    (detached--db-update-sessions))))
+                    (detached--initialize-session session))))
               (detached--db-get-sessions)))))
 
 (defun detached--annotation-widths (sessions annotation-format)
diff --git a/test/detached-test.el b/test/detached-test.el
index d1ac511229..c11644ca60 100644
--- a/test/detached-test.el
+++ b/test/detached-test.el
@@ -206,7 +206,7 @@
      (setq copy (copy-detached-session session))
      (setf (detached--session-state copy) nil)
      (should (not (equal copy (detached--db-get-session id))))
-     (detached--db-update-entry copy t)
+     (detached--db-update-entry copy)
      (should (equal copy (car (detached--db-get-sessions)))))))
 
 (ert-deftest detached-test-detached-command ()



reply via email to

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