org-export: Make backend registration more stable wrt Org reload

* contrib/lisp/org-export.el (org-export-define-backend,
  org-export-define-derived-backend): Modify backend properties if
  backend is already registered.
(org-export-registered-backends): Use defvar instead of defconst so
a reload doesn't reset it.
This commit is contained in:
Nicolas Goaziou 2012-11-14 14:41:27 +01:00
parent 3d56f56399
commit 72a27c3b3f
1 changed files with 21 additions and 22 deletions

View File

@ -251,7 +251,7 @@ whose extension is either \"png\", \"jpeg\", \"jpg\", \"gif\",
See `org-export-inline-image-p' for more information about See `org-export-inline-image-p' for more information about
rules.") rules.")
(defconst org-export-registered-backends nil (defvar org-export-registered-backends nil
"List of backends currently available in the exporter. "List of backends currently available in the exporter.
A backend is stored as a list where CAR is its name, as a symbol, A backend is stored as a list where CAR is its name, as a symbol,
@ -840,7 +840,7 @@ keywords are understood:
structure of the values." structure of the values."
(declare (debug (&define name sexp [&rest [keywordp sexp]] defbody)) (declare (debug (&define name sexp [&rest [keywordp sexp]] defbody))
(indent 1)) (indent 1))
(let (export-block filters menu-entry options) (let (export-block filters menu-entry options contents)
(while (keywordp (car body)) (while (keywordp (car body))
(case (pop body) (case (pop body)
(:export-block (let ((names (pop body))) (:export-block (let ((names (pop body)))
@ -851,15 +851,15 @@ keywords are understood:
(:menu-entry (setq menu-entry (pop body))) (:menu-entry (setq menu-entry (pop body)))
(:options-alist (setq options (pop body))) (:options-alist (setq options (pop body)))
(t (pop body)))) (t (pop body))))
(setq contents (append (list :translate-alist translators)
(and filters (list :filters-alist filters))
(and options (list :options-alist options))
(and menu-entry (list :menu-entry menu-entry))))
`(progn `(progn
;; Register back-end. ;; Register back-end.
(add-to-list (let ((registeredp (assq ',backend org-export-registered-backends)))
'org-export-registered-backends (if registeredp (setcdr registeredp ',contents)
',(cons backend (push (cons ',backend ',contents) org-export-registered-backends)))
(append (list :translate-alist translators)
(and filters (list :filters-alist filters))
(and options (list :options-alist options))
(and menu-entry (list :menu-entry menu-entry)))))
;; Tell parser to not parse EXPORT-BLOCK blocks. ;; Tell parser to not parse EXPORT-BLOCK blocks.
,(when export-block ,(when export-block
`(mapc `(mapc
@ -925,7 +925,7 @@ The back-end could then be called with, for example:
\(org-export-to-buffer 'my-latex \"*Test my-latex*\")" \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
(declare (debug (&define name sexp [&rest [keywordp sexp]] def-body)) (declare (debug (&define name sexp [&rest [keywordp sexp]] def-body))
(indent 2)) (indent 2))
(let (export-block filters menu-entry options sub-menu-entry translators) (let (export-block filters menu-entry options translators contents)
(while (keywordp (car body)) (while (keywordp (car body))
(case (pop body) (case (pop body)
(:export-block (let ((names (pop body))) (:export-block (let ((names (pop body)))
@ -935,22 +935,21 @@ The back-end could then be called with, for example:
(:filters-alist (setq filters (pop body))) (:filters-alist (setq filters (pop body)))
(:menu-entry (setq menu-entry (pop body))) (:menu-entry (setq menu-entry (pop body)))
(:options-alist (setq options (pop body))) (:options-alist (setq options (pop body)))
(:sub-menu-entry (setq sub-menu-entry (pop body)))
(:translate-alist (setq translators (pop body))) (:translate-alist (setq translators (pop body)))
(t (pop body)))) (t (pop body))))
(setq contents (append
(let ((p-table (org-export-backend-translate-table parent)))
(list :translate-alist (append translators p-table)))
(let ((p-filters (org-export-backend-filters parent)))
(list :filters-alist (append filters p-filters)))
(let ((p-options (org-export-backend-options parent)))
(list :options-alist (append options p-options)))
(and menu-entry (list :menu-entry menu-entry))))
`(progn `(progn
;; Register back-end. ;; Register back-end.
(add-to-list (let ((registeredp (assq ',child org-export-registered-backends)))
'org-export-registered-backends (if registeredp (setcdr registeredp ',contents)
',(cons child (push (cons ',child ',contents) org-export-registered-backends)))
(append
(let ((p-table (org-export-backend-translate-table parent)))
(list :translate-alist (append translators p-table)))
(let ((p-filters (org-export-backend-filters parent)))
(list :filters-alist (append filters p-filters)))
(let ((p-options (org-export-backend-options parent)))
(list :options-alist (append options p-options)))
(and menu-entry (list :menu-entry menu-entry)))))
;; Tell parser to not parse EXPORT-BLOCK blocks. ;; Tell parser to not parse EXPORT-BLOCK blocks.
,(when export-block ,(when export-block
`(mapc `(mapc