Browse Source

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; }
Eric Schulte 15 years ago
parent
commit
25f76ffa44
3 changed files with 27 additions and 21 deletions
  1. 19 13
      contrib/babel/lisp/org-babel-exp.el
  2. 0 4
      contrib/babel/lisp/org-babel-lob.el
  3. 8 4
      lisp/org-exp.el

+ 19 - 13
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: <label class=\"org-src-name\">%s</label>\n" call-line))
+          ((t (format ": %s\n" call-line)))))))))
 
 (defun org-babel-exp-results (info type)
   (let ((lang (first info))

+ 0 - 4
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

+ 8 - 4
lisp/org-exp.el

@@ -2456,12 +2456,16 @@ INDENT was the original indentation of the block."
 			(setq rtn
                               (concat
                                (if caption
-                                   (format "<label class=\"org-src-name\">%s  &equiv</label>"
-                                           caption)
+                                   (concat
+                                    "<div class=\"org-src-container\">"
+                                    (format
+                                     "<label class=\"org-src-name\">%s</label>"
+                                     caption))
                                  "")
                                (replace-match
-				   (format "<pre class=\"src src-%s\">\n" lang)
-                                t t rtn)))))
+                                (format "<pre class=\"src src-%s\">\n" lang)
+                                t t rtn)
+                               (if caption "</div>" "")))))
 		(if textareap
 		    (setq rtn (concat
 			       (format "<p>\n<textarea cols=\"%d\" rows=\"%d\" overflow-x:scroll >\n"