0

I prefer to work in one large org-agenda file. I have my appointments and notes in there from the past five years. I do not want to accidentally change any parts of my old entries while adding new information. I do not like to archive entries but keep them as they are. I would like to set some headings as "read only".

How can I do that? Or how can I at least make it more difficult for me to make any accidental changes to these headings and their contents, perhaps by "locking" them somehow?

I am running Emacs 27 on Windows 10.

2

Here is some lightly improved code that preserves the modified state when applied.For me tasks that are readonly do get listed in the agenda, but I get a bell error about text being read-only. I guess org-agenda is trying to set some properties on the text or something, and is having trouble because it is read-only. I don't see a real way around that.

(defun org-mark-readonly ()
  (interactive)
  (let ((buf-mod (buffer-modified-p)))
    (org-map-entries
     (lambda ()
       (org-mark-subtree)
       (add-text-properties (region-beginning) (region-end) '(read-only t)))
     "read_only")
    (unless buf-mod
      (set-buffer-modified-p nil))))


(defun org-remove-readonly ()
  (interactive)
  (let ((buf-mod (buffer-modified-p)))
    (org-map-entries
     (lambda ()
       (let* ((inhibit-read-only t))
     (org-mark-subtree)
     (remove-text-properties (region-beginning) (region-end) '(read-only t))))
     "read_only")
    (unless buf-mod
      (set-buffer-modified-p nil))))

(add-hook 'org-mode-hook 'org-mark-readonly)
2
  • Thank you so much. This updated code preserves the modified state. As you noted however, there are still problems viewing the org-agenda when items are marked as read_only. In my case, only some items are appearing, and I cannot move forward beyond a certain date. – Raoul Comninos Dec 31 '20 at 5:59
  • If I mark the whole file as read-only using # -*- buffer-read-only: t -*- (and removing the read_only tags) the file displays without problems in org-agenda. – Raoul Comninos Dec 31 '20 at 6:16
0

I did find one very useful solution since posting my question:

Make some org-sections read-only

2
  • The only downside to this method is that if one then opens the file, Emacs treats it as "modified" even if no changes have been made to it. – Raoul Comninos Dec 28 '20 at 8:09
  • Items so marked also do not display in org-agenda. – Raoul Comninos Dec 28 '20 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.