소스 검색

Sexp diary entries may retrurn a list

* lisp/org-agenda.el (org-agenda-get-sexps): Handle lists as return values
from diary entries
* lisp/org-bbdb.el (org-bbdb-anniversaries): Handle lists of anniversaries
* lisp/org.el (org-diary-sexp-entry): Handle lists as return values
from diary entries.

 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.
Łukasz Stelmach 14 년 전
부모
커밋
47107b6612
3개의 변경된 파일18개의 추가작업 그리고 13개의 파일을 삭제
  1. 14 11
      lisp/org-agenda.el
  2. 1 2
      lisp/org-bbdb.el
  3. 3 0
      lisp/org.el

+ 14 - 11
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)

+ 1 - 2
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."

+ 3 - 0
lisp/org.el

@@ -15026,7 +15026,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))))