diff options
author | Carsten Dominik <carsten.dominik@gmail.com> | 2011-06-14 14:56:07 +0200 |
---|---|---|
committer | Carsten Dominik <carsten.dominik@gmail.com> | 2011-06-14 14:56:07 +0200 |
commit | 9108d3f0ee1db9cb2f547046d23a9fb12d681fc0 (patch) | |
tree | a48a536bcb517906ce97c039f6d846a0599b7f1c | |
parent | 1891ee5aafee710315a26595385e670e1ac3771e (diff) | |
parent | 90f6765cdf77c1414726d899f00c77da43f45758 (diff) | |
download | org-mode-9108d3f0ee1db9cb2f547046d23a9fb12d681fc0.tar.gz |
Merge branch 'master' of orgmode.org:org-mode
-rw-r--r-- | doc/org.texi | 21 | ||||
-rw-r--r-- | lisp/ob-exp.el | 22 | ||||
-rw-r--r-- | lisp/ob-ruby.el | 11 | ||||
-rw-r--r-- | lisp/ob-tangle.el | 45 | ||||
-rw-r--r-- | lisp/org-exp-blocks.el | 69 | ||||
-rw-r--r-- | lisp/org-latex.el | 8 | ||||
-rw-r--r-- | lisp/org-list.el | 5 |
7 files changed, 125 insertions, 56 deletions
diff --git a/doc/org.texi b/doc/org.texi index 92343de..0fd0d22 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -11414,7 +11414,9 @@ This name is associated with the code block. This is similar to the @samp{#+tblname} lines that can be used to name tables in Org-mode files. Referencing the name of a code block makes it possible to evaluate the block from other places in the file, other files, or from Org-mode table -formulas (see @ref{The spreadsheet}). +formulas (see @ref{The spreadsheet}). Names are assumed to be unique by +evaluation functions and the behavior of multiple blocks of the same name is +undefined. @item <language> The language of the code in the block. @item <switches> @@ -11544,6 +11546,23 @@ Tangle the current file. Bound to @kbd{C-c C-v t}. Choose a file to tangle. Bound to @kbd{C-c C-v f}. @end table +@subsubheading Variables +@table @code +@item org-babel-tangle-named-block-combination +This variable controls the tangling of multiple code blocks with the same +name. +@table @code +@item nil +The default behavior. Blocks with the same name are tangled as normal. +@item append +The bodies of all blocks of the same name are appended during tangling. +@item first +Only the body of the first block of any given name is kept during tangling. +@item last +Only the body of the last block of any given name is kept during tangling. +@end table +@end table + @subsubheading Hooks @table @code @item org-babel-post-tangle-hook diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 09e85ca..ca0af4e 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -54,28 +54,6 @@ process." :type 'boolean) (put 'org-export-babel-evaluate 'safe-local-variable (lambda (x) (eq x nil))) -(defvar org-babel-function-def-export-keyword "function" - "The keyword to substitute for the source name line on export. -When exporting a source block function, this keyword will -appear in the exported version in the place of source name -line. A source block is considered to be a source block function -if the source name is present and is followed by a parenthesized -argument list. The parentheses may be empty or contain -whitespace. An example is the following which generates n random -\(uniform) numbers. - -#+source: rand(n) -#+begin_src R - runif(n) -#+end_src") - -(defvar org-babel-function-def-export-indent 4 - "Number of characters to indent a source block on export. -When exporting a source block function, the block contents will -be indented by this many characters. See -`org-babel-function-def-export-name' for the definition of a -source block function.") - (defmacro org-babel-exp-in-export-file (lang &rest body) (declare (indent 1)) `(let* ((lang-headers (intern (concat "org-babel-default-header-args:" ,lang))) diff --git a/lisp/ob-ruby.el b/lisp/ob-ruby.el index 41245e2..da53912 100644 --- a/lisp/ob-ruby.el +++ b/lisp/ob-ruby.el @@ -44,6 +44,7 @@ (eval-when-compile (require 'cl)) (declare-function run-ruby "ext:inf-ruby" (&optional command name)) +(declare-function xmp "ext:rcodetools" (&optional option)) (add-to-list 'org-babel-tangle-lang-exts '("ruby" . "rb")) @@ -61,8 +62,14 @@ This function is called by `org-babel-execute-src-block'." (result-type (cdr (assoc :result-type params))) (full-body (org-babel-expand-body:generic body params (org-babel-variable-assignments:ruby params))) - (result (org-babel-ruby-evaluate - session full-body result-type result-params))) + (result (if (member "xmp" result-params) + (with-temp-buffer + (require 'rcodetools) + (insert full-body) + (xmp (cdr (assoc :xmp-option params))) + (buffer-string)) + (org-babel-ruby-evaluate + session full-body result-type result-params)))) (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 5a81f73..8c13cf9 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -96,6 +96,15 @@ controlled by the :comments header argument." :group 'org-babel :type 'string) +(defcustom org-babel-tangle-named-block-combination nil + "Combine blocks of the same name during tangling." + :group 'org-babel + :type '(choice + (const :tag "Default: no special handling" nil) + (const :tag "Append all blocks of the same name" append) + (const :tag "Only keep the first block of the same name" first) + (const :tag "Only keep the last block of the same name" last))) + (defun org-babel-find-file-noselect-refresh (file) "Find file ensuring that the latest changes on disk are represented in the file." @@ -240,7 +249,8 @@ exported source code blocks by language." (setq block-counter (+ 1 block-counter)) (add-to-list 'path-collector file-name))))) specs))) - (org-babel-tangle-collect-blocks lang)) + (org-babel-tangle-combine-named-blocks + (org-babel-tangle-collect-blocks lang))) (message "tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") (file-name-nondirectory @@ -361,6 +371,39 @@ code blocks by language." blocks)) blocks)) +(defun org-babel-tangle-combine-named-blocks (blocks) + "Combine blocks of the same name. +This function follows noweb behavior of appending blocks of the +same name in the order they appear in the file." + (if org-babel-tangle-named-block-combination + (let (tangled-names) + (mapcar + (lambda (by-lang) + (cons + (car by-lang) + (mapcar (lambda (spec) + (let ((name (nth 3 spec))) + (unless (member name tangled-names) + (when name + (setf + (nth 5 spec) + (let ((named (mapcar + (lambda (el) (nth 5 el)) + (remove-if + (lambda (el) + (not (equal name (nth 3 el)))) + (cdr by-lang))))) + (case org-babel-tangle-named-block-combination + (append (mapconcat #'identity + named "")) + (first (first named)) + (last (car (last named)))))) + (add-to-list 'tangled-names name)) + spec))) + (cdr by-lang)))) + blocks)) + blocks)) + (defun org-babel-spec-to-string (spec) "Insert SPEC into the current file. Insert the source-code specified by SPEC into the current diff --git a/lisp/org-exp-blocks.el b/lisp/org-exp-blocks.el index bc8d289..4fd9450 100644 --- a/lisp/org-exp-blocks.el +++ b/lisp/org-exp-blocks.el @@ -76,13 +76,6 @@ (require 'cl)) (require 'org) -(defvar org-exp-blocks-block-regexp - (concat - "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)" - "[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)[\r\n]*[ \t]*" - "#\\+end_\\S-+.*[\r\n]?") - "Regular expression used to match blocks by org-exp-blocks.") - (defun org-export-blocks-set (var value) "Set the value of `org-export-blocks' and install fontification." (set var value) @@ -175,32 +168,52 @@ which defaults to the value of `org-export-blocks-witheld'." (save-window-excursion (let ((case-fold-search t) (types '()) - indentation type func start body headers preserve-indent progress-marker) + matched indentation type func + start end body headers preserve-indent progress-marker) (flet ((interblock (start end) (mapcar (lambda (pair) (funcall (second pair) start end)) org-export-interblocks))) (goto-char (point-min)) (setq start (point)) - (while (re-search-forward org-exp-blocks-block-regexp nil t) - (setq indentation (length (match-string 1))) - (setq type (intern (downcase (match-string 2)))) - (setq headers (save-match-data (org-split-string (match-string 3) "[ \t]+"))) - (setq body (match-string 4)) - (setq preserve-indent (or org-src-preserve-indentation (member "-i" headers))) - (unless preserve-indent - (setq body (save-match-data (org-remove-indentation body)))) - (unless (memq type types) (setq types (cons type types))) - (save-match-data (interblock start (match-beginning 0))) - (when (setq func (cadr (assoc type org-export-blocks))) - (let ((replacement (save-match-data - (if (memq type org-export-blocks-witheld) "" - (apply func body headers))))) - (when replacement - (replace-match replacement t t) - (unless preserve-indent - (indent-code-rigidly - (match-beginning 0) (match-end 0) indentation))))) - (setq start (match-end 0))) + (let ((beg-re "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]")) + (while (re-search-forward beg-re nil t) + (let* ((match-start (match-beginning 0)) + (body-start (match-end 0)) + (indentation (length (match-string 1))) + (inner-re (format "[\r\n]*[ \t]*#\\+\\(begin\\|end\\)_%s" + (regexp-quote (downcase (match-string 2))))) + (type (intern (downcase (match-string 2)))) + (headers (save-match-data + (org-split-string (match-string 3) "[ \t]+"))) + (balanced 1) + (preserve-indent (or org-src-preserve-indentation + (member "-i" headers))) + match-end) + (while (and (not (zerop balanced)) + (re-search-forward inner-re nil t)) + (if (string= (downcase (match-string 1)) "end") + (decf balanced) + (incf balanced))) + (when (not (zerop balanced)) + (error "unbalanced begin/end_%s blocks with %S" + type (buffer-substring match-start (point)))) + (setq match-end (match-end 0)) + (unless preserve-indent + (setq body (save-match-data (org-remove-indentation + (buffer-substring + body-start (match-beginning 0)))))) + (unless (memq type types) (setq types (cons type types))) + (save-match-data (interblock start match-start)) + (when (setq func (cadr (assoc type org-export-blocks))) + (let ((replacement (save-match-data + (if (memq type org-export-blocks-witheld) "" + (apply func body headers))))) + (when replacement + (delete-region match-start match-end) + (goto-char match-start) (insert replacement) + (unless preserve-indent + (indent-code-rigidly match-start (point) indentation)))))) + (setq start (point)))) (interblock start (point-max)) (run-hooks 'org-export-blocks-postblock-hook))))) diff --git a/lisp/org-latex.el b/lisp/org-latex.el index e2c74ae..ef8b2b1 100644 --- a/lisp/org-latex.el +++ b/lisp/org-latex.el @@ -986,7 +986,13 @@ when PUB-DIR is set, use this as the publishing directory." (file (buffer-file-name lbuf)) (base (file-name-sans-extension (buffer-file-name lbuf))) (pdffile (concat base ".pdf")) - (cmds org-latex-to-pdf-process) + (cmds (if (eq org-export-latex-listings 'minted) + ;; automatically add -shell-escape when needed + (mapcar (lambda (cmd) + (replace-regexp-in-string + "pdflatex " "pdflatex -shell-escape " cmd)) + org-latex-to-pdf-process) + org-latex-to-pdf-process)) (outbuf (get-buffer-create "*Org PDF LaTeX Output*")) (bibtex-p (with-current-buffer lbuf (save-excursion diff --git a/lisp/org-list.el b/lisp/org-list.el index d72a284..5160224 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -2946,8 +2946,11 @@ with overruling parameters for `org-list-to-generic'." :istart "\\item " :iend "\n" :icount (let ((enum (nth depth '("i" "ii" "iii" "iv")))) (if enum + ;; LaTeX increments counter just before + ;; using it, so set it to the desired + ;; value, minus one. (format "\\setcounter{enum%s}{%s}\n\\item " - enum counter) + enum (1- counter)) "\\item ")) :csep "\n" :cbon "\\texttt{[X]}" :cboff "\\texttt{[ ]}") |