From mboxrd@z Thu Jan 1 00:00:00 1970 From: Feng Shu Subject: Re: How to write a org babel hook, which can manupulate result Date: Thu, 27 Mar 2014 12:31:33 +0800 Message-ID: <87ppl8w9cq.fsf@news.tumashu-localhost.org> References: <87ha6lje04.fsf@news.tumashu-localhost.org> <87k3bh84ry.fsf@tanger.home> <8761n0jyio.fsf@news.tumashu-localhost.org> <87r45o7437.fsf@tanger.home> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33979) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WT2CF-0002Sj-4Z for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 00:45:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WT2C7-0001TI-OY for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 00:45:42 -0400 Received: from plane.gmane.org ([80.91.229.3]:60141) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WT2C7-0001SG-C6 for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 00:45:35 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WT2C5-0002fU-Ca for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 05:45:33 +0100 Received: from 101.22.53.123 ([101.22.53.123]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Mar 2014 05:45:33 +0100 Received: from tumashu by 101.22.53.123 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 27 Mar 2014 05:45:33 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Daimrod writes: > Feng Shu writes: > >> Daimrod writes: >> >>> Feng Shu 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*) > > #+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) >> >> #+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: --