* [babel] options to the example directive @ 2009-11-03 14:55 Eric S Fraga 2009-11-03 17:34 ` Dan Davison 0 siblings, 1 reply; 6+ messages in thread From: Eric S Fraga @ 2009-11-03 14:55 UTC (permalink / raw) To: org-mode mailing list I am finding org-babel incredibly useful in the preparation of documentation for didactic purposes. Kudos to the developers! I have two queries that I cannot seem to find an answer to in the documentation: 1. is there any way to specify arguments that should be generated for the #+begin_example line for the results of a babel invocation? Specifically, I would like to append automatically, for instance, arguments such as "-t -w 100 -h 20" so that the export to HTML output is presented in a text box that has scroll bars etc. 2. even if I manually put the options on the begin_example line, the export to HTML creates a '<pre class="example">' directive instead of what I would expect: '<textarea cols="40" rows="10">' or something similar. I don't understand why exporting a file without babel constructs should behave differently from exporting with babel. Should a begin_example section not export the same in both cases? I am using org-mode and babel up to date as of this morning. Any pointers highly welcome! Thanks, eric ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [babel] options to the example directive 2009-11-03 14:55 [babel] options to the example directive Eric S Fraga @ 2009-11-03 17:34 ` Dan Davison 2009-11-03 20:57 ` Eric Schulte 0 siblings, 1 reply; 6+ messages in thread From: Dan Davison @ 2009-11-03 17:34 UTC (permalink / raw) To: Eric S Fraga; +Cc: emacs org-mode mailing list Eric S Fraga <ucecesf@ucl.ac.uk> writes: > I am finding org-babel incredibly useful in the preparation of > documentation for didactic purposes. Kudos to the developers! > > I have two queries that I cannot seem to find an answer to in the > documentation: > > 1. is there any way to specify arguments that should be generated for > the #+begin_example line for the results of a babel invocation? Not currently. When exporting the *code* contained in a block, then any switches placed after begin_src are reinstated in the output code block. I.e. begin_src XXX <switches> :exports code ... becomes begin_src XXX <switches> ... However when a begin_example block is created as *results*, it is created without any switches. I'm tending to think that it would be inappropriate to simply reinstate the src block switches in the results block. How do you suggest this option should be made available? Perhaps a new header arg, or as a variable org-babel-results-block-switches, or both? Note that you will need to set org-babel-min-lines-for-block-output to zero in order to guarantee that output is enclosed in a begin_example block. Otherwise small chunks of output will be made verbatim by prepending lines with ': ', in which case (I believe) the -t switch is unavailable. > Specifically, I would like to append automatically, for instance, > arguments such as "-t -w 100 -h 20" so that the export to HTML > output is presented in a text box that has scroll bars etc. > > 2. even if I manually put the options on the begin_example line, the > export to HTML creates a '<pre class="example">' directive instead > of what I would expect: '<textarea cols="40" rows="10">' or > something similar. I don't understand why exporting a file without > babel constructs should behave differently from exporting with This is a consequence of the same issue: org-exp-blocks preprocesses your src block in a pre-export buffer (a copy of the original), hands it to org-babel, which creates the results block (overwriting the version where you had manually inserted switches), and that results block lacks any switches. Dan > babel. Should a begin_example section not export the same in both > cases? > > I am using org-mode and babel up to date as of this morning. > > Any pointers highly welcome! > > Thanks, > eric > > > _______________________________________________ > Emacs-orgmode mailing list > Remember: use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [babel] options to the example directive 2009-11-03 17:34 ` Dan Davison @ 2009-11-03 20:57 ` Eric Schulte 2009-11-04 9:45 ` Eric S Fraga 0 siblings, 1 reply; 6+ messages in thread From: Eric Schulte @ 2009-11-03 20:57 UTC (permalink / raw) To: Dan Davison; +Cc: emacs org-mode mailing list Dan Davison <davison@stats.ox.ac.uk> writes: > > This is a consequence of the same issue: org-exp-blocks preprocesses > your src block in a pre-export buffer (a copy of the original), hands it > to org-babel, which creates the results block (overwriting the version > where you had manually inserted switches), and that results block lacks > any switches. > Would it be worthwhile to add a :results_switches header argument for passing switches through to a results block? If that would solve the problem it should be easy to implement. Best -- Eric ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [babel] options to the example directive 2009-11-03 20:57 ` Eric Schulte @ 2009-11-04 9:45 ` Eric S Fraga 2009-11-04 18:52 ` Dan Davison 0 siblings, 1 reply; 6+ messages in thread From: Eric S Fraga @ 2009-11-04 9:45 UTC (permalink / raw) To: Eric Schulte; +Cc: Dan Davison, emacs org-mode mailing list At Tue, 03 Nov 2009 13:57:22 -0700, Eric Schulte wrote: > > Dan Davison <davison@stats.ox.ac.uk> writes: > > > > > This is a consequence of the same issue: org-exp-blocks preprocesses > > your src block in a pre-export buffer (a copy of the original), hands it > > to org-babel, which creates the results block (overwriting the version > > where you had manually inserted switches), and that results block lacks > > any switches. > > > > Would it be worthwhile to add a :results_switches header argument for > passing switches through to a results block? If that would solve the > problem it should be easy to implement. Best -- Eric Dan & Eric, I think this would be ideal, and results_switches is a perfectly fine name. Thanks, eric ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [babel] options to the example directive 2009-11-04 9:45 ` Eric S Fraga @ 2009-11-04 18:52 ` Dan Davison 2009-11-04 22:01 ` Eric Schulte 0 siblings, 1 reply; 6+ messages in thread From: Dan Davison @ 2009-11-04 18:52 UTC (permalink / raw) To: Eric S Fraga; +Cc: emacs org-mode mailing list [-- Attachment #1: Type: text/plain, Size: 892 bytes --] Eric S Fraga <ucecesf@ucl.ac.uk> writes: > At Tue, 03 Nov 2009 13:57:22 -0700, > Eric Schulte wrote: >> >> Dan Davison <davison@stats.ox.ac.uk> writes: >> >> > >> > This is a consequence of the same issue: org-exp-blocks preprocesses >> > your src block in a pre-export buffer (a copy of the original), hands it >> > to org-babel, which creates the results block (overwriting the version >> > where you had manually inserted switches), and that results block lacks >> > any switches. >> > >> >> Would it be worthwhile to add a :results_switches header argument for >> passing switches through to a results block? If that would solve the >> problem it should be easy to implement. Best -- Eric > > Dan & Eric, I think this would be ideal, and results_switches is a > perfectly fine name. That's in branch results-switches at git://repo.or.cz/org-mode/babel.git, with patch below. Dan [-- Attachment #2: patch --] [-- Type: text/plain, Size: 7163 bytes --] diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index 90ac447..1e04efe 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -175,7 +175,7 @@ the header arguments specified at the source code block." ;; (message "supplied params=%S" params) ;; debugging (let* ((info (or info (org-babel-get-src-block-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) (org-babel-expand-noweb-references info) (second info))) (processed-params (org-babel-process-params params)) @@ -192,7 +192,7 @@ the header arguments specified at the source code block." (funcall cmd body params))) (if (eq result-type 'value) (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)) (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) (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 source block. Specifically at the beginning of the #+RESNAME: 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) (looking-at org-babel-lob-one-liner-regexp))) (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) (when head (goto-char head)) (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))) (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 current source block. With optional argument INSERT controls 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)))) (unless (listp result) (setq result (format "%S" result)))) (if (and insert (member "replace" insert) (not (member "silent" insert))) - (org-babel-remove-result)) + (org-babel-remove-result info)) (if (= (length result) 0) (if (member "value" result-params) (message "No result returned by source block") @@ -578,28 +578,30 @@ code ---- the results are extracted in the syntax of the source (string-equal (substring result -1) "\r")))) (setq result (concat result "\n"))) (save-excursion - (let ((existing-result (org-babel-where-is-src-block-result t))) - (when existing-result (goto-char existing-result) (forward-line 1))) - (cond - ;; assume the result is a table if it's not a string - ((not (stringp result)) - (insert (concat (orgtbl-to-orgtbl - (if (and (listp (car result)) (listp (cdr (car result)))) - result (list result)) - '(:fmt (lambda (cell) (format "%S" cell)))) "\n")) - (forward-line -1) (org-cycle)) - ((member "file" insert) - (insert result)) - ((member "html" insert) - (insert (format "#+BEGIN_HTML\n%s#+END_HTML\n" result))) - ((member "latex" insert) - (insert (format "#+BEGIN_LaTeX\n%s#+END_LaTeX\n" result))) - ((member "code" insert) - (insert (format "#+BEGIN_SRC %s\n%s#+END_SRC\n" lang result))) - ((or (member "raw" insert) (member "org" insert)) - (save-excursion (insert result)) (if (org-at-table-p) (org-cycle))) - (t - (org-babel-examplize-region (point) (progn (insert result) (point)))))) + (let ((existing-result (org-babel-where-is-src-block-result t info)) + (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 + ;; assume the result is a table if it's not a string + ((not (stringp result)) + (insert (concat (orgtbl-to-orgtbl + (if (and (listp (car result)) (listp (cdr (car result)))) + result (list result)) + '(:fmt (lambda (cell) (format "%S" cell)))) "\n")) + (forward-line -1) (org-cycle)) + ((member "file" insert) + (insert result)) + ((member "html" insert) + (insert (format "#+BEGIN_HTML%s\n%s#+END_HTML\n" results-switches result))) + ((member "latex" insert) + (insert (format "#+BEGIN_LaTeX%s\n%s#+END_LaTeX\n" results-switches result))) + ((member "code" insert) + (insert (format "#+BEGIN_SRC %s%s\n%s#+END_SRC\n" lang results-switches result))) + ((or (member "raw" insert) (member "org" insert)) + (save-excursion (insert result)) (if (org-at-table-p) (org-cycle))) + (t + (org-babel-examplize-region (point) (progn (insert result) (point)) results-switches))))) (message "finished")))) (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'." (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." (interactive) (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)))) (defun org-babel-result-end () @@ -643,7 +645,7 @@ RESULT, and the display being the `file-name-nondirectory' if non-nil." (concat "[[file:" result "]]")) -(defun org-babel-examplize-region (beg end) +(defun org-babel-examplize-region (beg end results-switches) "Comment out region using the ': ' org example quote." (interactive "*r") (let ((size (abs (- (line-number-at-pos end) @@ -660,7 +662,7 @@ non-nil." (move-beginning-of-line 1) (insert ": ") (forward-line 1))) (t (goto-char beg) - (insert "#+begin_example\n") + (insert (format "#+begin_example%s\n" results-switches)) (forward-char (- end beg)) (insert "#+end_example\n")))))) [-- Attachment #3: Type: text/plain, Size: 23 bytes --] > > Thanks, > eric [-- Attachment #4: Type: text/plain, Size: 204 bytes --] _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [babel] options to the example directive 2009-11-04 18:52 ` Dan Davison @ 2009-11-04 22:01 ` Eric Schulte 0 siblings, 0 replies; 6+ messages in thread From: Eric Schulte @ 2009-11-04 22:01 UTC (permalink / raw) To: Dan Davison; +Cc: emacs org-mode mailing list Dan Davison <davison@stats.ox.ac.uk> writes: > Eric S Fraga <ucecesf@ucl.ac.uk> writes: > >> At Tue, 03 Nov 2009 13:57:22 -0700, >> Eric Schulte wrote: >>> >>> Dan Davison <davison@stats.ox.ac.uk> writes: >>> >>> > >>> > This is a consequence of the same issue: org-exp-blocks preprocesses >>> > your src block in a pre-export buffer (a copy of the original), hands it >>> > to org-babel, which creates the results block (overwriting the version >>> > where you had manually inserted switches), and that results block lacks >>> > any switches. >>> > >>> >>> Would it be worthwhile to add a :results_switches header argument for >>> passing switches through to a results block? If that would solve the >>> problem it should be easy to implement. Best -- Eric >> >> Dan & Eric, I think this would be ideal, and results_switches is a >> perfectly fine name. > > That's in branch results-switches at git://repo.or.cz/org-mode/babel.git, with patch below. > This changes has now been merged into the main branch. ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-11-04 22:01 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-11-03 14:55 [babel] options to the example directive Eric S Fraga 2009-11-03 17:34 ` Dan Davison 2009-11-03 20:57 ` Eric Schulte 2009-11-04 9:45 ` Eric S Fraga 2009-11-04 18:52 ` Dan Davison 2009-11-04 22:01 ` Eric Schulte
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).