Function: todo-edit-item--text
todo-edit-item--text is a byte-compiled function defined in
todo-mode.el.gz.
Signature
(todo-edit-item--text &optional ARG)
Documentation
Function providing the text editing facilities of todo-edit-item.
Source Code
;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-edit-item--text (&optional arg)
"Function providing the text editing facilities of `todo-edit-item'."
(let ((full-item (todo-item-string)))
;; If there are marked items and user invokes a text-editing
;; commands with point not on an item, todo-item-start is nil and
;; 1+ signals an error, so just make this a noop.
(when full-item
(let* ((opoint (point))
(ocat (todo-current-category))
(start (todo-item-start))
(end (save-excursion (todo-item-end)))
(item-beg (progn
(re-search-forward
(concat todo-date-string-start todo-date-pattern
"\\( " diary-time-regexp "\\)?"
(regexp-quote todo-nondiary-end) "?")
(line-end-position) t)
(1+ (- (point) start))))
(include-header (eq arg 'include-header))
(comment-edit (eq arg 'comment-edit))
(comment-delete (eq arg 'comment-delete))
(header-string (substring full-item 0 item-beg))
(item (if (or include-header comment-edit comment-delete)
full-item
(substring full-item item-beg)))
(multiline (or (eq arg 'multiline)
(> (length (split-string item "\n")) 1)))
(comment (save-excursion
(todo-item-start)
(re-search-forward
(concat " \\[" (regexp-quote todo-comment-string)
": \\([^]]+\\)\\]")
end t)))
(prompt (if comment "Edit comment: " "Enter a comment: ")))
;; When there are marked items, user can invoke todo-edit-item
;; even if point is not on an item, but text editing only
;; applies to the item at point.
(when (or (and (todo-done-item-p)
(or comment-edit comment-delete))
(and (not (todo-done-item-p))
(or (not arg) include-header multiline)))
(cond
((or comment-edit comment-delete)
(save-excursion
(todo-item-start)
(if (re-search-forward (concat " \\["
(regexp-quote todo-comment-string)
": \\([^]]+\\)\\]")
end t)
(if comment-delete
(when (todo-y-or-n-p "Delete comment? ")
(let ((inhibit-read-only t))
(delete-region (match-beginning 0) (match-end 0))))
(let ((inhibit-read-only t))
(replace-match (save-match-data
(prog1 (let ((buffer-read-only t))
(read-string
prompt
(cons (match-string 1) 1)))
;; If user moved point while editing
;; a comment, restore it and ensure
;; done items section is displayed.
(unless (= (point) opoint)
(todo-category-number ocat)
(let ((todo-show-with-done t))
(todo-category-select)
(goto-char opoint)))))
nil nil nil 1)))
(if comment-delete
(user-error "There is no comment to delete")
(let ((inhibit-read-only t))
(insert " [" todo-comment-string ": "
(prog1 (let ((buffer-read-only t))
(read-string prompt))
;; If user moved point while inserting a
;; comment, restore it and ensure done items
;; section is displayed.
(unless (= (point) opoint)
(todo-category-number ocat)
(let ((todo-show-with-done t))
(todo-category-select)
(goto-char opoint)))
(todo-item-end))
"]"))))))
(multiline
(let ((buf todo-edit-buffer))
(setq todo-edit-item--cat ocat)
(setq todo-edit-item--pos opoint)
(set-window-buffer (selected-window)
(set-buffer (make-indirect-buffer
(buffer-name) buf)))
(narrow-to-region (todo-item-start) (todo-item-end))
(todo-edit-mode)
(message "%s" (substitute-command-keys
(concat "Type \\[todo-edit-quit] "
"to return to Todo mode.\n")))))
(t
(let ((new (concat (if include-header "" header-string)
(read-string "Edit: " (if include-header
(cons item item-beg)
(cons item 0))))))
(when include-header
(while (not (string-match (concat todo-date-string-start
todo-date-pattern)
new))
(setq new (read-from-minibuffer
"Item must start with a date: " new))))
;; Ensure lines following hard newlines are indented.
(setq new (replace-regexp-in-string "\\(\n\\)[^[:blank:]]"
"\n\t" new nil nil 1))
;; If user moved point while editing item, restore it.
(unless (= (point) opoint)
(todo-category-number ocat)
(todo-category-select)
(goto-char opoint))
(let ((inhibit-read-only t))
(todo-remove-item)
(todo-insert-with-overlays new))
(move-to-column item-beg)))))))))