From 78bddaca1fc623bcf5fe7868c28ecaf4b21f3d7d Mon Sep 17 00:00:00 2001 From: Eduardo Bellani Date: Mon, 6 Mar 2017 17:57:31 +0100 Subject: [PATCH] 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. TINYCHANGE --- doc/org.texi | 1 + etc/ORG-NEWS | 3 +++ lisp/org-clock.el | 1 + testing/lisp/test-org-clock.el | 15 +++++++++++++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index fcd77aaf9..ccb469f20 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -6635,6 +6635,7 @@ be selected: tree @r{the surrounding level 1 tree} agenda @r{all agenda files} ("file"..) @r{scan these files} + function @r{the list of files returned by a function of no argument} 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 5abbd586e..29593b460 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -159,6 +159,9 @@ Select * From Users Where clue > 0 ,#+END_SRC #+end_example +*** New ~function~ scope argument for the Clock Table +Added a nullary function that returns a list of files as a possible +argument for the scope of the clock table. *** Export **** Add Slovanian translations **** Implement ~org-export-insert-image-links~ diff --git a/lisp/org-clock.el b/lisp/org-clock.el index 7b92caafd..01799653c 100644 --- a/lisp/org-clock.el +++ b/lisp/org-clock.el @@ -2378,6 +2378,7 @@ the currently selected interval size." (`file-with-archives (and buffer-file-name (org-add-archive-files (list buffer-file-name)))) + ((pred functionp) (funcall scope)) ((pred consp) scope) (_ (or (buffer-file-name) (current-buffer))))) (block (plist-get params :block)) diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el index f308797e3..665edd3cc 100644 --- a/testing/lisp/test-org-clock.el +++ b/testing/lisp/test-org-clock.el @@ -351,9 +351,20 @@ the buffer." #+TBLFM: $3=string(\"foo\")" (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" (test-org-clock-clocktable-contents ":scope file-with-archives" - "#+TBLFM: $3=string(\"foo\")"))))) + "#+TBLFM: $3=string(\"foo\")")))) + ;; Test "function" scope. + (should + (string-match-p + (regexp-quote "| 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 "" + (test-org-clock-clocktable-contents + (format ":scope (lambda () (list %S))" the-file)))))))) (ert-deftest test-org-clock/clocktable/maxlevel () "Test \":maxlevel\" parameter in Clock table."