branch: externals/gnosis
commit c1693be529c9c54c60d66650c90c8c83f0dfeac8
Author: Thanos Apollo <[email protected]>
Commit: Thanos Apollo <[email protected]>

    [Feature] Add gnosis-save-hook.
    
    * Hook run after a successful gnosis-save.
---
 gnosis.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/gnosis.el b/gnosis.el
index caa53d22a6..16e5ce4461 100644
--- a/gnosis.el
+++ b/gnosis.el
@@ -224,6 +224,10 @@ This is set automatically based on buffer type:
 
 (defvar gnosis-export-separator "\n- ")
 
+(defvar gnosis-save-hook nil
+  "Hook run after a successful `gnosis-save'.
+Each function is called with the saved thema ID (integer).")
+
 ;; TODO: Make this as a defcustom.
 (defvar gnosis-custom-values
   '((:deck "demo" (:proto (0 1 3) :anagnosis 3 :epignosis 0.5 :agnoia 0.3
@@ -1994,7 +1998,8 @@ Returns nil on success, or an error message string on 
failure."
         (gnosis--id-cache (let ((ht (make-hash-table :test 'equal)))
                             (dolist (id (gnosis-select 'id 'themata nil t) ht)
                               (puthash id t ht))))
-        (errors nil))
+        (errors nil)
+        (edited-id (string-to-number (caar themata))))
     (emacsql-with-transaction gnosis-db
       (cl-loop for thema in themata
               for err = (gnosis-save-thema thema deck)
@@ -2002,7 +2007,8 @@ Returns nil on success, or an error message string on 
failure."
     (if errors
         (user-error "Failed to import %d thema(ta):\n%s"
                     (length errors) (mapconcat #'identity (nreverse errors) 
"\n"))
-      (gnosis-edit-quit))))
+      (gnosis-edit-quit)
+      (run-hook-with-args 'gnosis-save-hook edited-id))))
 
 ;;;###autoload
 (defun gnosis-save-deck (deck-name)

Reply via email to