Function: todo-edit-quit

todo-edit-quit is an interactive and byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-edit-quit)

Documentation

Return from Todo Edit mode to Todo mode.

If the item contains hard line breaks, make sure the following lines are indented by todo-indent-to-here to conform to diary format.

If the whole file was in Todo Edit mode, check before returning whether the file is still a valid todo file and if so, also recalculate the todo file's categories sexp, in case changes were made in the number or names of categories.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-edit-quit ()
  "Return from Todo Edit mode to Todo mode.
If the item contains hard line breaks, make sure the following
lines are indented by `todo-indent-to-here' to conform to diary
format.

If the whole file was in Todo Edit mode, check before returning
whether the file is still a valid todo file and if so, also
recalculate the todo file's categories sexp, in case changes were
made in the number or names of categories."
  (interactive)
  (if (> (buffer-size) (- (point-max) (point-min)))
      ;; We got here via `e m'.
      (let ((item (buffer-string))
	    (regex "\\(\n\\)[^[:blank:]]")
	    (buf (buffer-base-buffer)))
	(while (not (string-match (concat todo-date-string-start
					  todo-date-pattern)
                                  item))
	  (setq item (read-from-minibuffer
		     "Item must start with a date: " item)))
	;; Ensure lines following hard newlines are indented.
	(when (string-match regex (buffer-string))
	  (setq item (replace-regexp-in-string regex "\n\t" item nil nil 1))
	  (delete-region (point-min) (point-max))
	  (insert item))
	(kill-buffer)
	(unless (eq (current-buffer) buf)
	  (set-window-buffer (selected-window) (set-buffer buf)))
	(todo-category-number todo-edit-item--cat)
	(todo-category-select)
	(goto-char todo-edit-item--pos)
        (if transient-mark-mode (deactivate-mark)))
    ;; We got here via `F e'.
    (when (todo-check-format)
      ;; FIXME: separate out sexp check?
      ;; If manual editing makes e.g. item counts change, have to
      ;; call this to update todo-categories, but it restores
      ;; category order to list order.
      ;; (todo-repair-categories-sexp)
      ;; Compare (todo-make-categories-list t) with sexp and if
      ;; different ask (todo-update-categories-sexp) ?
      (if (equal (file-name-extension (buffer-file-name)) "toda")
          (todo-archive-mode)
        (todo-mode))
      (let* ((cat-beg (concat "^" (regexp-quote todo-category-beg)
			      "\\(.*\\)$"))
	     (curline (buffer-substring-no-properties
		       (line-beginning-position) (line-end-position)))
	     (cat (cond ((string-match cat-beg curline)
			 (match-string-no-properties 1 curline))
			((or (re-search-backward cat-beg nil t)
			     (re-search-forward cat-beg nil t))
			 (match-string-no-properties 1)))))
	(todo-category-number cat)
	(todo-category-select)
	(goto-char (point-min))))))