emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to write a org babel hook, which can manupulate result
@ 2014-03-26 13:17 Feng Shu
  2014-03-26 13:32 ` Daimrod
  0 siblings, 1 reply; 6+ messages in thread
From: Feng Shu @ 2014-03-26 13:17 UTC (permalink / raw)
  To: orgmode

Hi:

I want to write a hook to menupulate org babel output,
The problem is: How can I get two points info: [pointA] and [pointB]
in my hook function?

#+begin_src R :results output raw drawer
tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
print(ascii(tbl),type="org")
#+END_SRC

#+RESULTS:
:RESULTS:
[pointA]
|   |    a |    b |
|---+------+------|
| 1 | 1.00 | 3.00 |
| 2 | 2.00 | 2.00 |
| 3 | 3.00 | 1.00 |
[pointB]
:END:



-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to write a org babel hook, which can manupulate result
  2014-03-26 13:17 How to write a org babel hook, which can manupulate result Feng Shu
@ 2014-03-26 13:32 ` Daimrod
  2014-03-26 15:32   ` Feng Shu
  2014-03-27  0:06   ` Feng Shu
  0 siblings, 2 replies; 6+ messages in thread
From: Daimrod @ 2014-03-26 13:32 UTC (permalink / raw)
  To: emacs-orgmode

Feng Shu <tumashu@gmail.com> writes:

> Hi:
Hi Feng,

Look at the :post header argument.
(info "(org) post")

> I want to write a hook to menupulate org babel output,
> The problem is: How can I get two points info: [pointA] and [pointB]
> in my hook function?
>
> #+begin_src R :results output raw drawer
> tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
> print(ascii(tbl),type="org")
> #+END_SRC
>
> #+RESULTS:
> :RESULTS:
> [pointA]
> |   |    a |    b |
> |---+------+------|
> | 1 | 1.00 | 3.00 |
> | 2 | 2.00 | 2.00 |
> | 3 | 3.00 | 1.00 |
> [pointB]
> :END:

-- 
Daimrod/Greg

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to write a org babel hook, which can manupulate result
  2014-03-26 13:32 ` Daimrod
@ 2014-03-26 15:32   ` Feng Shu
  2014-03-27  0:06   ` Feng Shu
  1 sibling, 0 replies; 6+ messages in thread
From: Feng Shu @ 2014-03-26 15:32 UTC (permalink / raw)
  To: emacs-orgmode

Daimrod <daimrod@gmail.com> writes:

> Feng Shu <tumashu@gmail.com> writes:
>
>> Hi:
> Hi Feng,
>
> Look at the :post header argument.
> (info "(org) post")

Thanks ...
>
>> I want to write a hook to menupulate org babel output,
>> The problem is: How can I get two points info: [pointA] and [pointB]
>> in my hook function?
>>
>> #+begin_src R :results output raw drawer
>> tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
>> print(ascii(tbl),type="org")
>> #+END_SRC
>>
>> #+RESULTS:
>> :RESULTS:
>> [pointA]
>> |   |    a |    b |
>> |---+------+------|
>> | 1 | 1.00 | 3.00 |
>> | 2 | 2.00 | 2.00 |
>> | 3 | 3.00 | 1.00 |
>> [pointB]
>> :END:

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to write a org babel hook, which can manupulate result
  2014-03-26 13:32 ` Daimrod
  2014-03-26 15:32   ` Feng Shu
@ 2014-03-27  0:06   ` Feng Shu
  2014-03-27  2:44     ` Daimrod
  1 sibling, 1 reply; 6+ messages in thread
From: Feng Shu @ 2014-03-27  0:06 UTC (permalink / raw)
  To: emacs-orgmode

Daimrod <daimrod@gmail.com> writes:

> Feng Shu <tumashu@gmail.com> writes:
>
>> Hi:
> Hi Feng,
>
> Look at the :post header argument.
> (info "(org) post")

How to use elisp in :post directly,
for example:

#+begin_src R :results output raw drawer :post (align-multi-table)
  <content>
#+end_src

#+begin_comment
(defun align-multi-table (&optional content)
  (interactive)
  (let ((content (or content *this*)))
    (with-temp-buffer
      (insert content)
      (goto-char (point-min))
      (while (not (eobp))
	(when (org-at-table-p)
	  (org-table-align))
	(forward-line))
      (buffer-string))))
#+end_comment

>
>> I want to write a hook to menupulate org babel output,
>> The problem is: How can I get two points info: [pointA] and [pointB]
>> in my hook function?
>>
>> #+begin_src R :results output raw drawer
>> tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
>> print(ascii(tbl),type="org")
>> #+END_SRC
>>
>> #+RESULTS:
>> :RESULTS:
>> [pointA]
>> |   |    a |    b |
>> |---+------+------|
>> | 1 | 1.00 | 3.00 |
>> | 2 | 2.00 | 2.00 |
>> | 3 | 3.00 | 1.00 |
>> [pointB]
>> :END:

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to write a org babel hook, which can manupulate result
  2014-03-27  0:06   ` Feng Shu
@ 2014-03-27  2:44     ` Daimrod
  2014-03-27  4:31       ` Feng Shu
  0 siblings, 1 reply; 6+ messages in thread
From: Daimrod @ 2014-03-27  2:44 UTC (permalink / raw)
  To: emacs-orgmode

