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.
This commit is contained in:
Nicolas Goaziou 2012-08-22 13:48:12 +02:00
parent 3f40057adc
commit cc839259a4
1 changed files with 16 additions and 8 deletions

View File

@ -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.