From 25f76ffa4413cedfd66e5f0d32908d827f9d28be Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 10 Feb 2010 13:34:00 -0700 Subject: [PATCH] babel: now including source code block arguments w/source name on export This change provides for better export of named source-code blocks, with specific support for more attractive html export. The arguments are included with the source code name, and both the source code name and code body are wrapped in a div to support styling with css. For example the following CSS can be used to associate a source-code block name with it's code body, and to slightly indent the body. .org-src-container { border-left: 4px solid gray; padding: 0.5em 0.5em 0.5em 1em; } .org-src-container pre { margin-left: 1em; } --- contrib/babel/lisp/org-babel-exp.el | 32 +++++++++++++++++------------ contrib/babel/lisp/org-babel-lob.el | 4 ---- lisp/org-exp.el | 12 +++++++---- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/contrib/babel/lisp/org-babel-exp.el b/contrib/babel/lisp/org-babel-exp.el index b299d5720..639db35d3 100644 --- a/contrib/babel/lisp/org-babel-exp.el +++ b/contrib/babel/lisp/org-babel-exp.el @@ -128,22 +128,28 @@ options are taken from `org-babel-default-header-args'." (defun org-babel-exp-code (info type) (let ((lang (first info)) - (body (second info)) - (switches (fourth info)) - (name (fifth info)) - (args (sixth info)) - (function-def-line "")) + (body (second info)) + (switches (fourth info)) + (name (fifth info)) + (args (mapcar #'cdr + (remove-if-not (lambda (el) (eq :var (car el))) (third info))))) (case type - ('inline (format "=%s=" (second info))) + ('inline (format "=%s=" body)) ('block (let ((str (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body - (if (string-match "\n$" body) "" "\n")))) - (add-text-properties 0 (length str) (list 'org-caption name) str) - str)) - ('lob (save-excursion - (re-search-backward org-babel-lob-one-liner-regexp) - (format "#+BEGIN_SRC org-babel-lob\n%s\n#+END_SRC" - (first (org-babel-lob-get-info)))))))) + (if (string-match "\n$" body) "" "\n")))) + (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)) + ((t (format ": %s\n" call-line))))))))) (defun org-babel-exp-results (info type) (let ((lang (first info)) diff --git a/contrib/babel/lisp/org-babel-lob.el b/contrib/babel/lisp/org-babel-lob.el index d1a1b17d3..d289a4424 100644 --- a/contrib/babel/lisp/org-babel-lob.el +++ b/contrib/babel/lisp/org-babel-lob.el @@ -104,9 +104,5 @@ the word 'call'." (concat ":var results=" (mapconcat #'identity info " "))))))) (org-babel-execute-src-block nil (list "emacs-lisp" "results" params)))) -(define-generic-mode org-babel-lob-mode - '("#") (list org-babel-function-def-export-keyword) nil nil nil - "Major mode for fontification of library of babel lines on export") - (provide 'org-babel-lob) ;;; org-babel-lob.el ends here diff --git a/lisp/org-exp.el b/lisp/org-exp.el index 3712f4234..4210e3278 100644 --- a/lisp/org-exp.el +++ b/lisp/org-exp.el @@ -2456,12 +2456,16 @@ INDENT was the original indentation of the block." (setq rtn (concat (if caption - (format "" - caption) + (concat + "
" + (format + "" + caption)) "") (replace-match - (format "
\n" lang)
-                                t t rtn)))))
+                                (format "
\n" lang)
+                                t t rtn)
+                               (if caption "
" ""))))) (if textareap (setq rtn (concat (format "

\n