From: Thomas Cordival <thomas@tuxella.me>
To: emacs-orgmode@gnu.org
Subject: Add minlevel parameter to column view parameters
Date: Tue, 17 Oct 2017 14:26:16 +0200 [thread overview]
Message-ID: <m2shei9d07.fsf@tuxella.me> (raw)
[-- 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
next reply other threads:[~2017-10-17 12:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-17 12:26 Thomas Cordival [this message]
2017-10-19 19:33 ` Add minlevel parameter to column view parameters Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2shei9d07.fsf@tuxella.me \
--to=thomas@tuxella.me \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.