Merge branch 'master' of git+ssh://repo.or.cz/srv/git/org-mode

This commit is contained in:
Carsten Dominik 2009-11-05 07:20:09 +01:00
commit dd5b4d286e
3 changed files with 55 additions and 43 deletions

View File

@ -153,6 +153,7 @@ constructs (header arguments, no-web syntax etc...) are ignored."
(lhs-file (concat base-name ".lhs")) (lhs-file (concat base-name ".lhs"))
(tex-file (concat base-name ".tex")) (tex-file (concat base-name ".tex"))
(command (concat org-babel-haskell-lhs2tex-command " " lhs-file " > " tex-file)) (command (concat org-babel-haskell-lhs2tex-command " " lhs-file " > " tex-file))
(preserve-indentp org-src-preserve-indentation)
indentation) indentation)
;; escape haskell source-code blocks ;; escape haskell source-code blocks
(with-temp-file tmp-org-file (with-temp-file tmp-org-file
@ -160,9 +161,13 @@ constructs (header arguments, no-web syntax etc...) are ignored."
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward haskell-regexp nil t) (while (re-search-forward haskell-regexp nil t)
(save-match-data (setq indentation (length (match-string 1)))) (save-match-data (setq indentation (length (match-string 1))))
(replace-match (save-match-data (concat (replace-match (save-match-data
(concat
"#+begin_latex\n\\begin{code}\n" "#+begin_latex\n\\begin{code}\n"
(org-remove-indentation (match-string 3)) (if (or preserve-indentp
(string-match "-i" (match-string 2)))
(match-string 3)
(org-remove-indentation (match-string 3)))
"\n\\end{code}\n#+end_latex\n")) "\n\\end{code}\n#+end_latex\n"))
t t) t t)
(indent-code-rigidly (match-beginning 0) (match-end 0) indentation))) (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))

View File

