emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Heikki Lehvaslaiho <heikki.lehvaslaiho@gmail.com>
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: emacs-orgmode@gnu.org, Thorsten Jolitz <tjolitz@gmail.com>
Subject: Re: manipulate org tables using emacs-lisp
Date: Sun, 2 Oct 2016 10:19:28 +0300	[thread overview]
Message-ID: <CAK=ukcZSwjfU8Xf78mFOY7qWUsi7BbQzAEct4sGiNTL2vMV1Hw@mail.gmail.com> (raw)
In-Reply-To: <m2oa345ugr.fsf@polytechnique.org>

[-- Attachment #1: Type: text/plain, Size: 2263 bytes --]

Hi Alan,

Try this function. You can test if the table was found before manipulating
it. Table functions typically work only inside tables, but the #+NAME line
is part of it although it is before the table itself (as defined by
function org-table-begin).


  (defun my/org-table-find-by-name (str)
    "Move point to the first table of the buffer with STR in the name.

The point does not move if the table is not found.
Returns the new position if successful, nil otherwise.
"
    (interactive "sTable name substring: ")
    (let ((re (concat "#\\+NAME:.+" str))
          (loc-table nil))
      (setq loc-table (save-excursion
                        (goto-char (point-min))
                        (re-search-forward re nil t)))
      (if (number-or-marker-p loc-table)
          (goto-char loc-table))))

  -Heikki

Hi Thorsten,

>
> On 2016-09-30 22:52, Thorsten Jolitz <tjolitz@gmail.com> writes:
>
> >> Are there functions for manipulating org-tables using emacs-lisp? More
> >> precisely, I would like to refer to a table by its name, read some cells
> >> (either by position or by matching some given text with some text in the
> >> first row/column), and write in some cells.
> >
> > ,----[ C-h f org-table-to-lisp RET ]
> > | org-table-to-lisp is an autoloaded compiled Lisp function in
> > | ‘../org-mode/lisp/org-table.el’.
> > |
> > | (org-table-to-lisp &optional TXT)
> > |
> > | Convert the table at point to a Lisp structure.
> > | The structure will be a list.  Each item is either the symbol ‘hline’
> > | for a horizontal separator line, or a list of field values as strings.
> > | The table is taken from the parameter TXT, or from the buffer at point.
> > |
> > | [back]
> > `----
> >
> > returns the table as a nested list you can map with lots of Elisp
> > functions (like mapcar).
> >
> > Ex.:
> >
> > | my | tab |
> > |  1 |   2 |
> >
> > =>
> >
> > (("my" "tab") ("1" "2"))
>
> This is very useful, thank you. But how do I go to a named table? I
> found org-babel-goto-named-block, but nothing for tables.
>
> Thanks again,
>
> Alan
>
> --
> OpenPGP Key ID : 040D0A3B4ED2E5C7
> Monthly Athmospheric CO₂, Mauna Loa Obs. 2016-08: 402.25, 2015-08: 398.93
>

[-- Attachment #2: Type: text/html, Size: 3262 bytes --]

  parent reply	other threads:[~2016-10-02  7:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-30  6:27 manipulate org tables using emacs-lisp Alan Schmitt
2016-09-30 20:52 ` Thorsten Jolitz
2016-10-01  8:44   ` Alan Schmitt
2016-10-01 16:32     ` Thorsten Jolitz
2016-10-02  7:19     ` Heikki Lehvaslaiho [this message]
2016-10-03 12:58       ` Alan Schmitt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK=ukcZSwjfU8Xf78mFOY7qWUsi7BbQzAEct4sGiNTL2vMV1Hw@mail.gmail.com' \
    --to=heikki.lehvaslaiho@gmail.com \
    --cc=alan.schmitt@polytechnique.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=tjolitz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).