Function: todo-diary-goto-entry

todo-diary-goto-entry is a byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-diary-goto-entry BUTTON)

Documentation

Jump to the diary entry for the BUTTON at point.

If the entry is a todo item, display its category properly. Overrides diary-goto-entry.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
;; This duplicates the item locating code from diary-goto-entry, but
;; without the marker code, to test whether the latter is dispensable.
;; If it is, diary-goto-entry can be simplified.  The code duplication
;; here can also be eliminated, leaving only the widening and category
;; selection, and instead of :override advice :around can be used.

(defun todo-diary-goto-entry (button)
  "Jump to the diary entry for the BUTTON at point.
If the entry is a todo item, display its category properly.
Overrides `diary-goto-entry'."
  ;; Locate the diary item in its source file.
  (let* ((locator (button-get button 'locator))
	 (file (cadr locator))
	 (date (regexp-quote (nth 2 locator)))
	 (content (regexp-quote (nth 3 locator))))
    (if (not (and (file-exists-p file)
		  (find-file-other-window file)))
	(message "Unable to locate this diary entry")
      ;; If it's a Todo file, make sure it's in Todo mode.
      (when (and (equal (file-name-directory (file-truename file))
			(file-truename todo-directory))
		 (not (derived-mode-p 'todo-mode)))
	(todo-mode))
      (when (eq major-mode 'todo-mode) (widen))
      (goto-char (point-min))
      (when (re-search-forward (format "%s.*\\(%s\\)" date content) nil t)
	(goto-char (match-beginning 1)))
      ;; If it's a todo item, determine its category and display the
      ;; category properly.
      (when (eq major-mode 'todo-mode)
	(let ((opoint (point)))
	  (re-search-backward (concat "^" (regexp-quote todo-category-beg)
				      "\\(.*\\)\n")
                              nil t)
	  (todo-category-number (match-string 1))
	  (todo-category-select)
          (if transient-mark-mode (deactivate-mark))
	  (goto-char opoint))))))