babel-exp: minor documentation and indentation changes

This commit is contained in:
Eric Schulte 2010-06-01 16:40:06 -06:00
parent bc53b3da3b
commit b7e273f25d
1 changed files with 44 additions and 27 deletions

View File

@ -112,12 +112,15 @@ options are taken from `org-babel-default-header-args'."
(org-babel-parse-header-arguments (org-babel-parse-header-arguments
(org-babel-clean-text-properties (org-babel-clean-text-properties
(concat ":var results=" (concat ":var results="
(mapconcat #'identity (org-babel-lob-get-info) " ")))))) (mapconcat #'identity
(org-babel-lob-get-info) " "))))))
'lob))) 'lob)))
(setq end (+ end (- (length replacement) (length (match-string 0))))) (setq end (+ end (- (length replacement) (length (match-string 0)))))
(replace-match replacement t t))))) (replace-match replacement t t)))))
(defun org-babel-exp-do-export (info type) (defun org-babel-exp-do-export (info type)
"Return a string containing the exported content of the current
code block respecting the value of the :exports header argument."
(case (intern (or (cdr (assoc :exports (third info))) "code")) (case (intern (or (cdr (assoc :exports (third info))) "code"))
('none "") ('none "")
('code (org-babel-exp-code info type)) ('code (org-babel-exp-code info type))
@ -127,22 +130,30 @@ options are taken from `org-babel-default-header-args'."
(org-babel-exp-results info type))))) (org-babel-exp-results info type)))))
(defun org-babel-exp-code (info type) (defun org-babel-exp-code (info type)
"Return the code the current code block in a manner suitable
for exportation by org-mode. This function is called by
`org-babel-exp-do-export'."
(let ((lang (first info)) (let ((lang (first info))
(body (second info)) (body (second info))
(switches (fourth info)) (switches (fourth info))
(name (fifth info)) (name (fifth info))
(args (mapcar #'cdr (args (mapcar
#'cdr
(remove-if-not (lambda (el) (eq :var (car el))) (third info))))) (remove-if-not (lambda (el) (eq :var (car el))) (third info)))))
(case type (case type
('inline (format "=%s=" body)) ('inline (format "=%s=" body))
('block ('block
(let ((str (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body (let ((str
(format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
(if (and body (string-match "\n$" body)) (if (and body (string-match "\n$" body))
"" "\n")))) "" "\n"))))
(when name (add-text-properties 0 (length str) (when name
(add-text-properties
0 (length str)
(list 'org-caption (list 'org-caption
(format "%s(%s)" (format "%s(%s)"
name (mapconcat #'identity args ", "))) name
(mapconcat #'identity args ", ")))
str)) str))
str)) str))
('lob ('lob
@ -150,15 +161,20 @@ options are taken from `org-babel-default-header-args'."
(substring (car args) (match-end 0))))) (substring (car args) (match-end 0)))))
(cond (cond
((eq backend 'html) ((eq backend 'html)
(format "\n#+HTML: <label class=\"org-src-name\">%s</label>\n" call-line)) (format "\n#+HTML: <label class=\"org-src-name\">%s</label>\n"
call-line))
((t (format ": %s\n" call-line))))))))) ((t (format ": %s\n" call-line)))))))))
(defun org-babel-exp-results (info type) (defun org-babel-exp-results (info type)
"Return the results of the current code block in a manner
suitable for exportation by org-mode. This function is called by
`org-babel-exp-do-export'."
(let ((lang (first info)) (let ((lang (first info))
(body (second info)) (body (second info))
(params (params
;; lets ensure that we lookup references in the original file ;; lets ensure that we lookup references in the original file
(mapcar (lambda (pair) (mapcar
(lambda (pair)
(if (and org-current-export-file (if (and org-current-export-file
(eq (car pair) :var) (eq (car pair) :var)
(string-match org-babel-ref-split-regexp (cdr pair))) (string-match org-babel-ref-split-regexp (cdr pair)))
@ -192,7 +208,8 @@ options are taken from `org-babel-default-header-args'."
(save-excursion (save-excursion
(re-search-backward org-babel-lob-one-liner-regexp nil t) (re-search-backward org-babel-lob-one-liner-regexp nil t)
(org-babel-execute-src-block (org-babel-execute-src-block
nil (list lang body (org-babel-merge-params params '((:results . "replace"))))) ""))))) nil (list lang body (org-babel-merge-params
params '((:results . "replace"))))) "")))))
(provide 'org-babel-exp) (provide 'org-babel-exp)
;;; org-babel-exp.el ends here ;;; org-babel-exp.el ends here