summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-08-22 13:48:12 +0200
committerNicolas Goaziou <n.goaziou@gmail.com>2012-08-24 09:56:48 +0200
commitcc839259a4561210374f4c1c7ba7933e4455aae7 (patch)
tree1da39a531d021dd601e6ab05763a4febca3f7a7a
parent3f40057adc81999ac7aa994434b5ed1e5e67e4a9 (diff)
downloadorg-mode-cc839259a4561210374f4c1c7ba7933e4455aae7.tar.gz
org-export: Nil value from a filter means filter will be skipped
* contrib/lisp/org-export.el (org-export-filter-apply-functions): Nil value from a filter means filter will be skipped. To ignore the current element or object, the filter has to return the empty string instead. This change is done to ease filter writing. When writing a backend-specific filter (and I guess most are), there's no more need for the somewhat contrived: (if (not (eq backend 'e-latex)) data ... filter's job...) A more straightforward: (when (eq backend 'e-latex) ... filter's job...) is now enough. On the other hand, it is not possible anymore to specify 'ignore as a filter to ignore every element or object of a given type. To achieve that goal, one can now write, for example: (add-to-list 'org-export-filter-example-block-functions (lambda (value backend info) (when (eq backend 'e-html) ""))) It will ignore every example block in the `e-html' export back-end.
-rw-r--r--contrib/lisp/org-export.el24
1 files changed, 16 insertions, 8 deletions
diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el
index 67ec9ac..e4da913 100644
--- a/contrib/lisp/org-export.el
+++ b/contrib/lisp/org-export.el
@@ -2426,18 +2426,26 @@ channel, as a plist. It must return a string or nil.")
;; variables (user filters) in the communication channel.
;;
;; Internal function `org-export-filter-apply-functions' takes care
-;; about applying each filter in order to a given data. It stops
-;; whenever a filter returns a nil value.
+;; about applying each filter in order to a given data. It ignores
+;; filters returning a nil value but stops whenever a filter returns
+;; an empty string.
(defun org-export-filter-apply-functions (filters value info)
"Call every function in FILTERS.
+
Functions are called with arguments VALUE, current export
-back-end and INFO. Call is done in a LIFO fashion, to be sure
-that developer specified filters, if any, are called first."
- (loop for filter in filters
- if (not value) return nil else
- do (setq value (funcall filter value (plist-get info :back-end) info)))
- value)
+back-end and INFO. A function returning a nil value will be
+skipped. If it returns the empty string, the process ends and
+VALUE is ignored.
+
+Call is done in a LIFO fashion, to be sure that developer
+specified filters, if any, are called first."
+ (catch 'exit
+ (dolist (filter filters value)
+ (let ((result (funcall filter value (plist-get info :back-end) info)))
+ (cond ((not value))
+ ((equal value "") (throw 'exit nil))
+ (t (setq value result)))))))
(defun org-export-install-filters (info)
"Install filters properties in communication channel.