@ -88,7 +88,8 @@ exported source code blocks by language."
(lang-specs (cdr (assoc lang org-babel-tangle-langs))) (lang-specs (cdr (assoc lang org-babel-tangle-langs)))
(ext (first lang-specs)) (ext (first lang-specs))
(she-bang (second lang-specs)) (she-bang (second lang-specs))
(commentable (not (third lang-specs)))) (commentable (not (third lang-specs)))
she-banged)
(mapc (mapc
(lambda (spec) (lambda (spec)
(let* ((tangle (cdr (assoc :tangle (third spec)))) (let* ((tangle (cdr (assoc :tangle (third spec))))
@ -113,7 +114,9 @@ exported source code blocks by language."
;; drop source-block to file ;; drop source-block to file
(with-temp-buffer (with-temp-buffer
(funcall lang-f) (funcall lang-f)
(when she-bang (insert (concat she-bang "\n"))) (when (and she-bang (not (member file-name she-banged)))
(insert (concat she-bang "\n"))
(setq she-banged (cons file-name she-banged)))
(when commentable (when commentable
(comment-region (comment-region
(point) (progn (insert "generated by org-babel-tangle") (point))) (point) (progn (insert "generated by org-babel-tangle") (point)))
@ -183,17 +186,17 @@ form
(link source-name params body)" (link source-name params body)"
(flet ((insert-comment (text) (flet ((insert-comment (text)
(when commentable (when commentable
(insert "\n")
(comment-region (point) (progn (insert text) (point))) (comment-region (point) (progn (insert text) (point)))
(move-end-of-line nil)))) (move-end-of-line nil)
(insert "\n"))))
(let ((link (first spec)) (let ((link (first spec))
(source-name (second spec)) (source-name (second spec))
(body (fourth spec)) (body (fourth spec))
(commentable (not (fifth spec)))) (commentable (not (fifth spec))))
(insert "\n\n")
(insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name)) (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
(insert (format "\n%s\n" (org-babel-chomp body))) (insert (format "%s" (org-babel-chomp body)))
(insert-comment (format "%s ends here" source-name)) (insert-comment (format "%s ends here" source-name)))))
(insert "\n"))))
(provide 'org-babel-tangle) (provide 'org-babel-tangle)
;;; org-babel-tangle.el ends here ;;; org-babel-tangle.el ends here

View File

@ -175,7 +175,7 @@ the header arguments specified at the source code block."
;; (message "supplied params=%S" params) ;; debugging ;; (message "supplied params=%S" params) ;; debugging
(let* ((info (or info (org-babel-get-src-block-info))) (let* ((info (or info (org-babel-get-src-block-info)))
(lang (first info)) (lang (first info))
(params (org-babel-merge-params (third info) params)) (params (setf (third info) (org-babel-merge-params (third info) params)))
(body (if (assoc :noweb params) (body (if (assoc :noweb params)
(org-babel-expand-noweb-references info) (second info))) (org-babel-expand-noweb-references info) (second info)))
(processed-params (org-babel-process-params params)) (processed-params (org-babel-process-params params))
@ -192,7 +192,7 @@ the header arguments specified at the source code block."
(funcall cmd body params))) (funcall cmd body params)))
(if (eq result-type 'value) (if (eq result-type 'value)
(setq result (org-babel-process-value-result result result-params))) (setq result (org-babel-process-value-result result result-params)))
(org-babel-insert-result result result-params) (org-babel-insert-result result result-params info)
result)) result))
(defun org-babel-load-in-session (&optional arg info) (defun org-babel-load-in-session (&optional arg info)
@ -473,7 +473,7 @@ buffer or nil if no such result exists."
(concat "#\\+resname:[ \t]*" (regexp-quote name) "[ \t\n\f\v\r]") nil t) (concat "#\\+resname:[ \t]*" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
(move-beginning-of-line 0) (point)))) (move-beginning-of-line 0) (point))))
(defun org-babel-where-is-src-block-result (&optional insert) (defun org-babel-where-is-src-block-result (&optional insert info)
"Return the point at the beginning of the result of the current "Return the point at the beginning of the result of the current
source block. Specifically at the beginning of the #+RESNAME: source block. Specifically at the beginning of the #+RESNAME:
line. If no result exists for this block then create a line. If no result exists for this block then create a
@ -482,7 +482,7 @@ line. If no result exists for this block then create a
(let* ((on-lob-line (progn (beginning-of-line 1) (let* ((on-lob-line (progn (beginning-of-line 1)
(looking-at org-babel-lob-one-liner-regexp))) (looking-at org-babel-lob-one-liner-regexp)))
(name (if on-lob-line (first (org-babel-lob-get-info)) (name (if on-lob-line (first (org-babel-lob-get-info))
(fifth (org-babel-get-src-block-info)))) (fifth (or info (org-babel-get-src-block-info)))))
(head (unless on-lob-line (org-babel-where-is-src-block-head))) end) (head (unless on-lob-line (org-babel-where-is-src-block-head))) end)
(when head (goto-char head)) (when head (goto-char head))
(or (and name (org-babel-find-named-result name)) (or (and name (org-babel-find-named-result name))
@ -528,7 +528,7 @@ line. If no result exists for this block then create a
(mapcar #'org-babel-read row))) (mapcar #'org-babel-read row)))
(org-table-to-lisp))) (org-table-to-lisp)))
(defun org-babel-insert-result (result &optional insert) (defun org-babel-insert-result (result &optional insert info)
"Insert RESULT into the current buffer after the end of the "Insert RESULT into the current buffer after the end of the
current source block. With optional argument INSERT controls current source block. With optional argument INSERT controls
insertion of results in the org-mode file. INSERT can take the insertion of results in the org-mode file. INSERT can take the
@ -566,7 +566,7 @@ code ---- the results are extracted in the syntax of the source
(if (member "file" insert) (setq result (org-babel-result-to-file result)))) (if (member "file" insert) (setq result (org-babel-result-to-file result))))
(unless (listp result) (setq result (format "%S" result)))) (unless (listp result) (setq result (format "%S" result))))
(if (and insert (member "replace" insert) (not (member "silent" insert))) (if (and insert (member "replace" insert) (not (member "silent" insert)))
(org-babel-remove-result)) (org-babel-remove-result info))
(if (= (length result) 0) (if (= (length result) 0)
(if (member "value" result-params) (if (member "value" result-params)
(message "No result returned by source block") (message "No result returned by source block")
@ -578,8 +578,10 @@ code ---- the results are extracted in the syntax of the source
(string-equal (substring result -1) "\r")))) (string-equal (substring result -1) "\r"))))
(setq result (concat result "\n"))) (setq result (concat result "\n")))
(save-excursion (save-excursion
(let ((existing-result (org-babel-where-is-src-block-result t))) (let ((existing-result (org-babel-where-is-src-block-result t info))
(when existing-result (goto-char existing-result) (forward-line 1))) (results-switches (cdr (assoc :results_switches (third info)))))
(when existing-result (goto-char existing-result) (forward-line 1))
(setq results-switches (if results-switches (concat " " results-switches) ""))
(cond (cond
;; assume the result is a table if it's not a string ;; assume the result is a table if it's not a string
((not (stringp result)) ((not (stringp result))
@ -591,15 +593,15 @@ code ---- the results are extracted in the syntax of the source
((member "file" insert) ((member "file" insert)
(insert result)) (insert result))
((member "html" insert) ((member "html" insert)
(insert (format "#+BEGIN_HTML\n%s#+END_HTML\n" result))) (insert (format "#+BEGIN_HTML%s\n%s#+END_HTML\n" results-switches result)))
((member "latex" insert) ((member "latex" insert)
(insert (format "#+BEGIN_LaTeX\n%s#+END_LaTeX\n" result))) (insert (format "#+BEGIN_LaTeX%s\n%s#+END_LaTeX\n" results-switches result)))
((member "code" insert) ((member "code" insert)
(insert (format "#+BEGIN_SRC %s\n%s#+END_SRC\n" lang result))) (insert (format "#+BEGIN_SRC %s%s\n%s#+END_SRC\n" lang results-switches result)))
((or (member "raw" insert) (member "org" insert)) ((or (member "raw" insert) (member "org" insert))
(save-excursion (insert result)) (if (org-at-table-p) (org-cycle))) (save-excursion (insert result)) (if (org-at-table-p) (org-cycle)))
(t (t
(org-babel-examplize-region (point) (progn (insert result) (point)))))) (org-babel-examplize-region (point) (progn (insert result) (point)) results-switches)))))
(message "finished")))) (message "finished"))))
(defun org-babel-result-to-org-string (result) (defun org-babel-result-to-org-string (result)
@ -607,11 +609,11 @@ code ---- the results are extracted in the syntax of the source
relies on `org-babel-insert-result'." relies on `org-babel-insert-result'."
(with-temp-buffer (org-babel-insert-result result) (buffer-string))) (with-temp-buffer (org-babel-insert-result result) (buffer-string)))
(defun org-babel-remove-result () (defun org-babel-remove-result (&optional info)
"Remove the result of the current source block." "Remove the result of the current source block."
(interactive) (interactive)
(save-excursion (save-excursion
(goto-char (org-babel-where-is-src-block-result t)) (forward-line 1) (goto-char (org-babel-where-is-src-block-result t info)) (forward-line 1)
(delete-region (point) (org-babel-result-end)))) (delete-region (point) (org-babel-result-end))))
(defun org-babel-result-end () (defun org-babel-result-end ()
@ -643,7 +645,7 @@ RESULT, and the display being the `file-name-nondirectory' if
non-nil." non-nil."
(concat "[[file:" result "]]")) (concat "[[file:" result "]]"))
(defun org-babel-examplize-region (beg end) (defun org-babel-examplize-region (beg end &optional results-switches)
"Comment out region using the ': ' org example quote." "Comment out region using the ': ' org example quote."
(interactive "*r") (interactive "*r")
(let ((size (abs (- (line-number-at-pos end) (let ((size (abs (- (line-number-at-pos end)
@ -660,7 +662,9 @@ non-nil."
(move-beginning-of-line 1) (insert ": ") (forward-line 1))) (move-beginning-of-line 1) (insert ": ") (forward-line 1)))
(t (t
(goto-char beg) (goto-char beg)
(insert "#+begin_example\n") (insert (if results-switches
(format "#+begin_example%s\n" results-switches)
"#+begin_example\n"))
(forward-char (- end beg)) (forward-char (- end beg))
(insert "#+end_example\n")))))) (insert "#+end_example\n"))))))