emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] sexp may retrurn a list
@ 2010-10-19 13:38 Łukasz Stelmach
  2010-10-24 20:01 ` Łukasz Stelmach
  0 siblings, 1 reply; 3+ messages in thread
From: Łukasz Stelmach @ 2010-10-19 13:38 UTC (permalink / raw)
  To: emacs-orgmode

Hi.

I've disovered, that %%(org-bbdb-anniversaries) returns (as every other
sexp) a string. Which is OK if there is only one.

  Anniversaries:  John Doe's 10th wedding anniversary

Unfortunately the agenda view becomes awful if we have noted Jane's
weeding date too 

  Anniversaries:  John Doe's 10th wedding anniversary; Jane Doe's 10th wedding anniversary

And what if we know 3 Eves and 5 Adams and it's Christmas Eve? (Hint:
their name day)

So i decided to introduce little modifications so that a sexp may return
a list of strings and org-agenda-get-sexps and org-diary-sexp-entry
functions accept that. I've modified org-bbdb-anniversaries too, so it
returns a list no matter how many anniversaries there are on a
particular day.

It looks better now, doesn't it?

  Anniversaries:  John Doe's 10th wedding anniversary
  Anniversaries:  Jane Doe's 10th wedding anniversary

The patch is backward compatible of course and if a sexp returns a
string than the output is the same as it used to be.

Behold The Patch:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index ede62e8..8544a62 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -4499,17 +4499,20 @@ the documentation of `org-diary'."
 		category (org-get-category beg)
 		todo-state (org-get-todo-state))
 
-	  (if (string-match "\\S-" result)
-	      (setq txt result)
-	    (setq txt "SEXP entry returned empty string"))
-
-	  (setq txt (org-format-agenda-item
-                     "" 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
-	    'type "sexp")
-	  (push txt ee))))
+	  (dolist (r (if (stringp result)
+			 (list result)
+		       result)) ;; we expect a list here
+	    (if (string-match "\\S-" r)
+		(setq txt r)
+	      (setq txt "SEXP entry returned empty string"))
+
+	    (setq txt (org-format-agenda-item
+		       "" 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
+	      'type "sexp")
+	    (push txt ee)))))
     (nreverse ee)))
 
 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el
index 53514f7..0d3134d 100644
--- a/lisp/org-bbdb.el
+++ b/lisp/org-bbdb.el
@@ -338,8 +338,7 @@ This is used by Org to re-create the anniversary hash table."
                 (setq text (append text (list tmp)))
               (setq text (list tmp)))))
         ))
-    (when text
-      (mapconcat 'identity text "; "))))
+    text))
 
 (defun org-bbdb-complete-link ()
   "Read a bbdb link with name completion."
diff --git a/lisp/org.el b/lisp/org.el
index 6ea9d25..62ccf1c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15020,7 +15020,7 @@ D may be an absolute day number, or a calendar-type list (month day year)."
 			      (org-current-line)
 			      (buffer-file-name) sexp)
                      (sleep-for 2))))))
-    (cond ((stringp result) result)
+    (cond ((or (listp result) (stringp result)) result)
 	  ((and (consp result)
 		(stringp (cdr result))) (cdr result))
 	  (result entry)
--8<---------------cut here---------------end--------------->8---


-- 
Miłego dnia,
Łukasz Stelmach

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

* Re: [PATCH] sexp may retrurn a list
  2010-10-19 13:38 [PATCH] sexp may retrurn a list Łukasz Stelmach
@ 2010-10-24 20:01 ` Łukasz Stelmach
  2010-10-26  5:28   ` Carsten Dominik
  0 siblings, 1 reply; 3+ messages in thread
From: Łukasz Stelmach @ 2010-10-24 20:01 UTC (permalink / raw)
  To: emacs-orgmode

Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:

> I've disovered, that %%(org-bbdb-anniversaries) returns (as every other
> sexp) a string. Which is OK if there is only one.
>
>   Anniversaries:  John Doe's 10th wedding anniversary
>
> Unfortunately the agenda view becomes awful if we have noted Jane's
> weeding date too 
>
>   Anniversaries:  John Doe's 10th wedding anniversary; Jane Doe's 10th wedding anniversary
>
> And what if we know 3 Eves and 5 Adams and it's Christmas Eve? (Hint:
> their name day)
[...]

