From 2bc4854fb86a96b69e53db00603e0b2f8f47fe08 Mon Sep 17 00:00:00 2001 From: Jambunathan K Date: Thu, 23 Jun 2011 02:16:30 +0530 Subject: [PATCH 2/5] org-exp.el: Allow easy plugging in of new backends. * lisp/org-exp.el (org-export-backends): New variable. (org-export-select-backend-specific-text): Use above variable. Also mark text between #+BACKEND and #+BEGIN_BACKEND...#+END_BACKEND with org-native-text property. This text property is currently used only by the new line-oriented generic exporter (which is not yet part of the repo). --- lisp/org-exp.el | 41 +++++++++++++++++++++-------------------- 1 files changed, 21 insertions(+), 20 deletions(-) diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 3f4c468..96554a3 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -1661,52 +1661,53 @@ from the buffer." (add-text-properties beg (if (bolp) (1- (point)) (point)) '(org-protected t))))) +(defvar org-export-backends + '(docbook html beamer ascii latex) + "List of Org supported export backends.") + (defun org-export-select-backend-specific-text () - (let ((formatters - '((docbook "DOCBOOK" "BEGIN_DOCBOOK" "END_DOCBOOK") - (html "HTML" "BEGIN_HTML" "END_HTML") - (beamer "BEAMER" "BEGIN_BEAMER" "END_BEAMER") - (ascii "ASCII" "BEGIN_ASCII" "END_ASCII") - (latex "LaTeX" "BEGIN_LaTeX" "END_LaTeX"))) + (let ((formatters org-export-backends) (case-fold-search t) - fmt beg beg-content end end-content ind) + backend backend-name beg beg-content end end-content ind) (while formatters - (setq fmt (pop formatters)) - ;; Handle #+backend: stuff + (setq backend (pop formatters) + backend-name (symbol-name backend)) + + ;; Handle #+BACKEND: stuff (goto-char (point-min)) - (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" (cadr fmt) + (while (re-search-forward (concat "^\\([ \t]*\\)#\\+" backend-name ":[ \t]*\\(.*\\)") nil t) - (if (not (eq (car fmt) org-export-current-backend)) + (if (not (eq backend org-export-current-backend)) (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))) (replace-match "\\1\\2" t) (add-text-properties (point-at-bol) (min (1+ (point-at-eol)) (point-max)) - `(org-protected t original-indentation ,ind)))) - ;; Delete #+attr_Backend: stuff of another backend. Those + `(org-protected t original-indentation ,ind org-native-text t)))) + ;; Delete #+ATTR_BACKEND: stuff of another backend. Those ;; matching the current backend will be taken care of by ;; `org-export-attach-captions-and-attributes' (goto-char (point-min)) - (while (re-search-forward (concat "^\\([ \t]*\\)#\\+attr_" (cadr fmt) + (while (re-search-forward (concat "^\\([ \t]*\\)#\\+ATTR_" backend-name ":[ \t]*\\(.*\\)") nil t) (setq ind (org-get-indentation)) - (when (not (eq (car fmt) org-export-current-backend)) + (when (not (eq backend org-export-current-backend)) (delete-region (point-at-bol) (min (1+ (point-at-eol)) (point-max))))) - ;; Handle #+begin_backend and #+end_backend stuff + ;; Handle #+BEGIN_BACKEND and #+END_BACKEND stuff (goto-char (point-min)) - (while (re-search-forward (concat "^[ \t]*#\\+" (caddr fmt) "\\>.*\n?") + (while (re-search-forward (concat "^[ \t]*#\\+BEGIN_" backend-name "\\>.*\n?") nil t) (setq beg (match-beginning 0) beg-content (match-end 0)) (setq ind (save-excursion (goto-char beg) (org-get-indentation))) - (when (re-search-forward (concat "^[ \t]*#\\+" (cadddr fmt) "\\>.*\n?") + (when (re-search-forward (concat "^[ \t]*#\\+END_" backend-name "\\>.*\n?") nil t) (setq end (match-end 0) end-content (match-beginning 0)) - (if (eq (car fmt) org-export-current-backend) + (if (eq backend org-export-current-backend) ;; yes, keep this (progn (add-text-properties beg-content end-content - `(org-protected t original-indentation ,ind)) + `(org-protected t original-indentation ,ind org-native-text t)) (delete-region (match-beginning 0) (match-end 0)) (save-excursion (goto-char beg) -- 1.7.2.3