I have just started using emacs-org to index news headlines.

I've adopted the convention: <2018-10-10 Wed> Key Headline :TAG:

Here's a concrete example (with made up headlines). Say that i'm tracking news about Trump. A collection of headlines may look at below -- i use C-c C-d to insert the timestamp generated by org-deadline-string.

* Trump says China not seeking deal seriously :China:
 DEADLINE: <2018-10-11 Thu> 
* Trump says he will meet Kim :NorthKorea:
 DEADLINE: <2018-10-10 Wed> 
** Trump says NK is special place
** Trump says Kim a good man
* Trump says China ready to do a trade deal :China:
 DEADLINE: <2018-10-08 Mon> 
* Trump says not happy with Kim :NorthKorea:
 DEADLINE: <2018-09-02 Sun> 

I wish to query these headlines by tag and timestamp. Say to see only headlines tagged :China: after 10 October.

How might i do this?

  • I think some more details are needed. What do you mean by "subset"? Do you mean query? Sort? – user1462309 Oct 10 at 17:21
  • The org-deadline-string and org-scheduled-string can be customized to say anything; e.g., instead of DEADLINE: it could say DATE:. Org-mode has built-in sorting options for deadline and scheduled entries. To insert the timestamps, use C-c C-d or C-c C-s. Org-mode expects one or more leading stars at the beginning of a headline. – lawlist Oct 10 at 20:50
  • @user1462309 i added some more detail. – ricardo Oct 10 at 23:00
  • @lawlist i found that C-c < gave me what i wanted with dates, as i don't really want any text. Is it possible to get by using these types of entries? If so, how do i next select entries in some date range? – ricardo Oct 10 at 23:29
  • As far as I am aware, the format you wish to use does not match the org-complex-heading-regexp; and, much of the builtin sorting and org-agenda stuff may not work as one would expect. There is always a way to sort things in Emacs using a proper regex; however, you may need to create some custom stuff to make it all work. In an org-mode buffer you can type M-x describe-variable RET org-complex-heading-regexp RET and see what I am talking about. Then you can grep the org source code directory for org-complex-heading-regexp and see just how many functions rely upon that format .... – lawlist Oct 10 at 23:38
up vote 2 down vote accepted

Step 1:   Copy and paste the following test data into a *scratch* buffer:

* Trump says China not seeking deal seriously :China:
  DEADLINE: <2018-10-11 Thu>
* Trump says he will meet Kim :NorthKorea:
  DEADLINE: <2018-10-10 Wed>
** Trump says NK is special place
** Trump says Kim a good man
* Trump says China ready to do a trade deal :China:
  DEADLINE: <2018-10-08 Mon>
* Trump says not happy with Kim :NorthKorea:
  DEADLINE: <2018-09-02 Sun>

Step 2:  Save the buffer to a file, e.g., ~/Desktop/test.org. By default, Emacs will assume the new file with an *.org extension should be org-mode. We do not have to use that extension, but it is convenient and helpful for a variety of reasons ... beyond the scope of this answer. If the buffer is not in org-mode after saving it, then type M-x org-mode.

Step 3:  Add the new file to the variable org-agenda-files, which can be done a variety of ways. [For more details on how to configure that variable, type M-x describe-variable RET org-agenda-files RET or C-h v ....] E.g., (setq org-agenda-files '("~/Desktop/test.org"))

Step 4:  Type M-x eval-expression RET (org-tags-view nil "DEADLINE>=\"<2018-10-11>\"&DEADLINE<=\"<+1y>\"&ALLTAGS={china}") RET. [The keyboard shortcut to evaluate an expression is M-:] This example is searching for all matching criteria from 10/11/2018 to 10/10/2019 (i.e., 1 year) and tags with a regex of china.

Step 5:  The result returned in the *Org Agenda* buffer is:

Headlines with TAGS match: DEADLINE>="<2018-10-11>"&DEADLINE<="<+1y>"&ALLTAGS={china}

Press ‘C-u r’ to search again with new search string

test:       Trump says China not seeking deal seriously                :China:

To create custom preset commands, check out this example: https://emacs.stackexchange.com/a/22062/2287

To learn about advanced searching, check out this page from the org manual: https://orgmode.org/worg/org-tutorials/advanced-searching.html

The above-example can be used in conjunction with let-bound variables such as org-agenda-sorting-strategy .... [Beyond the scope of this answer.]

Instead of using a file-visiting-buffer, the user may wish to use a sparse-tree search [which can be either a non-file-visiting-bufffer or a file-visiting-buffer] ... again, beyond the scope of this answer ...

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.