emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jambunathan K <kjambunathan@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH 3/5] Support custom formatters for marking up source or example blocks
Date: Thu, 23 Jun 2011 21:24:32 +0530	[thread overview]
Message-ID: <81wrgc7dc7.fsf@gmail.com> (raw)
In-Reply-To: <81aad88s5j.fsf@gmail.com> (Jambunathan K.'s message of "Thu, 23 Jun 2011 21:19:12 +0530")

[-- Attachment #1: Type: text/plain, Size: 40 bytes --]

PATCH-3/5 org-odt compatibility patch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0003-Support-custom-formatters-for-marking-up-source-or-e.patch --]
[-- Type: text/x-patch, Size: 2806 bytes --]

From a7881b8d146ddb27452b00ff19c345899d356536 Mon Sep 17 00:00:00 2001
From: Jambunathan K <kjambunathan@gmail.com>
Date: Thu, 23 Jun 2011 11:24:32 +0530
Subject: [PATCH 3/5] Support custom formatters for marking up source or example blocks.

* lisp/org-exp.el (org-export-format-source-code-or-example):
Add support for:
- custom formatters for existing backends
- seamless plugging in of new backends.
 lisp/org-exp.el |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/lisp/org-exp.el b/lisp/org-exp.el
index 96554a3..5008b65 100644
--- a/lisp/org-exp.el
+++ b/lisp/org-exp.el
@@ -2473,6 +2473,16 @@ in the list) and remove property and value from the list in LISTVAR."
 (defun org-export-format-source-code-or-example
   (lang code &optional opts indent caption)
   "Format CODE from language LANG and return it formatted for export.
+The CODE is marked up in `org-export-current-backend' format.
+Check if a function by name
+\"org-<backend>-format-source-code-or-example\" is bound. If yes,
+use it as the custom formatter. Otherwise, use the default
+formatter. Default formatters are provided for docbook, html,
+latex and ascii backends. For example, use
+`org-html-format-source-code-or-example' to provide a custom
+formatter for export to \"html\".
 If LANG is nil, do not add any fontification.
 OPTS contains formatting options, like `-n' for triggering numbering lines,
 and `+n' for continuing previous numbering.
@@ -2480,7 +2490,15 @@ Code formatting according to language currently only works for HTML.
 Numbering lines works for all three major backends (html, latex, and ascii).
 INDENT was the original indentation of the block."
-    (let (num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
+    (let* ((backend-name (symbol-name org-export-current-backend))
+	   (backend-formatter
+	    (intern (format "org-%s-format-source-code-or-example"
+			    backend-name)))
+	   (backend-feature (intern (concat "org-" backend-name)))
+	   (backend-formatter
+	    (and (require (intern (concat "org-" backend-name)) nil)
+		 (fboundp backend-formatter) backend-formatter))
+	   num cont rtn rpllbl keepp textareap preserve-indentp cols rows fmt)
       (setq opts (or opts "")
 	    num (string-match "[-+]n\\>" opts)
 	    cont (string-match "\\+n\\>" opts)
@@ -2517,6 +2535,9 @@ INDENT was the original indentation of the block."
       ;; Now backend-specific coding
       (setq rtn
+	     (backend-formatter
+	      (funcall backend-formatter lang caption textareap cols rows num
+		       cont rpllbl fmt))
 	     ((eq org-export-current-backend 'docbook)
 	      (setq rtn (org-export-number-lines rtn 0 0 num cont rpllbl fmt))
 	      (concat "\n#+BEGIN_DOCBOOK\n"

  parent reply	other threads:[~2011-06-23 15:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-23 15:49 org-odt compatibility patches Jambunathan K
2011-06-23 15:52 ` [PATCH 1/5] org-export: Reserve a slot for OpenDocumentExporter Jambunathan K
2011-06-23 15:53 ` [PATCH 2/5] org-exp.el: Allow easy plugging in of new backends Jambunathan K
2011-06-23 15:54 ` Jambunathan K [this message]
2011-06-23 15:56 ` [PATCH 4/5] Simplify org-export-format-source-code-or-example Jambunathan K
2011-06-23 15:57 ` [PATCH 5/5] Control insertion point for footnote definitions during pre-process Jambunathan K
2011-06-24  8:05 ` org-odt compatibility patches Carsten Dominik
2011-06-24  8:42   ` Jambunathan K
2011-06-24  8:55   ` Jambunathan K
2011-06-24 10:52     ` Bastien
2011-06-24 10:47   ` Bastien
2011-06-24 10:49 ` Bastien
2011-06-25  5:19   ` Jambunathan K
2011-06-25  8:54     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=81wrgc7dc7.fsf@gmail.com \
    --to=kjambunathan@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).