Function: todo-search

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

Signature

(todo-search)

Documentation

Search for a regular expression in this todo file.

The search runs through the whole file and encompasses all and only todo and done items; it excludes category names. Multiple matches are shown sequentially, highlighted in todo-search face.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
;; -----------------------------------------------------------------------------
;;; Searching and item filtering
;; -----------------------------------------------------------------------------

(defun todo-search ()
  "Search for a regular expression in this todo file.
The search runs through the whole file and encompasses all and
only todo and done items; it excludes category names.  Multiple
matches are shown sequentially, highlighted in `todo-search'
face."
  (interactive)
  (let ((regex (read-from-minibuffer "Enter a search string (regexp): "))
	(opoint (point))
	matches match cat in-done ov mlen msg)
    (widen)
    (goto-char (point-min))
    (while (not (eobp))
      (setq match (re-search-forward regex nil t))
      (if (and match transient-mark-mode) (deactivate-mark))
      (goto-char (line-beginning-position))
      (unless (or (equal (point) 1)
		  (looking-at (concat "^" (regexp-quote todo-category-beg))))
	(if match (push match matches)))
      (forward-line))
    (setq matches (reverse matches))
    (if matches
	(catch 'stop
	  (while matches
	    (setq match (pop matches))
	    (goto-char match)
	    (todo-item-start)
	    (when (looking-at todo-done-string-start)
	      (setq in-done t))
	    (re-search-backward (concat "^" (regexp-quote todo-category-beg)
					"\\(.*\\)\n")
                                nil t)
	    (setq cat (match-string-no-properties 1))
	    (todo-category-number cat)
	    (todo-category-select)
	    (if in-done
		(unless todo-show-with-done (todo-toggle-view-done-items)))
	    (goto-char match)
	    (setq ov (make-overlay (- (point) (length regex)) (point)))
	    (overlay-put ov 'face 'todo-search)
	    (when matches
	      (setq mlen (length matches))
	      (if (todo-y-or-n-p
		   (if (> mlen 1)
		       (format "There are %d more matches; go to next match? "
			       mlen)
		     "There is one more match; go to it? "))
		  (widen)
		(throw 'stop (setq msg (if (> mlen 1)
					   (format "There are %d more matches."
						   mlen)
					 "There is one more match."))))))
	  (setq msg "There are no more matches."))
      (todo-category-select)
      (goto-char opoint)
      (message "No match for \"%s\"" regex))
    (when msg
      (if (todo-y-or-n-p (concat msg "\nUnhighlight matches? "))
	  (todo-clear-matches)
	(message "You can unhighlight the matches later by typing %s"
		 (key-description (car (where-is-internal
					'todo-clear-matches))))))))