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: \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: \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.