Browse Source

Implement TODO-only search and bettwe ord boundaries.

Carsten Dominik 17 years ago
parent
commit
469caa5ff6
3 changed files with 118 additions and 60 deletions
  1. 13 0
      ChangeLog
  2. 10 0
      ORGWEBPAGE/Changes.org
  3. 95 60
      org.el

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2008-03-13  Carsten Dominik  <dominik@science.uva.nl>
+
+	* org.el (org-search-view): Add more text properties.
+	(org-agenda-schedule, org-agenda-deadline): Allow also in
+	search-type agendas.
+	(org-search-view): Order of arguments has been changed.
+	Interpret prefix-arg as TODO-ONLY.
+	(org-agenda, org-run-agenda-series, org-agenda-manipulate-query):
+	Take new argument order of `org-search-view' into account.
+	(org-todo-only): New variable.
+	(org-search-syntax-table): New variable and function.
+	(org-search-view): Do the search with the special syntax table.
+
 2008-03-13  Phil Jackson  <phil@shellarchive.co.uk>
 2008-03-13  Phil Jackson  <phil@shellarchive.co.uk>
 
 
 	* org-irc.el: New function to ensure port number is always
 	* org-irc.el: New function to ensure port number is always

+ 10 - 0
ORGWEBPAGE/Changes.org

@@ -9,6 +9,16 @@
 
 
 ** Details
 ** Details
 
 
+*** Improvements in Search View
+    
+    - Calling search view with a C-u prefix will makt it match
+      only in TODO entries.
+
+    - The single quote is no longer considered a word character
+      durin search, so that searching for the word "Nasim" will
+      also match in "Nasim's".
+
+*** Misc
    - When an entry already has a scheduling or deadline time
    - When an entry already has a scheduling or deadline time
      stamp, calling `C-c C-s' or `C-c C-d', respectively, will no
      stamp, calling `C-c C-s' or `C-c C-d', respectively, will no
      use that old date as the default, and you can can use the
      use that old date as the default, and you can can use the

+ 95 - 60
org.el

@@ -20012,7 +20012,7 @@ Pressing `<' twice means to restrict to the current subtree or region
 	       ((eq type 'alltodo)
 	       ((eq type 'alltodo)
 		(org-let lprops '(org-todo-list current-prefix-arg)))
 		(org-let lprops '(org-todo-list current-prefix-arg)))
 	       ((eq type 'search)
 	       ((eq type 'search)
-		(org-let lprops '(org-search-view current-prefix-arg match)))
+		(org-let lprops '(org-search-view current-prefix-arg match nil)))
 	       ((eq type 'stuck)
 	       ((eq type 'stuck)
 		(org-let lprops '(org-agenda-list-stuck-projects
 		(org-let lprops '(org-agenda-list-stuck-projects
 				  current-prefix-arg)))
 				  current-prefix-arg)))
@@ -20240,7 +20240,7 @@ s   Search for keywords                 C   Configure custom agenda commands
 	  '(call-interactively 'org-todo-list)))
 	  '(call-interactively 'org-todo-list)))
        ((eq type 'search)
        ((eq type 'search)
 	(org-let2 gprops lprops
 	(org-let2 gprops lprops
-		  '(org-search-view current-prefix-arg match)))
+		  '(org-search-view current-prefix-arg match nil)))
        ((eq type 'stuck)
        ((eq type 'stuck)
 	(org-let2 gprops lprops
 	(org-let2 gprops lprops
 	  '(call-interactively 'org-agenda-list-stuck-projects)))
 	  '(call-interactively 'org-agenda-list-stuck-projects)))
@@ -21193,13 +21193,32 @@ given in `org-agenda-start-on-weekday'."
 ;;; Agenda word search
 ;;; Agenda word search
 
 
 (defvar org-agenda-search-history nil)
 (defvar org-agenda-search-history nil)
