>From e72280536137057dfe2fb30d5e1a7147e43c9405 Mon Sep 17 00:00:00 2001 From: Thomas Cordival Date: Tue, 17 Oct 2017 13:57:11 +0200 Subject: [PATCH] Add minlevel to column view parameters * lisp/org-colview.el (org-columns--capture-view): Add logic to build the match string * testing/lisp/test-org-colview.el (test-org-colview/dblock): Add tests for maxlevel and minlevel * doc/org.texi: Describe the new minlevel parameter --- doc/org.texi | 2 + lisp/org-colview.el | 26 +++++++++---- testing/lisp/test-org-colview.el | 79 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 8 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 728e73f87..cf0051c7d 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -5830,6 +5830,8 @@ When @code{t}, insert an hline after every line. When a number @var{N}, insert an hline before each headline with level @code{<= @var{N}}. @item :vlines When set to @code{t}, force column groups to get vertical lines. address@hidden :minlevel +When set to a number, don't capture entries above this level. @item :maxlevel When set to a number, don't capture entries below this level. @item :skip-empty-rows diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 2a427aecc..074df3f08 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -1325,14 +1325,14 @@ and variances (respectively) of the individual estimates." ;;; Dynamic block for Column view -(defun org-columns--capture-view (maxlevel skip-empty format local) +(defun org-columns--capture-view (minlevel maxlevel skip-empty format local) "Get the column view of the current buffer. -MAXLEVEL sets the level limit. SKIP-EMPTY tells whether to skip -empty rows, an empty row being one where all the column view -specifiers but ITEM are empty. FORMAT is a format string for -columns, or nil. When LOCAL is non-nil, only capture headings in -current subtree. +MINLEVEL set the upper level limit. MAXLEVEL sets the deeper +level limit. SKIP-EMPTY tells whether to skip empty rows, an +empty row being one where all the column view specifiers but ITEM +are empty. FORMAT is a format string for columns, or nil. When +LOCAL is non-nil, only capture headings in current subtree. This function returns a list containing the title row and all other rows. Each row is a list of fields, as strings, or @@ -1360,7 +1360,15 @@ other rows. Each row is a list of fields, as strings, or (or (null r) (and has-item (= (length r) 1))))) (push (cons (org-reduced-level (org-current-level)) (nreverse row)) table))))) - (and maxlevel (format "LEVEL<=%d" maxlevel)) + (if (and minlevel maxlevel) + (format "LEVEL>=%d&LEVEL<=%d" minlevel maxlevel) + (if minlevel + (format "LEVEL>=%d" minlevel) + (if maxlevel + (format "LEVEL<=%d" maxlevel)) + )) + ;; (and (or (not minlevel) (format "LEVEL>=%d" minlevel)) + ;; (or (not maxlevel) (format "LEVEL<=%d" maxlevel))) (and local 'tree) 'archive 'comment) (org-columns-quit) @@ -1397,6 +1405,7 @@ PARAMS is a property list of parameters: a hline before each level <= that number. :indent When non-nil, indent each ITEM field according to its level. :vlines When t, make each column a colgroup to enforce vertical lines. +:minlevel When set to a number, don't capture headlines above this level. :maxlevel When set to a number, don't capture headlines below this level. :skip-empty-rows When t, skip rows where all specifiers other than ITEM are empty. @@ -1422,7 +1431,8 @@ PARAMS is a property list of parameters: (current-buffer)) (org-with-wide-buffer (when view-pos (goto-char view-pos)) - (org-columns--capture-view (plist-get params :maxlevel) + (org-columns--capture-view (plist-get params :minlevel) + (plist-get params :maxlevel) (plist-get params :skip-empty-rows) (plist-get params :format) view-pos)))))) diff --git a/testing/lisp/test-org-colview.el b/testing/lisp/test-org-colview.el index e6b02b9e1..0374d58a8 100644 --- a/testing/lisp/test-org-colview.el +++ b/testing/lisp/test-org-colview.el @@ -1508,6 +1508,85 @@ (org-test-with-temp-text "* H src_emacs-lisp{(+ 1 1)} 1\n#+BEGIN: columnview\n#+END:" (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) + (buffer-substring-no-properties (point) (point-max))))) + + "Test column view table respects minlevel" + (should + (equal + "#+BEGIN: columnview :id input :minlevel 2 +| ITEM | +|------| +| H1 | +| H1.1 | +| H1.2 | +| H2 | +| H2.1 | +#+END:" + (org-test-with-temp-text + "* In +:PROPERTIES: +:ID: input +:END: +** H1 +*** H1.1 +*** H1.2 +** H2 +*** H2.1 +* Out +#+BEGIN: columnview :id input :minlevel 2 +#+END:" + (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) + (buffer-substring-no-properties (point) (point-max))))) + + "Test column view table respects maxlevel" + (should + (equal + "#+BEGIN: columnview :id input :maxlevel 2 +| ITEM | +|------| +| In | +| H1 | +| H2 | +#+END:" + (org-test-with-temp-text + "* In +:PROPERTIES: +:ID: input +:END: +** H1 +*** H1.1 +*** H1.2 +** H2 +*** H2.1 +* Out +#+BEGIN: columnview :id input :maxlevel 2 +#+END:" + (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) + (buffer-substring-no-properties (point) (point-max))))) + + "Test column view table respects maxlevel and minlevel" + (should + (equal + "#+BEGIN: columnview :id input :maxlevel 2 :minlevel 2 +| ITEM | +|------| +| H1 | +| H2 | +#+END:" + (org-test-with-temp-text + "* In +:PROPERTIES: +:ID: input +:END: +** H1 +*** H1.1 +*** H1.2 +** H2 +*** H2.1 +* Out +#+BEGIN: columnview :id input :maxlevel 2 :minlevel 2 +#+END:" + (let ((org-columns-default-format "%ITEM")) (org-update-dblock)) (buffer-substring-no-properties (point) (point-max)))))) (provide 'test-org-colview) -- 2.11.0