From: "David O'Toole" <dto1138@gmail.com>
To: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>
Subject: user control of source block header line exporting formats
Date: Sat, 31 Jul 2010 16:54:57 -0400 [thread overview]
Message-ID: <AANLkTi=mW7fnYcS8MRzqkh2-y7N4B2JNAbEYNscb5ipr@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2010-07-31 20:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-31 20:54 David O'Toole [this message]
2010-08-27 15:13 ` user control of source block header line exporting formats Eric Schulte
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:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='AANLkTi=mW7fnYcS8MRzqkh2-y7N4B2JNAbEYNscb5ipr@mail.gmail.com' \
--to=dto1138@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* 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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.