From 042079c20223a0075f0a6c53e8f6f59f04872103 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 28 Feb 2024 01:52:59 +0200 Subject: Add gnosis-edit-read-only-values When creating gnosis-edit buffer for NOTE, we have to make sure the fields will not be deleted accidently be the user and the value of id won't change. Use gnosis-edit-read-only-values in gnosis-edit-note. --- gnosis.el | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/gnosis.el b/gnosis.el index 53859a8..3b95ba6 100644 --- a/gnosis.el +++ b/gnosis.el @@ -1153,6 +1153,13 @@ NOTES: List of note ids" ;; Editing notes +(defun gnosis-edit-read-only-values (&rest values) + "Makes the provided values read-only in the whole buffer." + (goto-char (point-min)) + (dolist (value values) + (while (search-forward value nil t) + (put-text-property (match-beginning 0) (match-end 0) 'read-only t))) + (goto-char (point-min))) (defun gnosis-edit-note (id) "Edit the contents of a note with the given ID. @@ -1181,12 +1188,16 @@ changes." (pop-to-buffer-same-window (get-buffer-create "*gnosis-edit*")) (gnosis-edit-mode) (erase-buffer) - (insert ";;\n;; You are editing a gnosis note. DO NOT change the value of id.\n\n") + (insert ";;\n;; You are editing a gnosis note.\n\n") (insert "(gnosis-edit-update-note ") (gnosis-export-note id) (insert ")") - (insert "\n\n;; After finishing editing, save changes with ` '\n;; Do NOT exit without saving.") - (indent-region (point-min) (point-max))) + (insert "\n\n;; After finishing editing, save changes with ` '\n;; Avoid exiting without saving.") + (indent-region (point-min) (point-max)) + ;; Insert id & fields as read-only values + (gnosis-edit-read-only-values (format ":id %s" id) ":main" ":options" ":answer" + ":tags" ":extra-notes" ":image" ":second-image" + ":ef" ":ff" ":suspend")) (defun gnosis-edit-save-exit () "Save edits and exit." -- cgit v1.2.3