* org-babel: [PATCH] allow emacs-lisp results to be pretty-printed
@ 2009-10-03 18:29 Benjamin Andresen
2009-10-03 19:27 ` Benjamin Andresen
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Andresen @ 2009-10-03 18:29 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 350 bytes --]
Hey there,
on irc (#org-mode) someone asked how one would go about to insert the
result of a emacs-lisp function without it being transformed into a
org-mode table.
I didn't see any other way, so I wrote a small patch that allows the
parameter :results to accept 'pp'. Is this the right way? And where
should this special parameter be documented?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: babel-el-results-pp.patch --]
[-- Type: text/x-patch, Size: 1189 bytes --]
diff --git a/contrib/babel/lisp/langs/org-babel-emacs-lisp.el b/contrib/babel/lisp/langs/org-babel-emacs-lisp.el
index 39f5cc7..60671ac 100644
--- a/contrib/babel/lisp/langs/org-babel-emacs-lisp.el
+++ b/contrib/babel/lisp/langs/org-babel-emacs-lisp.el
@@ -39,10 +39,14 @@
"Execute a block of emacs-lisp code with org-babel. This
function is called by `org-babel-execute-src-block' via multiple-value-bind."
(message "executing emacs-lisp code block...")
- (save-window-excursion
- (let ((print-level nil) (print-length nil))
- (eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
- ,(read (concat "(progn " body ")")))))))
+ (let ((results (cdr (assoc :results params))))
+ (save-window-excursion
+ (let ((print-level nil) (print-length nil))
+ (eval `(let ,(mapcar (lambda (var) `(,(car var) ',(cdr var))) vars)
+ ,(read (concat "(progn " (if (string-match "pp$" results)
+ (concat "(pp " body ")")
+ body)
+ ")"))))))))
(provide 'org-babel-emacs-lisp)
;;; org-babel-emacs-lisp.el ends here
[-- Attachment #3: Type: text/plain, Size: 11 bytes --]
br,
benny
[-- 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] 3+ messages in thread
* Re: allow emacs-lisp results to be pretty-printed
2009-10-03 18:29 org-babel: [PATCH] allow emacs-lisp results to be pretty-printed Benjamin Andresen
@ 2009-10-03 19:27 ` Benjamin Andresen
[not found] ` <m2tyyfi3oz.fsf@gmail.com>
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Andresen @ 2009-10-03 19:27 UTC (permalink / raw)
To: emacs-orgmode
Benjamin Andresen <benny@in-ulm.de> writes:
> where should this special parameter be documented?
I would add a page on Worg that is linked from org-babel.org that
contains the following.
I have done this for org-babel-screen.org here:
http://orgmode.org/worg/org-contrib/babel/org-babel-screen.php
(might not be visible yet, because Worg is only exported from git every
hour or so)
Is that a good way to do this?
* Header Arguments
:PROPERTIES:
:CUSTOM_ID: header-arguments
:END:
- results :: supports everything documented
[[file:org-babel.org::results%20arguments%20specify%20what%20should%20be%20done][here]]
as well as
- pp :: pretty prints results and replaces any previously inserted
results from code block
br,
benny
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [babel] allow emacs-lisp results to be pretty-printed
[not found] ` <m2iqevi24b.fsf@gmail.com>
@ 2009-10-18 16:12 ` Eric Schulte
0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2009-10-18 16:12 UTC (permalink / raw)
To: Benjamin Andresen; +Cc: emacs-orgmode
"Eric Schulte" <schulte.eric@gmail.com> writes:
>>
>>> WRT the pp patch for emacs-lisp, I think it is an excellent addition and
>>> in fact I think that it points to a more general need. Languages should
>>> have the option of returning values as they would appear when written in
>>> the language. That is how they would be printed in a source-code file.
>>> This seems to be what your pp patch does for emacs-lisp. In fact such
>>> output should be wrapped in a #+begin/end-src block for fontification of
>>> the results on export.
>>
This is now implemented behind the "code" header argument. The
following now works with the most recent version of Org-mode. The
"code" header argument currently has explicit support in emacs-lisp,
ruby, and python.
Best -- Eric
#+begin_src emacs-lisp :results code
(mapcar (lambda (el) (lambda (item) (+ item el))) '(1 2 3 4 5))
#+end_src
#+resname:
#+BEGIN_SRC emacs-lisp
((lambda
(item)
(+ item el))
(lambda
(item)
(+ item el))
(lambda
(item)
(+ item el))
(lambda
(item)
(+ item el))
(lambda
(item)
(+ item el)))
#+END_SRC
#+begin_src ruby :results code
[1, 2, 33, 4].map{|n| "the number #{n}"}
#+end_src
#+resname:
#+BEGIN_SRC ruby
["the number 1", "the number 2", "the number 33", "the number 4"]
#+END_SRC
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-10-18 16:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-10-03 18:29 org-babel: [PATCH] allow emacs-lisp results to be pretty-printed Benjamin Andresen
2009-10-03 19:27 ` Benjamin Andresen
[not found] ` <m2tyyfi3oz.fsf@gmail.com>
[not found] ` <87hbufqi8m.fsf@in-ulm.de>
[not found] ` <m2iqevi24b.fsf@gmail.com>
2009-10-18 16:12 ` [babel] " 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).