emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Add minlevel parameter to column view parameters
@ 2017-10-17 12:26 Thomas Cordival
  2017-10-19 19:33 ` Nicolas Goaziou
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Cordival @ 2017-10-17 12:26 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 401 bytes --]

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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: example.org --]
[-- Type: text/x-org, Size: 568 bytes --]

* 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:

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Add-minlevel-to-column-view-parameters.patch --]
[-- Type: text/x-patch, Size: 6038 bytes --]

From e72280536137057dfe2fb30d5e1a7147e43c9405 Mon Sep 17 00:00:00 2001
From: Thomas Cordival <thomas@tuxella.me>
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."
 \f
 ;;; 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<point>#+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
+<point>#+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
+<point>#+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
+<point>#+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


[-- Attachment #4: Type: text/plain, Size: 20 bytes --]


--
Thomas Cordival

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Add minlevel parameter to column view parameters
  2017-10-17 12:26 Add minlevel parameter to column view parameters Thomas Cordival
@ 2017-10-19 19:33 ` Nicolas Goaziou
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Goaziou @ 2017-10-19 19:33 UTC (permalink / raw)
  To: Thomas Cordival; +Cc: emacs-orgmode

Hello,

Thomas Cordival <thomas@tuxella.me> writes:

> you will find attached a simple patch to add a new parameter to the
> column view dynamic block: minlevel.

Thank you!

> +     (if (and minlevel maxlevel)
> +	 (format "LEVEL>=%d&LEVEL<=%d" minlevel maxlevel)
> +       (if minlevel
> +	   (format "LEVEL>=%d" minlevel)
> +	 (if maxlevel
> +	     (format "LEVEL<=%d" maxlevel))
> +	 ))

This could be refactored into a `cond'.

> +     ;; (and (or (not minlevel) (format "LEVEL>=%d" minlevel))
> +     ;; 	  (or (not maxlevel) (format "LEVEL<=%d" maxlevel)))

This can be removed.

Have you signed FSF papers? Otherwise, you need to insert TINCHANGE at
the end of the commit message.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-19 19:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-17 12:26 Add minlevel parameter to column view parameters Thomas Cordival
2017-10-19 19:33 ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).