diff options
author | Thanos Apollo <[email protected]> | 2024-02-28 01:52:59 +0200 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-02-28 01:52:59 +0200 |
commit | 042079c20223a0075f0a6c53e8f6f59f04872103 (patch) | |
tree | e9ef5dbfb8e1974b83611a012b785088815fb86f /gnosis.el | |
parent | 9500c73f55f44ef4f02acea5aa6cb969006bfdcb (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.el | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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." |