From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: Directly search for Headlines? Date: Mon, 07 Jul 2014 19:54:28 +0200 Message-ID: <877g3pgiln.fsf@gmail.com> References: <3033611404741970@web12g.yandex.ru> <87pphh19jr.fsf@alphaville.bos.redhat.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4D7p-0002vO-5U for emacs-orgmode@gnu.org; Mon, 07 Jul 2014 13:54:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4D7h-0004L1-R2 for emacs-orgmode@gnu.org; Mon, 07 Jul 2014 13:54:49 -0400 Received: from plane.gmane.org ([80.91.229.3]:45529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4D7h-0004Kp-K6 for emacs-orgmode@gnu.org; Mon, 07 Jul 2014 13:54:41 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1X4D7f-0000Ci-30 for emacs-orgmode@gnu.org; Mon, 07 Jul 2014 19:54:39 +0200 Received: from e178189211.adsl.alicedsl.de ([85.178.189.211]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Jul 2014 19:54:39 +0200 Received: from tjolitz by e178189211.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 07 Jul 2014 19:54:39 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Ken Mankoff writes: > On 2014-07-07 at 11:19, Nick Dokos wrote: >> John Durden writes: >> >>> Can you search directly for headlines in all agenda-files, with the >>> name of the headline, not tags? If so, how? If not, wouldn't this be >>> useful? >>> >> >> Try `s' in the agenda perhaps? > > Yes this feature would be useful. > > "s" in agenda just saves all Org Buffers for me. for me too > My work-around is to search for "* Foo", but this doesn't find headlines > with TODO items. Internally, the necessary functionality already exists: ,----[ C-h f org-map-entries RET ] | org-map-entries is a compiled Lisp function in `org.el'. | | (org-map-entries FUNC &optional MATCH SCOPE &rest SKIP) | | Call FUNC at each headline selected by MATCH in SCOPE. | | [...] | MATCH is a tags/property/todo match as it is used in the agenda tags view. | Only headlines that are matched by this query will be considered during | the iteration. When MATCH is nil or t, all headlines will be | visited by the iteration. | | SCOPE determines the scope of this command. It can be any of: | | nil The current buffer, respecting the restriction if any | tree The subtree started with the entry at point | region The entries within the active region, if any | region-start-level | The entries within the active region, but only those at | the same level than the first one. | file The current buffer, without restriction | file-with-archives | The current buffer, and any archives associated with it | agenda All agenda files | agenda-with-archives | All agenda files with any archive files associated with them | (file1 file2 ...) | If this is a list, all files in the list will be scanned [...] `---- or ,----[ C-h f org-element-map RET ] | org-element-map is a compiled Lisp function in `org-element.el'. | | (org-element-map DATA TYPES FUN &optional INFO FIRST-MATCH | NO-RECURSION WITH-AFFILIATED) | | Map a function on selected elements or objects. | | DATA is a parse tree, an element, an object, a string, or a list | of such constructs. TYPES is a symbol or list of symbols of | elements or objects types (see `org-element-all-elements' and | `org-element-all-objects' for a complete list of types). FUN is | the function called on the matching element or object. It has to | accept one argument: the element or object itself. | [...] `---- One could either use something like this #+begin_src emacs-lisp (defun tj/match-true-headlines-1 () (interactive) (org-element-map (org-element-parse-buffer 'headline) 'headline (lambda (--entry) (let ((true-headline (org-element-property :title --entry))) (when (string-match "world" true-headline) true-headline))))) #+end_src #+results: : tj/match-true-headlines-1 or like this #+begin_src emacs-lisp (defun tj/match-true-headlines-2 () (interactive) (org-map-entries (lambda () (when (looking-at org-complex-heading-regexp) (let ((true-headline (match-string 4))) (when (string-match "world" true-headline) (org-no-properties true-headline))))))) #+end_src #+results: : tj/match-true-headlines-2 Lets try some test headlines after evaluating the above src_blocks. * Hello world ** What a wonderful world ** Nice work if you can get it *** Don't get around much anymore *** World music #+begin_src emacs-lisp :results table (tj/match-true-headlines-1) #+end_src #+results: | Hello world | What a wonderful world | World music | #+begin_src emacs-lisp :results table (delq nil (tj/match-true-headlines-2)) #+end_src #+results: | Hello world | What a wonderful world | World music | So both versions match the correct headlines in this *outorg-edit-buffer* (where I write my message-mode email in full org-mode). I don't know if this can be done with existing Org Agenda functionality (as always, its quite likely...) If not, to be useful this should be integrated in the Org Agenda framework. -- cheers, Thorsten