emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* user control of source block header line exporting formats
@ 2010-07-31 20:54 David O'Toole
  2010-08-27 15:13 ` Eric Schulte
  0 siblings, 1 reply; 2+ messages in thread
From: David O'Toole @ 2010-07-31 20:54 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

I've attached a diff of my apparently-working changes to allow better
control of the way ob-exp.el formats the name and arguments of source
code blocks.

What do you think?

[-- Attachment #2: caption-formatting.diff --]
[-- Type: text/x-patch, Size: 3700 bytes --]

diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index 796812c..0c34431 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -206,42 +206,66 @@ The function respects the value of the :exports header argument."
 		     (org-babel-exp-results info type))))))
 
 (defvar backend)
+
+(defvar org-babel-format-code-functions
+  '(inline org-babel-format-code-inline
+    block org-babel-format-code-block
+    lob org-babel-format-code-lob))
+
+(defun org-babel-format-code-inline (lang body args switches name) 
+  (format "=%s=" body))
+
+(defvar org-babel-format-code-block-control-string "%s(%s)")
+
+(defun org-babel-format-code-block-default-style (info)
+  (destructuring-bind (lang body args0 switches name &rest ignore) info
+    (format org-babel-format-code-block-control-string
+	    name
+	    (mapconcat #'identity args ", "))))
+
+(defun org-babel-format-code-block-alternate-style (info)
+  (destructuring-bind (lang body args0 switches name &rest ignore) info
+    (format "SOURCE: %s ARGUMENTS: %s LANGUAGE: %s"
+	    name (if (null args) "None."
+		     (mapconcat #'identity args ", "))
+	    lang)))
+
+(defvar org-babel-format-code-block-caption-function
+  'org-babel-format-code-block-default-style) 
+
+(defun org-babel-format-code-block (lang body args switches name) 
+  (let ((str
+	 (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
+		 (if (and body (string-match "\n$" body))
+		     "" "\n"))))
+    (when name
+      (add-text-properties
+       0 (length str)
+       (list 'org-caption
+	     (funcall org-babel-format-code-block-caption-function 
+		      (list lang body args switches name)))
+       str))
+    str))
+
+(defun org-babel-format-code-lob (lang body args switches name) 
+  (let ((call-line (and (string-match "results=" (car args))
+			(substring (car args) (match-end 0)))))
+    (cond
+      ((eq backend 'html)
+       (format "\n#+HTML: <label class=\"org-src-name\">%s</label>\n"
+	       call-line))
+      ((format ": %s\n" call-line)))))
+
 (defun org-babel-exp-code (info type)
   "Prepare and return code in the current code block for export.
-Code is prepared in a manner suitable for exportat by
+Code is prepared in a manner suitable for export by
 org-mode.  This function is called by `org-babel-exp-do-export'.
 The code block is not evaluated."
-  (let ((lang (nth 0 info))
-        (body (nth 1 info))
-        (switches (nth 3 info))
-        (name (nth 4 info))
-        (args (mapcar
-	       #'cdr
-	       (org-remove-if-not (lambda (el) (eq :var (car el))) (nth 2 info)))))
-    (case type
-      ('inline (format "=%s=" body))
-      ('block
-	  (let ((str
-		 (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
-			 (if (and body (string-match "\n$" body))
-			     "" "\n"))))
-	    (when name
-	      (add-text-properties
-	       0 (length str)
-	       (list 'org-caption
-		     (format "%s(%s)"
-			     name
-			     (mapconcat #'identity args ", ")))
-	       str))
-	    str))
-      ('lob
-       (let ((call-line (and (string-match "results=" (car args))
-			     (substring (car args) (match-end 0)))))
-	 (cond
-	  ((eq backend 'html)
-	   (format "\n#+HTML: <label class=\"org-src-name\">%s</label>\n"
-		   call-line))
-	  ((format ": %s\n" call-line))))))))
+  (destructuring-bind (lang body args0 switches name &rest ignore) info
+    (let ((args (mapcar #'cdr
+			(org-remove-if-not (lambda (el) (eq :var (car el))) args0))))
+      (let ((formatter (getf org-babel-format-code-functions type)))
+	(funcall formatter lang body args switches name)))))
 
 (defun org-babel-exp-results (info type &optional silent)
   "Evaluate and return the results of the current code block for export.

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-08-27 15:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-31 20:54 user control of source block header line exporting formats David O'Toole
2010-08-27 15:13 ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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