From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Cordival Subject: Add minlevel parameter to column view parameters Date: Tue, 17 Oct 2017 14:26:16 +0200 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4R5z-00017l-Bi for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 08:35:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4R5s-0008Ve-WE for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 08:35:43 -0400 Received: from [195.159.176.226] (port=34509 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e4R5s-0008UU-I3 for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 08:35:36 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1e4R5M-0000kp-0o for emacs-orgmode@gnu.org; Tue, 17 Oct 2017 14:35:04 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Hello, you will find attached a simple patch to add a new parameter to the column view dynamic block: minlevel. This parameter mirrors the behavior of the maxlevel parameter: only headings below a given level will be included in the table. I use this feature in documents where I want to keep a list of items (headings) on which I define properties alongside a table summarizing these properties: --=-=-= Content-Type: text/x-org Content-Disposition: inline; filename=ooo.org Content-Description: example.org * Summary #+BEGIN: columnview :id input :minlevel 3 | Year | Title | Theatre | |------+--------------------+----------| | 1995 | Scream | New York | | 1999 | Scream 2 | Tokyo | | 2013 | 500 days of summer | Paris | #+END: * Movies :PROPERTIES: :ID: input :COLUMNS: %Year %ITEM(Title) %Theatre :END: ** Horror *** Scream :PROPERTIES: :year: 1995 :theatre: New York :END: *** Scream 2 :PROPERTIES: :year: 1999 :theatre: Tokyo :END: ** Romance *** 500 days of summer :PROPERTIES: :year: 2013 :theatre: Paris :END: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-minlevel-to-column-view-parameters.patch >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. +@item :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 --=-=-= Content-Type: text/plain -- Thomas Cordival --=-=-=--