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,46 +130,59 @@ 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
(remove-if-not (lambda (el) (eq :var (car el))) (third info))))) #'cdr
(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
(if (and body (string-match "\n$" body)) (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
"" "\n")))) (if (and body (string-match "\n$" body))
(when name (add-text-properties 0 (length str) "" "\n"))))
(list 'org-caption (when name
(format "%s(%s)" (add-text-properties
name (mapconcat #'identity args ", "))) 0 (length str)
str)) (list 'org-caption
str)) (format "%s(%s)"
name
(mapconcat #'identity args ", ")))
str))
str))
('lob ('lob
(let ((call-line (and (string-match "results=" (car args)) (let ((call-line (and (string-match "results=" (car 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
(if (and org-current-export-file (lambda (pair)
(eq (car pair) :var) (if (and org-current-export-file
(string-match org-babel-ref-split-regexp (cdr pair))) (eq (car pair) :var)
`(:var . ,(concat (match-string 1 (cdr pair)) (string-match org-babel-ref-split-regexp (cdr pair)))
"=" org-current-export-file `(:var . ,(concat (match-string 1 (cdr pair))
":" (match-string 2 (cdr pair)))) "=" org-current-export-file
pair)) ":" (match-string 2 (cdr pair))))
(third info)))) pair))
(third info))))
(case type (case type
('inline ('inline
(let ((raw (org-babel-execute-src-block (let ((raw (org-babel-execute-src-block
@ -189,10 +205,11 @@ options are taken from `org-babel-default-header-args'."
nil nil (org-babel-merge-params params '((:results . "replace")))) nil nil (org-babel-merge-params params '((:results . "replace"))))
"") "")
('lob ('lob
(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