Feng Shu <tumashu@gmail.com> writes:

> Daimrod <daimrod@gmail.com> writes:
>
>> Feng Shu <tumashu@gmail.com> writes:
>>
>>> Hi:
>> Hi Feng,
>>
>> Look at the :post header argument.
>> (info "(org) post")
>
> How to use elisp in :post directly,

I don't think you can.

You have to use it this way (not tested):

#+NAME: align-multi-table
#+BEGIN_SRC emacs-lisp :var content="nil" :results raw
  (align-multi-table content)
#+END_SRC
#+begin_src R :results output raw drawer :post align-multi-table(content=*this*)
  <content>
#+end_src

> for example:
>
> #+begin_src R :results output raw drawer :post (align-multi-table)
>   <content>
> #+end_src
> #+begin_comment
> (defun align-multi-table (&optional content)
>   (interactive)
>   (let ((content (or content *this*)))
>     (with-temp-buffer
>       (insert content)
>       (goto-char (point-min))
>       (while (not (eobp))
> 	(when (org-at-table-p)
> 	  (org-table-align))
> 	(forward-line))
>       (buffer-string))))
> #+end_comment
>
>>
>>> I want to write a hook to menupulate org babel output,
>>> The problem is: How can I get two points info: [pointA] and [pointB]
>>> in my hook function?
>>>
>>> #+begin_src R :results output raw drawer
>>> tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
>>> print(ascii(tbl),type="org")
>>> #+END_SRC
>>>
>>> #+RESULTS:
>>> :RESULTS:
>>> [pointA]
>>> |   |    a |    b |
>>> |---+------+------|
>>> | 1 | 1.00 | 3.00 |
>>> | 2 | 2.00 | 2.00 |
>>> | 3 | 3.00 | 1.00 |
>>> [pointB]
>>> :END:

-- 
Daimrod/Greg

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: How to write a org babel hook, which can manupulate result
  2014-03-27  2:44     ` Daimrod
@ 2014-03-27  4:31       ` Feng Shu
  0 siblings, 0 replies; 6+ messages in thread
From: Feng Shu @ 2014-03-27  4:31 UTC (permalink / raw)
  To: emacs-orgmode

Daimrod <daimrod@gmail.com> writes:

> Feng Shu <tumashu@gmail.com> writes:
>
>> Daimrod <daimrod@gmail.com> writes:
>>
>>> Feng Shu <tumashu@gmail.com> writes:
>>>
>>>> Hi:
>>> Hi Feng,
>>>
>>> Look at the :post header argument.
>>> (info "(org) post")
>>
>> How to use elisp in :post directly,
>
> I don't think you can.
>
> You have to use it this way (not tested):
> #+NAME: align-multi-table
> #+BEGIN_SRC emacs-lisp :var content="nil" :results raw
>   (align-multi-table content)
> #+END_SRC
> #+begin_src R :results output raw drawer :post align-multi-table(content=*this*)
>   <content>
> #+end_src

I prefer using a hook function to do this job, The below is my hook:

#+begin_src elisp
(add-hook 'org-babel-after-execute-hook 'eh-org-babel-align-tables)

(defun eh-org-babel-align-tables (&optional info)
  "Align all tables in the result of the current source"
  (interactive)
  (let ((location (org-babel-where-is-src-block-result nil info)))
    (when location
      (save-excursion
        (goto-char location)
	(when (looking-at (concat org-babel-result-regexp ".*$"))
	  (while (< (point) (progn (forward-line 1) (org-babel-result-end)))
	    (when (org-at-table-p)
	      (toggle-truncate-lines 1)
	      (org-table-align)
	      (goto-char (org-table-end)))
	    (forward-line)))))))
#+end_src


>
>> for example:
>>
>> #+begin_src R :results output raw drawer :post (align-multi-table)
>>   <content>
>> #+end_src
>> #+begin_comment
>> (defun align-multi-table (&optional content)
>>   (interactive)
>>   (let ((content (or content *this*)))
>>     (with-temp-buffer
>>       (insert content)
>>       (goto-char (point-min))
>>       (while (not (eobp))
>> 	(when (org-at-table-p)
>> 	  (org-table-align))
>> 	(forward-line))
>>       (buffer-string))))
>> #+end_comment
>>
>>>
>>>> I want to write a hook to menupulate org babel output,
>>>> The problem is: How can I get two points info: [pointA] and [pointB]
>>>> in my hook function?
>>>>
>>>> #+begin_src R :results output raw drawer
>>>> tbl <- data.frame(a=c(1,2,3),b=c(3,2,1))
>>>> print(ascii(tbl),type="org")
>>>> #+END_SRC
>>>>
>>>> #+RESULTS:
>>>> :RESULTS:
>>>> [pointA]
>>>> |   |    a |    b |
>>>> |---+------+------|
>>>> | 1 | 1.00 | 3.00 |
>>>> | 2 | 2.00 | 2.00 |
>>>> | 3 | 3.00 | 1.00 |
>>>> [pointB]
>>>> :END:

-- 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-27  4:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-26 13:17 How to write a org babel hook, which can manupulate result Feng Shu
2014-03-26 13:32 ` Daimrod
2014-03-26 15:32   ` Feng Shu
2014-03-27  0:06   ` Feng Shu
2014-03-27  2:44     ` Daimrod
2014-03-27  4:31       ` Feng Shu

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).