+(defvar org-todo-only nil)
+
+(defvar org-search-syntax-table nil
+  "Special syntax table for org-mode search.
+In this table, we have single quotes not as word constituents, to
+that when \"+Ameli\" is searchd as a work, it will also match \"Ameli's\"")
+
+(defun org-search-syntax-table ()
+  (unless org-search-syntax-table
+    (setq org-search-syntax-table (copy-syntax-table org-mode-syntax-table))
+    (modify-syntax-entry ?' "." org-search-syntax-table)
+    (modify-syntax-entry ?` "." org-search-syntax-table))
+  org-search-syntax-table)
 
 
 ;;;###autoload
 ;;;###autoload
-(defun org-search-view (&optional arg string)
+(defun org-search-view (&optional todo-only string edit-at)
   "Show all entries that contain words or regular expressions.
   "Show all entries that contain words or regular expressions.
 If the first character of the search string is an asterisks,
 If the first character of the search string is an asterisks,
 search only the headlines.
 search only the headlines.
 
 
+With optional prefix argument TODO-ONLY, only consider entries that are
+TODO entries.  The argument STRING can be used to pass a default search
+string into this function.  If EDIT-AT is non-nil, it means that the
+user should get a chance to edit this string, with cursor at position
+EDIT-AT.
+
 The search string is broken into \"words\" by splitting at whitespace.
 The search string is broken into \"words\" by splitting at whitespace.
 The individual words are then interpreted as a boolean expression with
 The individual words are then interpreted as a boolean expression with
 logical AND.  Words prefixed with a minus must not occur in the entry.
 logical AND.  Words prefixed with a minus must not occur in the entry.
@@ -21209,6 +21228,11 @@ Matching is case-insensitive and the words are enclosed by word delimiters.
 Words enclosed by curly braces are interpreted as regular expressions
 Words enclosed by curly braces are interpreted as regular expressions
 that must or must not match in the entry.
 that must or must not match in the entry.
 
 
+If the search string starts with an asterisk, search only in headlines.
+If (possibly after the leading star) the search string starts with an
+exclamation mark, this also means to look at TODO entries only, an effect
+that can also be achieved with a prefix argument.
+
 This command searches the agenda files, and in addition the files listed
 This command searches the agenda files, and in addition the files listed
 in `org-agenda-text-search-extra-files'."
 in `org-agenda-text-search-extra-files'."
   (interactive "P")
   (interactive "P")
@@ -21225,22 +21249,27 @@ in `org-agenda-text-search-extra-files'."
 	 regexp rtn rtnall files file pos
 	 regexp rtn rtnall files file pos
 	 marker priority category tags c neg re
 	 marker priority category tags c neg re
 	 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
 	 ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str)
-    (unless (and (not arg)
+    (unless (and (not edit-at)
 		 (stringp string)
 		 (stringp string)
 		 (string-match "\\S-" string))
 		 (string-match "\\S-" string))
       (setq string (read-string "[+-]Word/{Regexp} ...: "
       (setq string (read-string "[+-]Word/{Regexp} ...: "
 				(cond
 				(cond
-				 ((integerp arg) (cons string arg))
+				 ((integerp edit-at) (cons string edit-at))
-				 (arg string))
+				 (edit-at string))
 				'org-agenda-search-history)))
 				'org-agenda-search-history)))
+    (org-set-local 'org-todo-only todo-only)
     (setq org-agenda-redo-command
     (setq org-agenda-redo-command
-	  (list 'org-search-view 'current-prefix-arg string))
+	  (list 'org-search-view (if todo-only t nil) string
+		'(if current-prefix-arg 1 nil)))
     (setq org-agenda-query-string string)
     (setq org-agenda-query-string string)
 
 
     (if (equal (string-to-char string) ?*)
     (if (equal (string-to-char string) ?*)
 	(setq hdl-only t
 	(setq hdl-only t
 	      words (substring string 1))
 	      words (substring string 1))
       (setq words string))
       (setq words string))
+    (when (equal (string-to-char words) ?!)
+      (setq todo-only t
+	    words (substring words 1)))
     (setq words (org-split-string words))
     (setq words (org-split-string words))
     (mapc (lambda (w)
     (mapc (lambda (w)
 	    (setq c (string-to-char w))
 	    (setq c (string-to-char w))
@@ -21274,55 +21303,60 @@ in `org-agenda-text-search-extra-files'."
 	    (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
 	    (setq rtn (list (format "ORG-AGENDA-ERROR: No such org-file %s"
 				    file))))
 				    file))))
 	(with-current-buffer buffer
 	(with-current-buffer buffer
-	  (unless (org-mode-p)
+	  (with-syntax-table (org-search-syntax-table)
-	    (error "Agenda file %s is not in `org-mode'" file))
+	    (unless (org-mode-p)
-	  (let ((case-fold-search t))
+	      (error "Agenda file %s is not in `org-mode'" file))
-	    (save-excursion
+	    (let ((case-fold-search t))
-	      (save-restriction
+	      (save-excursion
-		(if org-agenda-restrict
+		(save-restriction
-		    (narrow-to-region org-agenda-restrict-begin
+		  (if org-agenda-restrict
-				      org-agenda-restrict-end)
+		      (narrow-to-region org-agenda-restrict-begin
-		  (widen))
+					org-agenda-restrict-end)
-		(goto-char (point-min))
+		    (widen))
-		(unless (or (org-on-heading-p)
+		  (goto-char (point-min))
-			    (outline-next-heading))
+		  (unless (or (org-on-heading-p)
-		  (throw 'nextfile t))
+			      (outline-next-heading))
-		(goto-char (max (point-min) (1- (point))))
+		    (throw 'nextfile t))
-		(while (re-search-forward regexp nil t)
+		  (goto-char (max (point-min) (1- (point))))
-		  (org-back-to-heading t)
+		  (while (re-search-forward regexp nil t)
-		  (skip-chars-forward "* ")
+		    (org-back-to-heading t)
-		  (setq beg (point-at-bol)
+		    (skip-chars-forward "* ")
-			beg1 (point)
+		    (setq beg (point-at-bol)
-			end (progn (outline-next-heading) (point)))
+			  beg1 (point)
-		  (catch :skip
+			  end (progn (outline-next-heading) (point)))
-		    (goto-char beg)
+		    (catch :skip
-		    (org-agenda-skip)
+		      (goto-char beg)
-		    (setq str (buffer-substring-no-properties
+		      (org-agenda-skip)
-			       (point-at-bol)
+		      (setq str (buffer-substring-no-properties
-			       (if hdl-only (point-at-eol) end)))
+				 (point-at-bol)
-		    (mapc (lambda (wr) (when (string-match wr str)
+				 (if hdl-only (point-at-eol) end)))
-					 (goto-char (1- end))
+		      (mapc (lambda (wr) (when (string-match wr str)
-					 (throw :skip t)))
+					   (goto-char (1- end))
-			  regexps-)
+					   (throw :skip t)))
-		    (mapc (lambda (wr) (unless (string-match wr str)
+			    regexps-)
-					 (goto-char (1- end))
+		      (mapc (lambda (wr) (unless (string-match wr str)
-					 (throw :skip t)))
+					   (goto-char (1- end))
-			  regexps+)
+					   (throw :skip t)))
-		    (goto-char beg)
+			    (if todo-only
-		    (setq marker (org-agenda-new-marker (point))
+				(cons (concat "^\*+[ \t]+" org-not-done-regexp)
-			  category (org-get-category)
+				      regexps+)
-			  tags (org-get-tags-at (point))
+			      regexps+))
-			  txt (org-format-agenda-item
+		      (goto-char beg)
-			       ""
+		      (setq marker (org-agenda-new-marker (point))
-			       (buffer-substring-no-properties
+			    category (org-get-category)
-				beg1 (point-at-eol))
+			    tags (org-get-tags-at (point))
-			       category tags))
+			    txt (org-format-agenda-item
-		    (org-add-props txt props
+				 ""
-		      'org-marker marker 'org-hd-marker marker
+				 (buffer-substring-no-properties
-		      'priority 1000 'org-category category
+				  beg1 (point-at-eol))
-		      'type "search")
+				 category tags))
-		    (push txt ee)
+		      (org-add-props txt props
-		    (goto-char (1- end)))))))))
+			'org-marker marker 'org-hd-marker marker
+			'org-todo-regexp org-todo-regexp
+			'priority 1000 'org-category category
+			'type "search")
+		      (push txt ee)
+		      (goto-char (1- end))))))))))
       (setq rtn (nreverse ee))
       (setq rtn (nreverse ee))
       (setq rtnall (append rtnall rtn)))
       (setq rtnall (append rtnall rtn)))
     (if org-agenda-overriding-header
     (if org-agenda-overriding-header
@@ -22823,9 +22857,10 @@ Negative selection means, regexp must not match for selection of an entry."
 			(?\{ . " +{}") (?\} . " -{}")))))
 			(?\{ . " +{}") (?\} . " -{}")))))
     (setq org-agenda-redo-command
     (setq org-agenda-redo-command
 	  (list 'org-search-view
 	  (list 'org-search-view
+		org-todo-only
+		org-agenda-query-string
 		(+ (length org-agenda-query-string)
 		(+ (length org-agenda-query-string)
-		   (if (member char '(?\{ ?\})) 0 1))
+		   (if (member char '(?\{ ?\})) 0 1))))
-		org-agenda-query-string))
     (set-register org-agenda-query-register org-agenda-query-string)
     (set-register org-agenda-query-register org-agenda-query-string)
     (org-agenda-redo))
     (org-agenda-redo))
    (t (error "Canot manipulate query for %s-type agenda buffers"
    (t (error "Canot manipulate query for %s-type agenda buffers"
@@ -23575,7 +23610,7 @@ be used to request time specification in the time stamp."
 (defun org-agenda-schedule (arg)
 (defun org-agenda-schedule (arg)
   "Schedule the item at point."
   "Schedule the item at point."
   (interactive "P")
   (interactive "P")
-  (org-agenda-check-type t 'agenda 'timeline 'todo 'tags)
+  (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
   (org-agenda-check-no-diary)
   (org-agenda-check-no-diary)
   (let* ((marker (or (get-text-property (point) 'org-marker)
   (let* ((marker (or (get-text-property (point) 'org-marker)
 		     (org-agenda-error)))
 		     (org-agenda-error)))
@@ -23597,7 +23632,7 @@ be used to request time specification in the time stamp."
 (defun org-agenda-deadline (arg)
 (defun org-agenda-deadline (arg)
   "Schedule the item at point."
   "Schedule the item at point."
   (interactive "P")
   (interactive "P")
-  (org-agenda-check-type t 'agenda 'timeline 'todo 'tags)
+  (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
   (org-agenda-check-no-diary)
   (org-agenda-check-no-diary)
   (let* ((marker (or (get-text-property (point) 'org-marker)
   (let* ((marker (or (get-text-property (point) 'org-marker)
 		     (org-agenda-error)))
 		     (org-agenda-error)))