emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Extract prefix information from diary sexp entries for agenda display
@ 2012-04-22 22:28 Toby Cubitt
  2012-04-23 12:52 ` Bastien
  0 siblings, 1 reply; 2+ messages in thread
From: Toby Cubitt @ 2012-04-22 22:28 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2019 bytes --]

This patch adds a new org-agenda-diary-sexp-prefix customization
option. It can be set to a regexp which is used to match the part of the
text produced by a diary sexp entry that should be treated as
deadlining/scheduling information (the "prefix"), and displayed as such
in agenda views.

For example, let's say diary-remind-message is set to

  '("In " (format "%3d d." days) ":  " diary-entry)

to match the default format used for upcoming deadlines in org-mode. Then
the following diary-remind entry

  %%(diary-remind '(diary-date t 4 30) -14) Don't forget this birthday

will produce a line something like this:

  In  7 d.: Don't forget this birthday

in agenda views. But the "In 7 d.:" part will be displayed as part of the
entry, *not* in the "prefix" column where org-mode displays deadline and
scheduling information for normal org items, which looks like this:

  In  2 d.:   TODO Important thing to do soon
              In  7 d.: Don't forget this birthday
  Deadline:   TODO Do this today or else!

Setting org-agenda-diary-sexp-prefix to the regexp

  "^In +[0-9]+ d\\.:"

will extract the "In x days:" part of a diary sexp entry, and display it
as the prefix (i.e. deadline/scheduling info) for the entry in agenda
views, aligning it with the prefixes from org-mode's own deadline
entries:

  In  2 d.:   TODO Important thing to do soon
  In  7 d.:   Don't forget this birthday
  Deadline:   TODO Do this today or else!


More generally, org-mode has access to a lot of structured information
about its own agenda entries. But a diary sexp entry hands org-mode a
lump of output text, with no structure to tell it what information is
represented by different parts of that
text. `org-agenda-diary-sexp-prefix' gives you a way of telling org-mode
how to extract scheduling and deadline information from that lump of
text.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

[-- Attachment #2: 0001-Agenda-Add-org-agenda-diary-sexp-prefix-customizatio.patch --]
[-- Type: text/x-patch, Size: 2592 bytes --]

From 35e623da77892650b8a9ffab89a62a32192eab6c Mon Sep 17 00:00:00 2001
From: "Toby S. Cubitt" <tsc25@cantab.net>
Date: Sun, 29 Jan 2012 10:51:46 +0100
Subject: [PATCH] Agenda: Add org-agenda-diary-sexp-prefix customization
 option

* lisp/org-agenda.el (org-agenda-diary-sexp-prefix): Regexp matching
deadline/scheduling information to be displayed in diary sexp agenda
items.
(org-agenda-get-sexps): Extract deadline/scheduling information from
diary sexp entries.
---
 lisp/org-agenda.el |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 796f158..1af37c1 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -1516,6 +1516,16 @@ to occupy a fixed space in the agenda display."
   :group 'org-agenda-line-format
   :type 'string)
 
+(defcustom org-agenda-diary-sexp-prefix nil
+  "A regexp that matches part of a diary sexp entry
+which should be treated as scheduling/deadline information in
+`org-agenda'.
+
+For example, you can use this to extract the `diary-remind-message' from
+`diary-remind' entries."
+  :group 'org-agenda-line-format
+  :type '(choice (const :tag "None" nil) (regexp :tag "Regexp")))
+
 (defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
   "Text preceding timerange entries in the agenda view.
 This is a list with two strings.  The first applies when the range
@@ -5046,7 +5056,7 @@ This function is invoked if `org-agenda-todo-ignore-deadlines',
 		      (format "mouse-2 or RET jump to org file %s"
 			      (abbreviate-file-name buffer-file-name))))
 	 (regexp "^&?%%(")
-	 marker category org-category-pos ee txt tags entry
+	 marker category extra org-category-pos ee txt tags entry
 	 result beg b sexp sexp-entry todo-state)
     (goto-char (point-min))
     (while (re-search-forward regexp nil t)
@@ -5070,12 +5080,16 @@ This function is invoked if `org-agenda-todo-ignore-deadlines',
 	  (dolist (r (if (stringp result)
 			 (list result)
 		       result)) ;; we expect a list here
+	    (when (and org-agenda-diary-sexp-prefix
+		       (string-match org-agenda-diary-sexp-prefix r))
+	      (setq extra (match-string 0 r)
+		    r (replace-match "" nil nil r)))
 	    (if (string-match "\\S-" r)
 		(setq txt r)
 	      (setq txt "SEXP entry returned empty string"))
 
 	    (setq txt (org-agenda-format-item
-		       "" txt category tags 'time))
+		       extra txt category tags 'time))
 	    (org-add-props txt props 'org-marker marker)
 	    (org-add-props txt nil
 	      'org-category category 'date date 'todo-state todo-state
-- 
1.7.8.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Extract prefix information from diary sexp entries for agenda display
  2012-04-22 22:28 [PATCH] Extract prefix information from diary sexp entries for agenda display Toby Cubitt
@ 2012-04-23 12:52 ` Bastien
  0 siblings, 0 replies; 2+ messages in thread
From: Bastien @ 2012-04-23 12:52 UTC (permalink / raw)
  To: emacs-orgmode

Toby Cubitt <tsc25@cantab.net> writes:

> This patch adds a new org-agenda-diary-sexp-prefix customization
> option. It can be set to a regexp which is used to match the part of the
> text produced by a diary sexp entry that should be treated as
> deadlining/scheduling information (the "prefix"), and displayed as such
> in agenda views.

Applied, thanks.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-23 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-22 22:28 [PATCH] Extract prefix information from diary sexp entries for agenda display Toby Cubitt
2012-04-23 12:52 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).