As Thomas Bauman pointed out, there are functions that can be used in
sexps which return cons cells like this

    (nil . "Full Moon 3:35am (CEST)")

(this one is diary-lunar-phases), these aren't properly supported by the
previous version of my patch. This one can distinguish between such a
cons cell and a "real" list.

    ("John Doe's 10th wedding anniversary"
     "Jane Doe's 10th wedding anniversary")

This is because

    (consp (cdr '(a . b))) ; => nil

so org-diary-sexp-entry can be made return (cdr result) only in case of
the former cons cell. The third condition in the `cond' block is IMHO
enough as it is now, but if you think adding

    (listp (cdr result)) 

may help then be it.

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index ede62e8..8544a62 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -4499,17 +4499,20 @@ the documentation of `org-diary'."
 		category (org-get-category beg)
 		todo-state (org-get-todo-state))
 
-	  (if (string-match "\\S-" result)
-	      (setq txt result)
-	    (setq txt "SEXP entry returned empty string"))
-
-	  (setq txt (org-format-agenda-item
-                     "" 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
-	    'type "sexp")
-	  (push txt ee))))
+	  (dolist (r (if (stringp result)
+			 (list result)
+		       result)) ;; we expect a list here
+	    (if (string-match "\\S-" r)
+		(setq txt r)
+	      (setq txt "SEXP entry returned empty string"))
+
+	    (setq txt (org-format-agenda-item
+		       "" 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
+	      'type "sexp")
+	    (push txt ee)))))
     (nreverse ee)))
 
 (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el
index 53514f7..0d3134d 100644
--- a/lisp/org-bbdb.el
+++ b/lisp/org-bbdb.el
@@ -338,8 +338,7 @@ This is used by Org to re-create the anniversary hash table."
                 (setq text (append text (list tmp)))
               (setq text (list tmp)))))
         ))
-    (when text
-      (mapconcat 'identity text "; "))))
+    text))
 
 (defun org-bbdb-complete-link ()
   "Read a bbdb link with name completion."
diff --git a/lisp/org.el b/lisp/org.el
index b482b8e..c1d4e7d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -15024,7 +15024,10 @@ D may be an absolute day number, or a calendar-type list (month day year)."
                      (sleep-for 2))))))
     (cond ((stringp result) result)
 	  ((and (consp result)
+		(not (consp (cdr result)))
 		(stringp (cdr result))) (cdr result))
+	  ((and (consp result)
+		(stringp (car result))) result)
 	  (result entry)
           (t nil))))
 
--8<---------------cut here---------------end--------------->8---


-- 
Miłego dnia,
Łukasz Stelmach

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

* Re: Re: [PATCH] sexp may retrurn a list
  2010-10-24 20:01 ` Łukasz Stelmach
@ 2010-10-26  5:28   ` Carsten Dominik
  0 siblings, 0 replies; 3+ messages in thread
From: Carsten Dominik @ 2010-10-26  5:28 UTC (permalink / raw)
  To: Łukasz Stelmach; +Cc: emacs-orgmode

Applied, thanks.

- Carsten

On Oct 24, 2010, at 10:01 PM, Łukasz Stelmach wrote:

