From 712376d24e787f2a3ea63f828159aa9e967e7ab0 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 4 Jan 2024 04:36:37 +0200 Subject: Add gnosis-edit-mode & map gnosis-edit-mode, a mode derived from emacs-lisp with that has keybind C-c C-c to a #'lambda that evaluates & kills buffer, exiting recursive-edit loop --- gnosis.el | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'gnosis.el') diff --git a/gnosis.el b/gnosis.el index 49e4dc5..26e2754 100644 --- a/gnosis.el +++ b/gnosis.el @@ -846,9 +846,8 @@ Used to reveal all clozes left with `gnosis-face-cloze-unanswered' face." This function initializes the `gnosis-dir' as a Git repository if it is not already one. It then adds the gnosis.db file to the repository and commits -the changes with a message containing the review type and the number of notes. +the changes with a message containing the reviewed number of notes. -TYPE: The type of the review session. NOTE-NUM: The number of notes reviewed in the session." (let ((git (executable-find "git")) (default-directory gnosis-dir)) @@ -856,7 +855,7 @@ NOTE-NUM: The number of notes reviewed in the session." (error "Git not found, please install git")) (unless (file-exists-p (concat (file-name-as-directory gnosis-dir) ".git")) (shell-command "git init")) - (sit-for 0.2) + (sit-for 0.2) ;; wait for shell command to finish (shell-command (concat git " add " (shell-quote-argument "gnosis.db"))) (shell-command (concat git " commit -m " (shell-quote-argument (concat (format "Total notes for session: %d " note-num))))) @@ -939,8 +938,8 @@ changes." (image (gnosis-get 'images 'extras `(= id ,id))) (second-image (gnosis-get 'extra-image 'extras `(= id ,id)))) (with-current-buffer (switch-to-buffer (get-buffer-create "*gnosis-edit*")) + (gnosis-edit-mode) (erase-buffer) - (emacs-lisp-mode) (insert ";;\n;; You are editing a gnosis note. DO NOT change the value of id.\n\n") (insert "(gnosis-edit-update-note ") (cl-loop for (field value) in `((id ,id) @@ -962,9 +961,19 @@ changes." (t (insert (format ":%s \"%s\"\n" field value))))) (delete-char -1) ;; delete extra line (insert ")") - (insert "\n;; After finishing editing, evaluate expression with `C-x C-e'.") + (insert "\n;; After finishing editing, save changes with ` '\n;; Do NOT exit without saving.") (indent-region (point-min) (point-max))))) +(define-derived-mode gnosis-edit-mode emacs-lisp-mode "Gnosis EDIT" + "Gnosis Edit Mode." + :interactive t + :lighter " gnosis-edit-mode" + :keymap gnosis-edit-mode-map) + +(defvar-keymap gnosis-edit-mode-map + :doc "gnosis-edit keymap" + "C-c C-c" #'(lambda () (interactive) (eval-buffer) (kill-buffer) (throw 'exit nil))) + (cl-defun gnosis-edit-update-note (&key id main options answer tags (extra-notes nil) (image nil) (second-image nil)) "Update note with id value of ID. @@ -992,8 +1001,7 @@ SECOND-IMAGE: Image to display after user-input" (gnosis-update 'extras `(= ,field ,value) `(= id ,id))) ((listp value) (gnosis-update 'notes `(= ,field ',value) `(= id ,id))) - (t (gnosis-update 'notes `(= ,field ,value) `(= id ,id))))) - (throw 'exit nil)) + (t (gnosis-update 'notes `(= ,field ,value) `(= id ,id)))))) ;;;###autoload -- cgit v1.2.3