emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 6/7] Use org-eval-in-environment, make macros functions


From: David Maus
Subject: [O] [PATCH 6/7] Use org-eval-in-environment, make macros functions
Date: Tue, 2 Aug 2011 11:23:39 +0200

* org-agenda.el (org-batch-agenda, org-batch-agenda-csv): Make
a function, use org-eval-in-environment.
---
 lisp/org-agenda.el |   59 ++++++++++++++++++++++-----------------------------
 1 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 25a556e..6079377 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -2569,22 +2569,19 @@ s   Search for keywords                 C   Configure 
custom agenda commands
   (org-let (nth 1 series) '(org-finalize-agenda)))
 
 ;;;###autoload
-(defmacro org-batch-agenda (cmd-key &rest parameters)
+(defun org-batch-agenda (cmd-key &rest parameters)
   "Run an agenda command in batch mode and send the result to STDOUT.
 If CMD-KEY is a string of length 1, it is used as a key in
 `org-agenda-custom-commands' and triggers this command.  If it is a
 longer string it is used as a tags/todo match string.
 Parameters are alternating variable names and values that will be bound
 before running the agenda command."
-  (let (pars)
-    (while parameters
-      (push (list (pop parameters) (if parameters (pop parameters))) pars))
+  (org-eval-in-environment (org-make-parameter-alist parameters)
     (if (> (length cmd-key) 2)
-       (eval (list 'let (nreverse pars)
-                   (list 'org-tags-view nil cmd-key)))
-      (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
-    (set-buffer org-agenda-buffer-name)
-    (princ (org-encode-for-stdout (buffer-string)))))
+       (org-tags-view nil cmd-key)
+      (org-agenda nil cmd-key)))
+  (set-buffer org-agenda-buffer-name)
+  (princ (org-encode-for-stdout (buffer-string))))
 
 ;(defun org-encode-for-stdout (string)
 ;  (if (fboundp 'encode-coding-string)
@@ -2597,7 +2594,7 @@ before running the agenda command."
 (defvar org-agenda-info nil)
 
 ;;;###autoload
-(defmacro org-batch-agenda-csv (cmd-key &rest parameters)
+(defun org-batch-agenda-csv (cmd-key &rest parameters)
   "Run an agenda command in batch mode and send the result to STDOUT.
 If CMD-KEY is a string of length 1, it is used as a key in
 `org-agenda-custom-commands' and triggers this command.  If it is a
@@ -2631,30 +2628,26 @@ extra        Sting with extra planning info
 priority-l   The priority letter if any was given
 priority-n   The computed numerical priority
 agenda-day   The day in the agenda where this is listed"
-
-  (let (pars)
-    (while parameters
-      (push (list (pop parameters) (if parameters (pop parameters))) pars))
-    (push (list 'org-agenda-remove-tags t) pars)
+  (org-eval-in-environment (append (org-agenda-remove-tags t)
+                                  (org-make-parameter-alist parameters))
     (if (> (length cmd-key) 2)
-       (eval (list 'let (nreverse pars)
-                   (list 'org-tags-view nil cmd-key)))
-      (eval (list 'let (nreverse pars) (list 'org-agenda nil cmd-key))))
-    (set-buffer org-agenda-buffer-name)
-    (let* ((lines (org-split-string (buffer-string) "\n"))
-          line)
-      (while (setq line (pop lines))
-       (catch 'next
-         (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
-         (setq org-agenda-info
-               (org-fix-agenda-info (text-properties-at 0 line)))
-         (princ
-          (org-encode-for-stdout
-           (mapconcat 'org-agenda-export-csv-mapper
-                      '(org-category txt type todo tags date time extra
-                                     priority-letter priority agenda-day)
-                     ",")))
-         (princ "\n"))))))
+       (org-tags-view nil cmd-key)
+      (org-agenda nil cmd-key)))
+  (set-buffer org-agenda-buffer-name)
+  (let* ((lines (org-split-string (buffer-string) "\n"))
+        line)
+    (while (setq line (pop lines))
+      (catch 'next
+       (if (not (get-text-property 0 'org-category line)) (throw 'next nil))
+       (setq org-agenda-info
+             (org-fix-agenda-info (text-properties-at 0 line)))
+       (princ
+        (org-encode-for-stdout
+         (mapconcat 'org-agenda-export-csv-mapper
+                    '(org-category txt type todo tags date time extra
+                                   priority-letter priority agenda-day)
+                    ",")))
+       (princ "\n")))))
 
 (defun org-fix-agenda-info (props)
   "Make sure all properties on an agenda item have a canonical form.
-- 
1.7.2.5




reply via email to

[Prev in Thread] Current Thread [Next in Thread]