summaryrefslogtreecommitdiff
path: root/gnosis.el
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2024-02-28 01:52:59 +0200
committerThanos Apollo <[email protected]>2024-02-28 01:52:59 +0200
commit042079c20223a0075f0a6c53e8f6f59f04872103 (patch)
treee9ef5dbfb8e1974b83611a012b785088815fb86f /gnosis.el
parent9500c73f55f44ef4f02acea5aa6cb969006bfdcb (diff)
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.
Diffstat (limited to 'gnosis.el')
-rw-r--r--gnosis.el17
1 files 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 `<C-c> <C-c>'\n;; Do NOT exit without saving.")
- (indent-region (point-min) (point-max)))
+ (insert "\n\n;; After finishing editing, save changes with `<C-c> <C-c>'\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."