From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: table export to same buffer Date: Sat, 03 Aug 2013 10:06:06 +0200 Message-ID: <87siyr19n5.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38840) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5WrH-0006Wz-W6 for emacs-orgmode@gnu.org; Sat, 03 Aug 2013 04:06:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V5WrB-0004Xo-TG for emacs-orgmode@gnu.org; Sat, 03 Aug 2013 04:06:39 -0400 Received: from plane.gmane.org ([80.91.229.3]:55884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V5WrB-0004Xd-Mi for emacs-orgmode@gnu.org; Sat, 03 Aug 2013 04:06:33 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1V5Wr5-0004L9-4U for emacs-orgmode@gnu.org; Sat, 03 Aug 2013 10:06:27 +0200 Received: from g231224114.adsl.alicedsl.de ([92.231.224.114]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Aug 2013 10:06:27 +0200 Received: from tjolitz by g231224114.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 03 Aug 2013 10:06:27 +0200 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 Rustom Mody writes: > Sebastien Vauban wrote > > On Fri, Aug 2, 2013 at 10:53 PM, Rustom Mody > wrote: > > Is it possible to export an orgmode table not to a new file but > overwriting the org table in the same buffer? > > Context is editing source code which contains a largeish table > of (say) constants. Editing is done with orgtbl minor mode. > When done it should become back the table in the natural > format of the programming language > [For simplicity lets just say csv will do] > Using an Org Babel code block (which you have to write, of course) > taking as input your table, and outputting your constants in the > wished format should do what you're looking for, right? > > I dont think so. The context is writing C with C mode (or haskell with > haskell-mode python with python-mode etc) ie the user is not using > orgmode.  That is why I mentioned orgtbl, ie org table editing > facilities are needed but the major mode is something else. > > However here some pre and postprocessing is also probably required. > Something like an automation of the following: > > 1. Editing a large struct spec in C -- major mode is C-mode > 2. Select the region (may even be a rectangle) > 3. Paste into an org-mode buffer > 4. Run C-c | on region > 5. Edit table as required > 6. org-table-export in desired format to a file F > 7. Visit F > 8. Copy/Cut F (if necessary as rectangle) > 9. Go back to original C-mode buffer and paste Another possibility is to make your source code file an 'outshine' file (activate outline-minor-mode with outshine.el extensions and structure it with outcommented Org-mode headlines), because then you get many of these steps for free (see [[http://orgmode.org/worg/org-tutorials/org-outside-org.html][Org-mode outside Org-mode]] on Worg for more info about outshine.el and outorg.el). This way, your source code file really _is_ an Org-mode file too, you switch between the two views on the same file with 'M-# M-#' and 'M-#'. I can give you an example without changing buffer while writing this email, since 'outorg' works with message-mode too, i.e. doing 'M-# M-#' in a message-mode buffer lets me write my email in full Org-mode. Lets insert a table with constants: #+tblname: consts | constant | value | |----------+---------| | conway | 1.30357 | | pi | 3.14159 | | e | 2.71828 | #+name: tbl2lst #+header: :var table=consts #+header: :results value list verbatim :wrap "SRC picolisp" #+begin_src emacs-lisp `(prog (scl 5) (setq lst (car ',table))) #+end_src #+results: tbl2lst #+BEGIN_SRC picolisp (prog (scl 5) (setq lst (car (quote (("constant" "value") hline ("conway" 1.30357) ("pi" 3.14159) ("e" 2.71828)))))) #+END_SRC So the steps are: 1. Make your source file an outshine file 2. Edit it as Org-file (with 'M-# M-#' outorg-edit-as-org) 3. Go back to the source view (with 'M-#' outorg-copy-edits-and-exit) Assume I'm editing a PicoLisp source file and want to introduce constants the easy way (in an Org-mode table). Then in step (2) I would add the table 'consts' and the Emacs Lisp source-block 'tbl2lst'. When going back to the source view, the table and the source block will be converted to PicoLisp comments. No so the results block, because outorg recognizes its a PicoLisp block and will convert it back to source code. Thus in the Emacs Lisp block I use the table as variable that holds a nested list structure and transform this nested list into a structure of my target programming language, let it be PicoLisp or C or whatever. This should be much easier than parsing the table itself. Then everytime you want to edit the constants, you simply switch to Org-mode view, edit the Org table, eval the Emacs Lisp source-block, and switch back to PicoLisp source view. -- cheers, Thorsten