From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jambunathan K Subject: [PATCH 2/5] org-exp.el: Allow easy plugging in of new backends Date: Thu, 23 Jun 2011 21:23:26 +0530 Message-ID: <811uyk8ryh.fsf@gmail.com> References: <81aad88s5j.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZmD6-0005h9-OQ for emacs-orgmode@gnu.org; Thu, 23 Jun 2011 11:52:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QZmD5-00039B-5Y for emacs-orgmode@gnu.org; Thu, 23 Jun 2011 11:52:52 -0400 Received: from mail-pz0-f51.google.com ([209.85.210.51]:62285) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QZmD4-000397-Mm for emacs-orgmode@gnu.org; Thu, 23 Jun 2011 11:52:51 -0400 Received: by pzk26 with SMTP id 26so1332512pzk.38 for ; Thu, 23 Jun 2011 08:52:49 -0700 (PDT) In-Reply-To: <81aad88s5j.fsf@gmail.com> (Jambunathan K.'s message of "Thu, 23 Jun 2011 21:19:12 +0530") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain PATCH-2/5: org-odt compatibility --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-org-exp.el-Allow-easy-plugging-in-of-new-backends.patch >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 --=-=-=--