emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Eric Schulte" <schulte.eric@gmail.com>
To: "Sébastien Vauban" <wxhgmqzgwmuf@spammotel.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Re: [Babel] Need for an extra literal block construct
Date: Mon, 22 Nov 2010 17:42:45 -0700	[thread overview]
Message-ID: <87lj4keupm.fsf@gmail.com> (raw)
In-Reply-To: <80k4k5t4jh.fsf@missioncriticalit.com> ("Sébastien Vauban"'s message of "Mon, 22 Nov 2010 22:46:42 +0100")

[-- Attachment #1: Type: text/plain, Size: 2022 bytes --]

Hi Seb,

Sébastien Vauban <wxhgmqzgwmuf@spammotel.com> writes:

[...]
>
> Tested it (yesterday) for HTML. Per-fect!  Thanks a lot... It's of great use.
>

great, thanks for testing

>
> Tried to test it (now) for LaTeX. Can't, for the same reason as
> described in:
>
>    [[http://mid.gmane.org/80eiadw0dh.fsf%40missioncriticalit.com][Email from Sébastien Vauban: Debugger entered--Lisp error: ]]** TODO Debugger entered--Lisp error: (void-function -mode)
>    [2010-11-22 Mon 21:48]
>

After looking at this message I don't understand what the error is, are
you getting a "void-function -mode" error when exporting to LaTeX?  The
following exports fine to LaTeX for me w/o error.

** introducing =wrap= header argument
#+begin_src emacs-lisp :results wrap :exports both
  (mapcar (lambda (el) (list el (+ 1 (* el el)))) (number-sequence 0 10))
#+end_src

#+results:
#+BEGIN_RESULT
|  0 |   1 |
|  1 |   2 |
|  2 |   5 |
|  3 |  10 |
|  4 |  17 |
|  5 |  26 |
|  6 |  37 |
|  7 |  50 |
|  8 |  65 |
|  9 |  82 |
| 10 | 101 |
#+END_RESULT

now indented
- first
- second
  #+begin_src emacs-lisp :results wrap :exports both
    "something else"
  #+end_src

  #+results:
  #+BEGIN_RESULT
  : something else
  #+END_RESULT

>
> Though, already a couple of comments:
>
> 1. I guess there is one little typo in your patch:
>    +	    (wrap "#+BEGIN_LaTe\n" "#+END_LaTeX"))
>                                ^
>

Fixed version attached, Thanks

>
> 2. Could you make the wrap on by default?
>

No, but you can by adding (:results . "wrap") to
`org-babel-default-header-args' in your personal configuration.
Although I guess if this is turned on by default then there should be a
way to turn it off, either a "nowrap" header argument or a "plain"
header argument or something that would be on by default.

So do you think this could be applied to the core?  If not what changes
would you recommend?

Thanks -- Eric

>
> Best regards,
>   Seb


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-wrap-results-header-argument-wraps-code-block-result.patch --]
[-- Type: text/x-diff, Size: 5423 bytes --]

From e2589d43280164dbcb2e1d3b18ef6bf23ac99b6b Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Fri, 19 Nov 2010 16:04:59 -0700
Subject: [PATCH] "wrap" :results header argument wraps code block results

* lisp/ob.el (org-babel-insert-result): Responds to new "wrap" header
  argument.
  (org-babel-merge-params): Includes new "wrap" header argument in
  one of the results header argument exclusive groups.
---
 lisp/ob.el |   72 +++++++++++++++++++++++++++++------------------------------
 1 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/lisp/ob.el b/lisp/ob.el
index 3689619..9feb0a6 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -1433,11 +1433,11 @@ code ---- the results are extracted in the syntax of the source
 	    (delete-region (point) (org-babel-result-end)))
 	   ((member "append" result-params)
 	    (goto-char (org-babel-result-end)) (setq beg (point)))
-	   ((member "prepend" result-params) ;; already there
-	    )))
+	   ((member "prepend" result-params)))) ; already there
 	(setq results-switches
 	      (if results-switches (concat " " results-switches) ""))
-	(cond
+	;; insert results based on type
+	(cond			     
 	 ;; do nothing for an empty result
 	 ((= (length result) 0))
 	 ;; insert a list if preferred
@@ -1449,6 +1449,7 @@ code ---- the results are extracted in the syntax of the source
 				 '(:splicep nil :istart "- " :iend "\n")))))
 	 ;; assume the result is a table if it's not a string
 	 ((not (stringp result))
+	  (goto-char beg)
 	  (insert (concat (orgtbl-to-orgtbl
 			   (if (or (eq 'hline (car result))
 				   (and (listp (car result))
@@ -1458,24 +1459,30 @@ code ---- the results are extracted in the syntax of the source
 	  (goto-char beg) (when (org-at-table-p) (org-table-align)))
 	 ((member "file" result-params)
 	  (insert result))
-	 ((member "html" result-params)
-	  (insert (format "#+BEGIN_HTML%s\n%s#+END_HTML\n"
-			  results-switches result)))
-	 ((member "latex" result-params)
-	  (insert (format "#+BEGIN_LaTeX%s\n%s#+END_LaTeX\n"
-			  results-switches result)))
-	 ((member "code" result-params)
-	  (insert (format "#+BEGIN_SRC %s%s\n%s#+END_SRC\n"
-			  (or lang "none") results-switches result)))
-	 ((member "org" result-params)
-	  (insert (format "#+BEGIN_SRC org\n%s#+END_SRC\n" result)))
-	 ((member "raw" result-params)
-	  (save-excursion (insert result)) (if (org-at-table-p) (org-cycle)))
-	 (t
-	  (org-babel-examplize-region
-	   (point) (progn (insert result) (point)) results-switches)))
-	;; possibly indent the results to match the #+results line
+	 (t (goto-char beg)
+	    (org-babel-examplize-region
+	     (point) (progn (insert result) (point)) results-switches)))
 	(setq end (if (listp result) (org-table-end) (point)))
+	;; possibly wrap result
+	(flet ((wrap (start finish)
+		     (goto-char beg) (insert start)
+		     (goto-char (+ (if (listp result) 0 (length start)) end))
+		     (insert finish) (setq end (point))))
+	  (cond
+	   ((member "html" result-params)
+	    (wrap "#+BEGIN_HTML\n" "#+END_HTML"))
+	   ((member "latex" result-params)
+	    (wrap "#+BEGIN_LaTeX\n" "#+END_LaTeX"))
+	   ((member "code" result-params)
+	    (wrap (format "#+BEGIN_SRC %s%s\n" (or lang "none") results-switches)
+		  "#+END_SRC"))
+	   ((member "org" result-params)
+	    (wrap "#+BEGIN_ORG\n" "#+END_ORG"))
+	   ((member "raw" result-params)
+	    (goto-char beg) (if (org-at-table-p) (org-cycle)))
+	   ((member "wrap" result-params)
+	    (wrap "#+BEGIN_RESULT\n" "#+END_RESULT"))))
+	;; possibly indent the results to match the #+results line
 	(when (and indent (> indent 0)
 		   ;; in this case `table-align' does the work for us
 		   (not (and (listp result)
@@ -1503,22 +1510,13 @@ code ---- the results are extracted in the syntax of the source
      ((org-at-table-p) (progn (goto-char (org-table-end)) (point)))
      ((org-in-item-p) (- (org-list-bottom-point) 1))
      (t
-      (let ((case-fold-search t))
-        (cond
-         ((looking-at "[ \t]*#\\+begin_latex")
-          (re-search-forward "[ \t]*#\\+end_latex" nil t)
-          (forward-line 1))
-         ((looking-at "[ \t]*#\\+begin_html")
-          (re-search-forward "[ \t]*#\\+end_html" nil t)
-          (forward-line 1))
-         ((looking-at "[ \t]*#\\+begin_example")
-          (re-search-forward "[ \t]*#\\+end_example" nil t)
-          (forward-line 1))
-         ((looking-at "[ \t]*#\\+begin_src")
-          (re-search-forward "[ \t]*#\\+end_src" nil t)
-          (forward-line 1))
-         (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
-                     (forward-line 1))))))
+      (let ((case-fold-search t)
+	    (blocks-re (regexp-opt
+			(list "latex" "html" "example" "src" "result"))))
+	(if (looking-at (concat "[ \t]*#\\+begin_" blocks-re))
+	    (re-search-forward (concat "[ \t]*#\\+end_" blocks-re) nil t)
+	  (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
+	    (forward-line 1))))
       (point)))))
 
 (defun org-babel-result-to-file (result)
@@ -1570,7 +1568,7 @@ This takes into account some special considerations for certain
 parameters when merging lists."
   (let ((results-exclusive-groups
 	 '(("file" "list" "vector" "table" "scalar" "raw" "org"
-            "html" "latex" "code" "pp")
+            "html" "latex" "code" "pp" "wrap")
 	   ("replace" "silent" "append" "prepend")
 	   ("output" "value")))
 	(exports-exclusive-groups
-- 
1.7.0.4


[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-11-23  0:43 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-16 15:16 [babel] Environment around exported results Sébastien Vauban
2010-09-20  4:46 ` Eric Schulte
2010-09-20 19:10   ` Sébastien Vauban
2010-09-21  7:44     ` Sébastien Vauban
2010-09-21 13:14     ` Eric Schulte
2010-09-24  9:28       ` Sébastien Vauban
2010-09-24 21:01         ` Rainer M Krug
2010-09-27  8:16           ` Sébastien Vauban
2010-11-19 13:27             ` [Babel] Need for an extra literal block construct Sébastien Vauban
2010-11-19 15:17               ` Christian Moe
2010-11-19 20:12                 ` Sébastien Vauban
2010-11-19 20:26                   ` Sébastien Vauban
2010-11-19 20:38                     ` Thomas S. Dye
2010-11-19 22:02                       ` Sébastien Vauban
2010-11-19 22:20                         ` Thomas S. Dye
2010-11-19 23:00                           ` Sébastien Vauban
2010-11-19 22:24                     ` Eric Schulte
2010-11-19 23:07                       ` Eric Schulte
2010-11-20  7:20                         ` Sébastien Vauban
2010-11-22 21:46                         ` Sébastien Vauban
2010-11-23  0:42                           ` Eric Schulte [this message]
2010-11-23 23:15                             ` Sébastien Vauban
2010-11-19 23:13                       ` Sébastien Vauban
2010-11-19 22:36                   ` Dan Davison
2010-11-20 21:50                     ` Sébastien Vauban
2010-11-21 10:01                       ` Dan Davison
2010-11-22 20:22                         ` Sébastien Vauban
2010-11-21 13:41                       ` Nicolas Goaziou
2010-11-22 20:30                         ` Sébastien Vauban
2010-11-23 19:27                           ` Nicolas Goaziou
2010-11-23 23:22                             ` Sébastien Vauban
2010-11-24 10:14                               ` Nicolas Goaziou
2010-11-19 23:10                   ` Christian Moe
2010-11-19 23:23                     ` Sébastien Vauban

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lj4keupm.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=wxhgmqzgwmuf@spammotel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).