emacs-diffs
[Top][All Lists]
Advanced

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

scratch/sqlite 80a248e: Allow listing all backends, and fix up deletion


From: Lars Ingebrigtsen
Subject: scratch/sqlite 80a248e: Allow listing all backends, and fix up deletion
Date: Tue, 14 Dec 2021 20:51:22 -0500 (EST)

branch: scratch/sqlite
commit 80a248efbcf610a1a7a8a732c8d6c7c313098663
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Allow listing all backends, and fix up deletion
---
 doc/lispref/variables.texi      |  4 ++++
 lisp/emacs-lisp/multisession.el | 45 +++++++++++++++++++++++++++--------------
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index e6b7a65..095cc80 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2853,6 +2853,10 @@ instances are updating the value at the same time, it's 
unpredictable
 which instance ``wins''.
 @end defun
 
+@defun multisession-delete object
+This function will delete the value from the backend storage.
+@end defun
+
 @defun make-multisession
 You can also make persistent values that aren't tied to a specific
 variable, but is tied to an explicit package and key.
diff --git a/lisp/emacs-lisp/multisession.el b/lisp/emacs-lisp/multisession.el
index 6bb1c7d..20412e6 100644
--- a/lisp/emacs-lisp/multisession.el
+++ b/lisp/emacs-lisp/multisession.el
@@ -105,6 +105,7 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
     (multisession-backend-value (multisession--storage object) object)))
 
 (defun multisession--set-value (object value)
+  "Set the stored value of OBJECT to VALUE."
   (if (null user-init-file)
       ;; We have no backend, so just store the value.
       (setf (multisession--cached-value object) value)
@@ -112,6 +113,10 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
     (multisession--backend-set-value (multisession--storage object)
                                      object value)))
 
+(defun multisession-delete (object)
+  "Delete OBJECT from the backend storage."
+  (multisession--backend-delete (multisession--storage object) object))
+
 (gv-define-simple-setter multisession-value multisession--set-value)
 
 ;; SQLite Backend
@@ -228,10 +233,11 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
    multisession--db
    "select package, key, value from multisession order by package, key"))
 
-(cl-defmethod multisession--backend-delete ((_type (eql sqlite)) id)
+(cl-defmethod multisession--backend-delete ((_type (eql sqlite)) object)
   (sqlite-execute multisession--db
                   "delete from multisession where package = ? and key = ?"
-                  id))
+                  (list (multisession--package object)
+                        (multisession--key object))))
 
 ;; Files Backend
 
@@ -318,10 +324,8 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
            (expand-file-name "files" multisession-directory)
            "\\.value\\'")))
 
-(cl-defmethod multisession--backend-delete ((_type (eql files)) id)
-  (let ((file (multisession--object-file-name
-               (make-multisession :package (car id)
-                                  :key (cadr id)))))
+(cl-defmethod multisession--backend-delete ((_type (eql files)) object)
+  (let ((file (multisession--object-file-name object)))
     (when (file-exists-p file)
       (delete-file file))))
 
@@ -344,13 +348,20 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
   (setq-local revert-buffer-function #'multisession-edit-mode--revert))
 
 ;;;###autoload
-(defun list-multisession-values ()
-  "List all values in the \"multisession\" database."
-  (interactive)
-  (pop-to-buffer (get-buffer-create "*Multisession*"))
-  (multisession-edit-mode)
-  (multisession-edit-mode--revert)
-  (goto-char (point-min)))
+(defun list-multisession-values (&optional choose-storage)
+  "List all values in the \"multisession\" database.
+If CHOOSE-STORAGE (interactively, the prefix), query for the
+storage method to list."
+  (interactive "P")
+  (let ((storage
+         (if choose-storage
+             (intern (completing-read "Storage method: " '(sqlite files) nil 
t))
+           multisession-storage)))
+    (pop-to-buffer (get-buffer-create "*Multisession*"))
+    (multisession-edit-mode)
+    (setq-local multisession-storage storage)
+    (multisession-edit-mode--revert)
+    (goto-char (point-min))))
 
 (defun multisession-edit-mode--revert (&rest _)
   (let ((inhibit-read-only t))
@@ -367,11 +378,15 @@ DOC should be a doc string, and ARGS are keywords as 
applicable to
 
 (defun multisession-delete-value (id)
   "Delete the value at point."
-  (interactive (list (get-text-property (point) 'multisession--id))
+  (interactive (list (get-text-property (point) 'tabulated-list-id))
                multisession-edit-mode)
   (unless id
     (error "No value on the current line"))
-  (multisession--backend-delete multisession-storage id)
+  (unless (yes-or-no-p "Really delete this item? ")
+    (user-error "Not deleting"))
+  (multisession--backend-delete multisession-storage
+                                (make-multisession :package (car id)
+                                                   :key (cdr id)))
   (let ((inhibit-read-only t))
     (beginning-of-line)
     (delete-region (point) (progn (forward-line 1) (point)))))



reply via email to

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