From cc839259a4561210374f4c1c7ba7933e4455aae7 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 22 Aug 2012 13:48:12 +0200 Subject: [PATCH] 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. --- contrib/lisp/org-export.el | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/contrib/lisp/org-export.el b/contrib/lisp/org-export.el index 67ec9acba..e4da9138a 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.