> Łukasz Stelmach <lukasz.stelmach@iem.pw.edu.pl> writes:
>
>> I've disovered, that %%(org-bbdb-anniversaries) returns (as every  
>> other
>> sexp) a string. Which is OK if there is only one.
>>
>>  Anniversaries:  John Doe's 10th wedding anniversary
>>
>> Unfortunately the agenda view becomes awful if we have noted Jane's
>> weeding date too
>>
>>  Anniversaries:  John Doe's 10th wedding anniversary; Jane Doe's  
>> 10th wedding anniversary
>>
>> And what if we know 3 Eves and 5 Adams and it's Christmas Eve? (Hint:
>> their name day)
> [...]
>
> As Thomas Bauman pointed out, there are functions that can be used in
> sexps which return cons cells like this
>
>    (nil . "Full Moon 3:35am (CEST)")
>
> (this one is diary-lunar-phases), these aren't properly supported by  
> the
> previous version of my patch. This one can distinguish between such a
> cons cell and a "real" list.
>
>    ("John Doe's 10th wedding anniversary"
>     "Jane Doe's 10th wedding anniversary")
>
> This is because
>
>    (consp (cdr '(a . b))) ; => nil
>
> so org-diary-sexp-entry can be made return (cdr result) only in case  
> of
> the former cons cell. The third condition in the `cond' block is IMHO
> enough as it is now, but if you think adding
>
>    (listp (cdr result))
>
> may help then be it.
>
> --8<---------------cut here---------------start------------->8---
> diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
> index ede62e8..8544a62 100644
> --- a/lisp/org-agenda.el
> +++ b/lisp/org-agenda.el
> @@ -4499,17 +4499,20 @@ the documentation of `org-diary'."
> 		category (org-get-category beg)
> 		todo-state (org-get-todo-state))
>
> -	  (if (string-match "\\S-" result)
> -	      (setq txt result)
> -	    (setq txt "SEXP entry returned empty string"))
> -
> -	  (setq txt (org-format-agenda-item
> -                     "" 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
> -	    'type "sexp")
> -	  (push txt ee))))
> +	  (dolist (r (if (stringp result)
> +			 (list result)
> +		       result)) ;; we expect a list here
> +	    (if (string-match "\\S-" r)
> +		(setq txt r)
> +	      (setq txt "SEXP entry returned empty string"))
> +
> +	    (setq txt (org-format-agenda-item
> +		       "" 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
> +	      'type "sexp")
> +	    (push txt ee)))))
>     (nreverse ee)))
>
> (defun org-diary-class (m1 d1 y1 m2 d2 y2 dayname &rest skip-weeks)
> diff --git a/lisp/org-bbdb.el b/lisp/org-bbdb.el
> index 53514f7..0d3134d 100644
> --- a/lisp/org-bbdb.el
> +++ b/lisp/org-bbdb.el
> @@ -338,8 +338,7 @@ This is used by Org to re-create the anniversary  
> hash table."
>                 (setq text (append text (list tmp)))
>               (setq text (list tmp)))))
>         ))
> -    (when text
> -      (mapconcat 'identity text "; "))))
> +    text))
>
> (defun org-bbdb-complete-link ()
>   "Read a bbdb link with name completion."
> diff --git a/lisp/org.el b/lisp/org.el
> index b482b8e..c1d4e7d 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -15024,7 +15024,10 @@ D may be an absolute day number, or a  
> calendar-type list (month day year)."
>                      (sleep-for 2))))))
>     (cond ((stringp result) result)
> 	  ((and (consp result)
> +		(not (consp (cdr result)))
> 		(stringp (cdr result))) (cdr result))
> +	  ((and (consp result)
> +		(stringp (car result))) result)
> 	  (result entry)
>           (t nil))))
>
> --8<---------------cut here---------------end--------------->8---
>
>
> -- 
> Miłego dnia,
> Łukasz Stelmach
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

end of thread, other threads:[~2010-10-26  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-10-19 13:38 [PATCH] sexp may retrurn a list Łukasz Stelmach
2010-10-24 20:01 ` Łukasz Stelmach
2010-10-26  5:28   ` Carsten Dominik

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).