From 04a4a4862eaac826fc53b625b242a2ad175466c9 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 18 Jul 2009 15:38:21 -0400 Subject: [PATCH 1/5] Using #+begin_example...#+end_example blocks for output. --- lisp/org-babel.el | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index c4fe4c83f..c98d576a8 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -61,6 +61,14 @@ then run `org-babel-pop-to-session'." (defvar org-babel-inline-src-block-regexp nil "Regexp used to test when on an inline org-babel src-block") +(defvar org-babel-min-lines-for-block-output 2 + "If number of lines of output is equal to or exceeds this + value, the output is placed in a + #+begin_example...#+end_example block. Otherwise the output is + marked as literal by inserting colons at the starts of the + lines. This variable only takes effect if the :results output + option is in effect.") + (defun org-babel-named-src-block-regexp-for-name (name) "Regexp used to match named src block." (concat "#\\+srcname:[ \t]*" (regexp-quote name) "[ \t\n]*" @@ -462,14 +470,21 @@ non-nil." (interactive "*r") (let ((size (abs (- (line-number-at-pos end) (line-number-at-pos beg))))) - (if (= size 0) - (let ((result (buffer-substring beg end))) - (delete-region beg end) - (insert (concat ": " result))) - (save-excursion - (goto-char beg) - (dotimes (n size) - (move-beginning-of-line 1) (insert ": ") (forward-line 1)))))) + (save-excursion + (cond ((= size 0) + (error "This should be impossible: a newline was appended to result if missing") + (let ((result (buffer-substring beg end))) + (delete-region beg end) + (insert (concat ": " result)))) + ((< size org-babel-min-lines-for-block-output) + (goto-char beg) + (dotimes (n size) + (move-beginning-of-line 1) (insert ": ") (forward-line 1))) + (t + (goto-char beg) + (insert "#+begin_example\n") + (forward-char (- end beg)) + (insert "#+end_example\n")))))) (defun org-babel-merge-params (&rest plists) "Combine all parameter association lists in PLISTS. Later From 4dfe45cdf16ca75772c63936a88ea1d341d94187 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 18 Jul 2009 15:39:00 -0400 Subject: [PATCH 2/5] Trivial: function name change for clarification. --- lisp/org-babel.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index c98d576a8..86fe8c90f 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -176,11 +176,11 @@ the header arguments specified at the source code block." (setq result (multiple-value-bind (session vars result-params result-type) processed-params (funcall cmd body params))) (if (eq result-type 'value) - (setq result (org-babel-process-result result result-params))) + (setq result (org-babel-process-value-result result result-params))) (org-babel-insert-result result result-params) (case result-type (output nil) (value result)))) -(defun org-babel-process-result (result result-params) +(defun org-babel-process-value-result (result result-params) "Process returned value for insertion in buffer. Currently, this function forces to table output if :results From 802c5c529234ded083c3a8523b242d69150a0ee6 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 18 Jul 2009 15:39:47 -0400 Subject: [PATCH 3/5] Updating org-babel.org. --- org-babel.org | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/org-babel.org b/org-babel.org index ea5749e65..fca0d5393 100644 --- a/org-babel.org +++ b/org-babel.org @@ -83,10 +83,15 @@ cd ~ && du -sc * |grep -v total | 1264 | "tools" | #+srcname: directory-pie -#+begin_src R :var dirs = directories +#+begin_src R :var dirs = directories :session R-pie-example pie(dirs[,1], labels = dirs[,2]) #+end_src + + + + + *** operations in/on tables #+tblname: grades-table @@ -211,6 +216,8 @@ would then be [[#sandbox][the sandbox]]. output. Sometimes one will want to see stdout just to check everything looks OK, and then fold it away. + I'm addressing this in branch 'examplizing-output'. + ** TODO make tangle files read-only? With a file-local variable setting, yea that makes sense. Maybe the header should reference the related org-mode file. @@ -2036,7 +2043,17 @@ plot "data" using 1:2 with lines (see [[* file result types][file result types]]) -* Bugs [19/30] +* Bugs [20/31] +** TODO prompt characters appearing in output with R +#+begin_src R :session *R* :results output + x <- 6 + y <- 8 + 3 +#+end_src + +#+resname: +: > [1] 3 + ** TODO o-b-execute-subtree overwrites heading when subtree is folded *** Example Try M-x org-babel-execute-subtree with the subtree folded and @@ -2073,11 +2090,6 @@ even a third" #+end_src #+resname: multi-line-string-output - -** TODO cursor movement when evaluating source blocks - E.g. the pie chart example. Despite the save-window-excursion in - org-babel-execute:R. (I never learned how to do this properly: org-R - jumps all over the place...) ** PROPOSED external shell execution can't isolate return values I have no idea how to do this as of yet. The result is that when @@ -2172,6 +2184,13 @@ b=5 set this automatically, and we are SOL without a regexp to match the prompt. +** DONE cursor movement when evaluating source blocks + E.g. the pie chart example. Despite the save-window-excursion in + org-babel-execute:R. (I never learned how to do this properly: org-R + jumps all over the place...) + + I don't see this now [ded] + ** DONE LoB: calls fail if reference has single character name commit 21d058869df1ff23f4f8cc26f63045ac9c0190e2 **** This doesn't work From c2b255e0daa5cf2f906f313f934473bfc862ac5c Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 18 Jul 2009 15:52:51 -0400 Subject: [PATCH 4/5] Changing default min lines for block output to 10 --- lisp/org-babel.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index 86fe8c90f..ba6fb8315 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -61,7 +61,7 @@ then run `org-babel-pop-to-session'." (defvar org-babel-inline-src-block-regexp nil "Regexp used to test when on an inline org-babel src-block") -(defvar org-babel-min-lines-for-block-output 2 +(defvar org-babel-min-lines-for-block-output 10 "If number of lines of output is equal to or exceeds this value, the output is placed in a #+begin_example...#+end_example block. Otherwise the output is From bcfa3b95c7bb1c0f5fc58a6be4c44f5d3746bbc8 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 18 Jul 2009 17:47:30 -0400 Subject: [PATCH 5/5] Add ability to remove #+begin_example blocks of output. --- lisp/org-babel.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lisp/org-babel.el b/lisp/org-babel.el index ba6fb8315..e991731e4 100644 --- a/lisp/org-babel.el +++ b/lisp/org-babel.el @@ -451,11 +451,15 @@ relies on `org-babel-insert-result'." (save-excursion (if (org-at-table-p) (org-table-end) - (while (if (looking-at "\\(: \\|\\[\\[\\)") - (progn (while (looking-at "\\(: \\|\\[\\[\\)") - (forward-line 1)) t)) - (forward-line 1)) - (forward-line -1) + (let ((case-fold-search nil)) + (if (looking-at-p "#\\+begin_example") + (search-forward "#+end_example" nil t) + (progn + (while (if (looking-at "\\(: \\|\\[\\[\\)") + (progn (while (looking-at "\\(: \\|\\[\\[\\)") + (forward-line 1)) t)) + (forward-line 1)) + (forward-line -1)))) (point)))) (defun org-babel-result-to-file (result)