org-clock.el: Add nullary function evaluation as a clocktable scope parameter
* lisp/org-clock.el (org-dblock-write:clocktable): Funcall the scope argument if it is a function. * doc/org.texi: Document the feature of using a nullary function as the scope for the clocktable. * testing/lisp/test-org-clock.el: Adds a test for the above feature. Also, fix the number of hours of a test that seemed to be broken. * etc/ORG-NEWS: Add a blurb declaring the new clocktable feature. This modifies the behavior of the scope parameter to have as scope a nullary function that returns a list of file paths. --- --- doc/org.texi | 1 + etc/ORG-NEWS | 6 +++++- lisp/org-clock.el | 3 ++- testing/lisp/test-org-clock.el | 27 +++++++++++++++++++++++++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 6be76d8..a8fbd8f 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6638,6 +6638,7 @@ be selected: tree @r{the surrounding level 1 tree} agenda @r{all agenda files} ("file"..) @r{scan these files} + nullary function @r{scan the list of files returned by calling this nullary function.} file-with-archives @r{current file and its archives} agenda-with-archives @r{all agenda files, including archives} :block @r{The time block to consider. This block is specified either} diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index c115cf9..6425a51 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -27,6 +27,10 @@ into *** Agenda **** New variable : ~org-agenda-show-future-repeats~ **** New variable : ~org-agenda-prefer-last-repeat~ +*** Clock table +**** New scope argument + Added a nullary function that returns a list of files as a + possible argument for the scope of the clock table. *** Babel **** Clojure: new setting ~org-babel-clojure-sync-nrepl-timeout~ diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 65c13fd..1e78188 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2370,7 +2370,8 @@ the currently selected interval size." (`file-with-archives (and buffer-file-name (org-add-archive-files (list buffer-file-name)))) - ((pred consp) scope) + ((pred functionp) (funcall scope)) + ((pred consp) scope) (_ (or (buffer-file-name) (current-buffer))))) (block (plist-get params :block)) (ts (plist-get params :tstart)) diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index f99affc..492fc39 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -347,7 +347,7 @@ contents. The clocktable doesn't appear in the buffer." " (org-test-with-temp-text-in-file "* Test -CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 00:41] => 16905:01 +CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 01:41] => 16905:01 #+BEGIN: clocktable :scope file-with-archives #+TBLFM: $3=string(\"foo\") @@ -359,7 +359,30 @@ CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 00:41] => 16905:01 (forward-line 2) (buffer-substring-no-properties (point) (progn (goto-char (point-max)) - (line-beginning-position -1))))))) + (line-beginning-position -1)))))) + ;; test scope using a function + (should + (equal + "| File | Headline | Time | +|-----------------+------------------+--------| +| | ALL *Total time* | *1:00* | +|-----------------+------------------+--------| +" + (org-test-with-temp-text-in-file + "* Test +CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00" + (let ((the-file (buffer-file-name))) + (org-test-with-temp-text-in-file + (format "#+BEGIN: clocktable :scope (lambda () (list %S)) +#+END:" the-file) + (search-forward "#+begin:") + (beginning-of-line) + (org-update-dblock) + (forward-line 2) + (buffer-substring-no-properties + (point) + (progn (goto-char (point-max)) + (line-beginning-position -1))))))))) (provide 'test-org-clock) ;;; test-org-clock.el end here -- TINYCHANGE