summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-10-30 01:00:49 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-12-19 12:14:48 +0100
commit835b8e05e512bee7370b8d3aee749c222636335c (patch)
tree65660473d347af734275117aab3ca9a5babca269
parent9ea8e46df08efb3ac118854c238ac51794caf8d5 (diff)
downloadorg-mode-835b8e05e512bee7370b8d3aee749c222636335c.tar.gz
org-list: Tweak `org-list-to-generic'
* lisp/org-list.el (org-list-to-generic): :istart, :icount, :iend and :isep are now called with an additional argument, the type of the list. Also add a new property :ifmt. (org-list--to-generic-item): Use new property. (org-list-to-subtree): Adapt to new requirements for :istart and :iend. * testing/lisp/test-org-list.el (test-org-list/to-generic): Update tests.
-rw-r--r--etc/ORG-NEWS12
-rw-r--r--lisp/org-list.el40
-rw-r--r--testing/lisp/test-org-list.el19
3 files changed, 51 insertions, 20 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index ec8a0c2..1d83983 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -12,6 +12,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
** Incompatible changes
+*** Change signature for some properties in ~org-list-to-generic~
+
+~:istart~, ~:icount~, ~:iend~ and ~:isep~ now expect the type of the
+list as their first argument.
+
*** ~org-capture-templates~ no longer accepts S-expressions as file names
Since functions are allowed there, a straightforward way to migrate
@@ -27,7 +32,9 @@ into
*** Agenda
**** New variable : ~org-agenda-show-future-repeats~
**** New variable : ~org-agenda-prefer-last-repeat~
+
*** Babel
+
**** Clojure: new setting ~org-babel-clojure-sync-nrepl-timeout~
Creation of a new setting to specify the Cider timeout. By setting
@@ -93,6 +100,11 @@ as descriptions of links, a.k.a. image links. See its docstring for
details.
**** Horizontal rules are no longer ignored in LaTeX table math mode
+*** ~org-list-to-generic~ includes a new property: ~:ifmt~
+
+~:ifmt~ is a function to be called on the body of each item. See
+~org-list-to-generic~ documentation for details.
+
*** New variable : ~org-bibtex-headline-format-function~
This allow to use a different title than entry title.
diff --git a/lisp/org-list.el b/lisp/org-list.el
index 325a248..abc6c53 100644
--- a/lisp/org-list.el
+++ b/lisp/org-list.el
@@ -3314,23 +3314,28 @@ Valid parameters are:
Strings to start or end a list item, and to start a list item
with a counter. They can also be set to a function returning
- a string or nil, which will be called with the depth of the
- item, counting from 1.
+ a string or nil, which will be called with two arguments: the
+ type of list and the depth of the item, counting from 1.
:icount
Strings to start a list item with a counter. It can also be
set to a function returning a string or nil, which will be
- called with two arguments: the depth of the item, counting from
- 1, and the counter. Its value, when non-nil, has precedence
- over `:istart'.
+ called with three arguments: the type of list, the depth of the
+ item, counting from 1, and the counter. Its value, when
+ non-nil, has precedence over `:istart'.
:isep
String used to separate items. It can also be set to
a function returning a string or nil, which will be called with
- the depth of the items, counting from 1. It always start on
- a new line.
+ two arguments: the type of list and the depth of the item,
+ counting from 1. It always start on a new line.
+
+:ifmt
+
+ Function to be applied to the contents of every item. It is
+ called with two arguments: the type of list and the contents.
:cbon, :cboff, :cbtrans
@@ -3461,6 +3466,7 @@ PARAMS is a plist used to tweak the behavior of the transcoder."
(iend (plist-get params :iend))
(isep (plist-get params :isep))
(icount (plist-get params :icount))
+ (ifmt (plist-get params :ifmt))
(cboff (plist-get params :cboff))
(cbon (plist-get params :cbon))
(cbtrans (plist-get params :cbtrans))
@@ -3474,9 +3480,9 @@ PARAMS is a plist used to tweak the behavior of the transcoder."
(tag (org-element-property :tag item))
(depth (org-list--depth item))
(separator (and (org-export-get-next-element item info)
- (org-list--generic-eval isep depth)))
- (closing (pcase (org-list--generic-eval iend depth)
- ((or `nil `"") "\n")
+ (org-list--generic-eval isep type depth)))
+ (closing (pcase (org-list--generic-eval iend type depth)
+ ((or `nil "") "\n")
((and (guard separator) s)
(if (equal (substring s -1) "\n") s (concat s "\n")))
(s s))))
@@ -3493,10 +3499,10 @@ PARAMS is a plist used to tweak the behavior of the transcoder."
;; Build output.
(concat
(let ((c (org-element-property :counter item)))
- (if c (org-list--generic-eval icount depth c)
- (org-list--generic-eval istart depth)))
+ (if (and c icount) (org-list--generic-eval icount type depth c)
+ (org-list--generic-eval istart type depth)))
(let ((body
- (if (or istart iend icount cbon cboff cbtrans (not backend)
+ (if (or istart iend icount ifmt cbon cboff cbtrans (not backend)
(and (eq type 'descriptive)
(or dtstart dtend ddstart ddend)))
(concat
@@ -3512,7 +3518,11 @@ PARAMS is a plist used to tweak the behavior of the transcoder."
(org-element-interpret-data tag))
dtend))
(and tag ddstart)
- (if (= (length contents) 0) "" (substring contents 0 -1))
+ (let ((contents
+ (if (= (length contents) 0) ""
+ (substring contents 0 -1))))
+ (if ifmt (org-list--generic-eval ifmt type contents)
+ contents))
(and tag ddend))
(org-export-with-backend backend item contents info))))
;; Remove final newline.
@@ -3556,7 +3566,7 @@ list with overruling parameters for `org-list-to-generic'."
(org-previous-line-empty-p)))))
(level (org-reduced-level (or (org-current-level) 0)))
(make-stars
- (lambda (depth)
+ (lambda (_type depth &optional _count)
;; Return the string for the heading, depending on DEPTH
;; of current sub-list.
(let ((oddeven-level (+ level depth)))
diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el
index 1ddbaa5..fe9da96 100644
--- a/testing/lisp/test-org-list.el
+++ b/testing/lisp/test-org-list.el
@@ -1157,13 +1157,13 @@
"level1 a\nlevel2 b"
(org-test-with-temp-text "- a\n - b"
(org-list-to-generic (org-list-to-lisp)
- '(:istart (lambda (l) (format "level%d "l)))))))
+ '(:istart (lambda (type l) (format "level%d "l)))))))
(should
(equal
"a\nblevel2level1"
(org-test-with-temp-text "- a\n - b"
(org-list-to-generic (org-list-to-lisp)
- '(:iend (lambda (l) (format "level%d" l)))))))
+ '(:iend (lambda (type l) (format "level%d" l)))))))
;; Test `:icount' parameter.
(should
(equal
@@ -1187,7 +1187,7 @@
(org-test-with-temp-text "1. [@3] a"
(org-list-to-generic
(org-list-to-lisp)
- '(:icount (lambda (l c) (format "level:%d, counter:%d " l c)))))))
+ '(:icount (lambda (type l c) (format "level:%d, counter:%d " l c)))))))
;; Test `:isep' parameter.
(should
(equal
@@ -1203,8 +1203,17 @@
(equal
"a\n- 1 -\nb"
(org-test-with-temp-text "- a\n- b"
- (org-list-to-generic (org-list-to-lisp)
- '(:isep (lambda (l) (format "- %d -" l)))))))
+ (org-list-to-generic
+ (org-list-to-lisp)
+ '(:isep (lambda (type depth) (format "- %d -" depth)))))))
+ ;; Test `:ifmt' parameter.
+ (should
+ (equal
+ ">> a <<"
+ (org-test-with-temp-text "1. [@3] a"
+ (org-list-to-generic
+ (org-list-to-lisp)
+ '(:ifmt (lambda (type c) (format ">> %s <<" c)))))))
;; Test `:cbon', `:cboff', `:cbtrans'
(should
(equal