Avoid making todo-mode buffers manually editable
* lisp/calendar/todo-mode.el (todo-add-category) (todo-move-category, todo-edit-item--header) (todo-set-item-priority, todo-move-item, todo-item-undone) (todo-archive-done-item, todo-set-category-number): Restrict the scope of nil buffer-read-only to the function calls that change buffer text, thereby preventing todo mode buffers from becoming manually editable and hence possibly corrupted when the minibuffer is in use.
This commit is contained in:
parent
53332bdf62
commit
ee41f07be5
1 changed files with 115 additions and 113 deletions
|
@ -1294,15 +1294,15 @@ return the new category number."
|
||||||
file)))
|
file)))
|
||||||
(find-file file0)
|
(find-file file0)
|
||||||
(let ((counts (make-vector 4 0)) ; [todo diary done archived]
|
(let ((counts (make-vector 4 0)) ; [todo diary done archived]
|
||||||
(num (1+ (length todo-categories)))
|
(num (1+ (length todo-categories))))
|
||||||
(buffer-read-only nil))
|
|
||||||
(setq todo-current-todo-file file0)
|
(setq todo-current-todo-file file0)
|
||||||
(setq todo-categories (append todo-categories
|
(setq todo-categories (append todo-categories
|
||||||
(list (cons cat counts))))
|
(list (cons cat counts))))
|
||||||
(widen)
|
(widen)
|
||||||
(goto-char (point-max))
|
(goto-char (point-max))
|
||||||
(save-excursion ; Save point for todo-category-select.
|
(save-excursion ; Save point for todo-category-select.
|
||||||
(insert todo-category-beg cat "\n\n" todo-category-done "\n"))
|
(let ((buffer-read-only nil))
|
||||||
|
(insert todo-category-beg cat "\n\n" todo-category-done "\n")))
|
||||||
(todo-update-categories-sexp)
|
(todo-update-categories-sexp)
|
||||||
;; If invoked by user, display the newly added category, if
|
;; If invoked by user, display the newly added category, if
|
||||||
;; called programmatically return the category number to the
|
;; called programmatically return the category number to the
|
||||||
|
@ -1459,8 +1459,7 @@ the archive of the file moved to, creating it if it does not exist."
|
||||||
(match-beginning 0)
|
(match-beginning 0)
|
||||||
(point-max)))
|
(point-max)))
|
||||||
(content (buffer-substring-no-properties beg end))
|
(content (buffer-substring-no-properties beg end))
|
||||||
(counts (cdr (assoc cat todo-categories)))
|
(counts (cdr (assoc cat todo-categories))))
|
||||||
buffer-read-only)
|
|
||||||
;; Move the category to the new file. Also update or create
|
;; Move the category to the new file. Also update or create
|
||||||
;; archive file if necessary.
|
;; archive file if necessary.
|
||||||
(with-current-buffer
|
(with-current-buffer
|
||||||
|
@ -1520,6 +1519,7 @@ the archive of the file moved to, creating it if it does not exist."
|
||||||
;; Delete the category from the old file, and if that was the
|
;; Delete the category from the old file, and if that was the
|
||||||
;; last category, delete the file. Also handle archive file
|
;; last category, delete the file. Also handle archive file
|
||||||
;; if necessary.
|
;; if necessary.
|
||||||
|
(let ((buffer-read-only nil))
|
||||||
(remove-overlays beg end)
|
(remove-overlays beg end)
|
||||||
(delete-region beg end)
|
(delete-region beg end)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
@ -1538,7 +1538,7 @@ the archive of the file moved to, creating it if it does not exist."
|
||||||
(todo-update-categories-sexp)
|
(todo-update-categories-sexp)
|
||||||
(when (> todo-category-number (length todo-categories))
|
(when (> todo-category-number (length todo-categories))
|
||||||
(setq todo-category-number 1))
|
(setq todo-category-number 1))
|
||||||
(todo-category-select)))))
|
(todo-category-select))))))
|
||||||
(set-window-buffer (selected-window)
|
(set-window-buffer (selected-window)
|
||||||
(set-buffer (find-file-noselect nfile))))))
|
(set-buffer (find-file-noselect nfile))))))
|
||||||
|
|
||||||
|
@ -2314,7 +2314,6 @@ made in the number or names of categories."
|
||||||
;; INC must be an integer, but users could pass it via
|
;; INC must be an integer, but users could pass it via
|
||||||
;; `todo-edit-item' as e.g. `-' or `C-u'.
|
;; `todo-edit-item' as e.g. `-' or `C-u'.
|
||||||
(inc (prefix-numeric-value inc))
|
(inc (prefix-numeric-value inc))
|
||||||
(buffer-read-only nil)
|
|
||||||
ndate ntime
|
ndate ntime
|
||||||
year monthname month day) ;; dayname
|
year monthname month day) ;; dayname
|
||||||
(when marked (todo--user-error-if-marked-done-item))
|
(when marked (todo--user-error-if-marked-done-item))
|
||||||
|
@ -2477,13 +2476,14 @@ made in the number or names of categories."
|
||||||
(day day)
|
(day day)
|
||||||
(dayname nil)) ;; dayname
|
(dayname nil)) ;; dayname
|
||||||
(mapconcat #'eval calendar-date-display-form "")))))
|
(mapconcat #'eval calendar-date-display-form "")))))
|
||||||
|
(let ((buffer-read-only nil))
|
||||||
(when ndate (replace-match ndate nil nil nil 1))
|
(when ndate (replace-match ndate nil nil nil 1))
|
||||||
;; Add new time string to the header, if it was supplied.
|
;; Add new time string to the header, if it was supplied.
|
||||||
(when ntime
|
(when ntime
|
||||||
(if otime
|
(if otime
|
||||||
(replace-match ntime nil nil nil 2)
|
(replace-match ntime nil nil nil 2)
|
||||||
(goto-char (match-end 1))
|
(goto-char (match-end 1))
|
||||||
(insert ntime)))
|
(insert ntime))))
|
||||||
(setq todo-date-from-calendar nil)
|
(setq todo-date-from-calendar nil)
|
||||||
(setq first nil))
|
(setq first nil))
|
||||||
;; Apply the changes to the first marked item header to the
|
;; Apply the changes to the first marked item header to the
|
||||||
|
@ -2650,8 +2650,7 @@ meaning to raise or lower the item's priority by one."
|
||||||
(1- curnum))
|
(1- curnum))
|
||||||
((and (eq arg 'lower) (<= curnum maxnum))
|
((and (eq arg 'lower) (<= curnum maxnum))
|
||||||
(1+ curnum))))
|
(1+ curnum))))
|
||||||
candidate
|
candidate)
|
||||||
buffer-read-only)
|
|
||||||
(unless (and priority
|
(unless (and priority
|
||||||
(or (and (eq arg 'raise) (zerop priority))
|
(or (and (eq arg 'raise) (zerop priority))
|
||||||
(and (eq arg 'lower) (> priority maxnum))))
|
(and (eq arg 'lower) (> priority maxnum))))
|
||||||
|
@ -2704,6 +2703,7 @@ meaning to raise or lower the item's priority by one."
|
||||||
(when match
|
(when match
|
||||||
(user-error (concat "Cannot reprioritize items from the same "
|
(user-error (concat "Cannot reprioritize items from the same "
|
||||||
"category in this mode, only in Todo mode")))))
|
"category in this mode, only in Todo mode")))))
|
||||||
|
(let ((buffer-read-only nil))
|
||||||
;; Interactively or with non-nil ARG, relocate the item within its
|
;; Interactively or with non-nil ARG, relocate the item within its
|
||||||
;; category.
|
;; category.
|
||||||
(when (or arg (called-interactively-p 'any))
|
(when (or arg (called-interactively-p 'any))
|
||||||
|
@ -2712,10 +2712,9 @@ meaning to raise or lower the item's priority by one."
|
||||||
(when priority
|
(when priority
|
||||||
(unless (= priority 1)
|
(unless (= priority 1)
|
||||||
(todo-forward-item (1- priority))
|
(todo-forward-item (1- priority))
|
||||||
;; When called from todo-item-undone and the highest priority
|
;; When called from todo-item-undone and the highest priority is
|
||||||
;; is chosen, this advances point to the first done item, so
|
;; chosen, this advances point to the first done item, so move
|
||||||
;; move it up to the empty line above the done items
|
;; it up to the empty line above the done items separator.
|
||||||
;; separator.
|
|
||||||
(when (looking-back (concat "^"
|
(when (looking-back (concat "^"
|
||||||
(regexp-quote todo-category-done)
|
(regexp-quote todo-category-done)
|
||||||
"\n")
|
"\n")
|
||||||
|
@ -2727,7 +2726,7 @@ meaning to raise or lower the item's priority by one."
|
||||||
(let* ((ov (todo-get-overlay 'prefix))
|
(let* ((ov (todo-get-overlay 'prefix))
|
||||||
(pref (overlay-get ov 'before-string)))
|
(pref (overlay-get ov 'before-string)))
|
||||||
(overlay-put ov 'before-string
|
(overlay-put ov 'before-string
|
||||||
(concat todo-item-mark pref))))))))
|
(concat todo-item-mark pref)))))))))
|
||||||
|
|
||||||
(defun todo-raise-item-priority ()
|
(defun todo-raise-item-priority ()
|
||||||
"Raise priority of current item by moving it up by one item."
|
"Raise priority of current item by moving it up by one item."
|
||||||
|
@ -2768,8 +2767,7 @@ section in the category moved to."
|
||||||
(save-excursion (beginning-of-line)
|
(save-excursion (beginning-of-line)
|
||||||
(looking-at todo-category-done)))
|
(looking-at todo-category-done)))
|
||||||
(not marked))
|
(not marked))
|
||||||
(let* ((buffer-read-only)
|
(let* ((file1 todo-current-todo-file)
|
||||||
(file1 todo-current-todo-file)
|
|
||||||
(item (todo-item-string))
|
(item (todo-item-string))
|
||||||
(done-item (and (todo-done-item-p) item))
|
(done-item (and (todo-done-item-p) item))
|
||||||
(omark (save-excursion (todo-item-start) (point-marker)))
|
(omark (save-excursion (todo-item-start) (point-marker)))
|
||||||
|
@ -2828,7 +2826,8 @@ section in the category moved to."
|
||||||
(setq here (point))
|
(setq here (point))
|
||||||
(while todo-items
|
(while todo-items
|
||||||
(todo-forward-item)
|
(todo-forward-item)
|
||||||
(todo-insert-with-overlays (pop todo-items))))
|
(let ((buffer-read-only nil))
|
||||||
|
(todo-insert-with-overlays (pop todo-items)))))
|
||||||
;; Move done items en bloc to top of done items section.
|
;; Move done items en bloc to top of done items section.
|
||||||
(when done-items
|
(when done-items
|
||||||
(todo-category-number cat2)
|
(todo-category-number cat2)
|
||||||
|
@ -2842,7 +2841,8 @@ section in the category moved to."
|
||||||
(forward-line)
|
(forward-line)
|
||||||
(unless here (setq here (point)))
|
(unless here (setq here (point)))
|
||||||
(while done-items
|
(while done-items
|
||||||
(todo-insert-with-overlays (pop done-items))
|
(let ((buffer-read-only nil))
|
||||||
|
(todo-insert-with-overlays (pop done-items)))
|
||||||
(todo-forward-item)))
|
(todo-forward-item)))
|
||||||
;; If only done items were moved, move point to the top
|
;; If only done items were moved, move point to the top
|
||||||
;; one, otherwise, move point to the top moved todo item.
|
;; one, otherwise, move point to the top moved todo item.
|
||||||
|
@ -2881,12 +2881,14 @@ section in the category moved to."
|
||||||
(goto-char beg)
|
(goto-char beg)
|
||||||
(while (< (point) end)
|
(while (< (point) end)
|
||||||
(if (todo-marked-item-p)
|
(if (todo-marked-item-p)
|
||||||
(todo-remove-item)
|
(let ((buffer-read-only nil))
|
||||||
|
(todo-remove-item))
|
||||||
(todo-forward-item)))
|
(todo-forward-item)))
|
||||||
(setq todo-categories-with-marks
|
(setq todo-categories-with-marks
|
||||||
(assq-delete-all cat1 todo-categories-with-marks)))
|
(assq-delete-all cat1 todo-categories-with-marks)))
|
||||||
(if ov (delete-overlay ov))
|
(if ov (delete-overlay ov))
|
||||||
(todo-remove-item))))
|
(let ((buffer-read-only nil))
|
||||||
|
(todo-remove-item)))))
|
||||||
(when todo (todo-update-count 'todo (- todo) cat1))
|
(when todo (todo-update-count 'todo (- todo) cat1))
|
||||||
(when diary (todo-update-count 'diary (- diary) cat1))
|
(when diary (todo-update-count 'diary (- diary) cat1))
|
||||||
(when done (todo-update-count 'done (- done) cat1))
|
(when done (todo-update-count 'done (- done) cat1))
|
||||||
|
@ -3015,8 +3017,7 @@ comments without asking."
|
||||||
(marked (assoc cat todo-categories-with-marks))
|
(marked (assoc cat todo-categories-with-marks))
|
||||||
(num (if (not marked) 1 (cdr marked))))
|
(num (if (not marked) 1 (cdr marked))))
|
||||||
(when (or marked (todo-done-item-p))
|
(when (or marked (todo-done-item-p))
|
||||||
(let ((buffer-read-only)
|
(let ((opoint (point))
|
||||||
(opoint (point))
|
|
||||||
(omark (point-marker))
|
(omark (point-marker))
|
||||||
(first 'first)
|
(first 'first)
|
||||||
(item-count 0)
|
(item-count 0)
|
||||||
|
@ -3078,6 +3079,7 @@ comments without asking."
|
||||||
(when ov (delete-overlay ov))
|
(when ov (delete-overlay ov))
|
||||||
(if (not undone)
|
(if (not undone)
|
||||||
(goto-char opoint)
|
(goto-char opoint)
|
||||||
|
(let ((buffer-read-only nil))
|
||||||
(if marked
|
(if marked
|
||||||
(progn
|
(progn
|
||||||
(setq item nil)
|
(setq item nil)
|
||||||
|
@ -3090,7 +3092,7 @@ comments without asking."
|
||||||
(setq todo-categories-with-marks
|
(setq todo-categories-with-marks
|
||||||
(assq-delete-all cat todo-categories-with-marks)))
|
(assq-delete-all cat todo-categories-with-marks)))
|
||||||
(goto-char omark)
|
(goto-char omark)
|
||||||
(todo-remove-item))
|
(todo-remove-item)))
|
||||||
(todo-update-count 'todo item-count)
|
(todo-update-count 'todo item-count)
|
||||||
(todo-update-count 'done (- item-count))
|
(todo-update-count 'done (- item-count))
|
||||||
(when diary-count (todo-update-count 'diary diary-count))
|
(when diary-count (todo-update-count 'diary diary-count))
|
||||||
|
@ -3175,8 +3177,7 @@ this category does not exist in the archive, it is created."
|
||||||
(concat (todo-item-string) "\n")))
|
(concat (todo-item-string) "\n")))
|
||||||
(count 0)
|
(count 0)
|
||||||
(opoint (unless (todo-done-item-p) (point)))
|
(opoint (unless (todo-done-item-p) (point)))
|
||||||
marked-items beg end all-done
|
marked-items beg end all-done)
|
||||||
buffer-read-only)
|
|
||||||
(cond
|
(cond
|
||||||
(all
|
(all
|
||||||
(if (todo-y-or-n-p "Archive all done items in this category? ")
|
(if (todo-y-or-n-p "Archive all done items in this category? ")
|
||||||
|
@ -3246,6 +3247,7 @@ this category does not exist in the archive, it is created."
|
||||||
(todo-archive-mode))
|
(todo-archive-mode))
|
||||||
(if headers-hidden (todo-toggle-item-header))))
|
(if headers-hidden (todo-toggle-item-header))))
|
||||||
(with-current-buffer tbuf
|
(with-current-buffer tbuf
|
||||||
|
(let ((buffer-read-only nil))
|
||||||
(cond
|
(cond
|
||||||
(all
|
(all
|
||||||
(save-excursion
|
(save-excursion
|
||||||
|
@ -3275,7 +3277,7 @@ this category does not exist in the archive, it is created."
|
||||||
(todo-backward-item))
|
(todo-backward-item))
|
||||||
(when item
|
(when item
|
||||||
(throw 'done (setq item nil))))
|
(throw 'done (setq item nil))))
|
||||||
(todo-forward-item))))))
|
(todo-forward-item)))))))
|
||||||
(when marked
|
(when marked
|
||||||
(setq todo-categories-with-marks
|
(setq todo-categories-with-marks
|
||||||
(assq-delete-all cat todo-categories-with-marks)))
|
(assq-delete-all cat todo-categories-with-marks)))
|
||||||
|
@ -3524,7 +3526,6 @@ decreasing or increasing its number."
|
||||||
(let* ((maxnum (length todo-categories))
|
(let* ((maxnum (length todo-categories))
|
||||||
(prompt (format "Set category priority (1-%d): " maxnum))
|
(prompt (format "Set category priority (1-%d): " maxnum))
|
||||||
(col (current-column))
|
(col (current-column))
|
||||||
(buffer-read-only nil)
|
|
||||||
(priority (cond ((and (eq arg 'raise) (> curnum 1))
|
(priority (cond ((and (eq arg 'raise) (> curnum 1))
|
||||||
(1- curnum))
|
(1- curnum))
|
||||||
((and (eq arg 'lower) (< curnum maxnum))
|
((and (eq arg 'lower) (< curnum maxnum))
|
||||||
|
@ -3549,6 +3550,7 @@ decreasing or increasing its number."
|
||||||
;; Category's name and items counts list.
|
;; Category's name and items counts list.
|
||||||
(catcons (nth (1- curnum) todo-categories))
|
(catcons (nth (1- curnum) todo-categories))
|
||||||
(todo-categories (nconc head (list catcons) tail))
|
(todo-categories (nconc head (list catcons) tail))
|
||||||
|
(buffer-read-only nil)
|
||||||
newcats)
|
newcats)
|
||||||
(when lower (setq todo-categories (nreverse todo-categories)))
|
(when lower (setq todo-categories (nreverse todo-categories)))
|
||||||
(setq todo-categories (delete-dups todo-categories))
|
(setq todo-categories (delete-dups todo-categories))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue