emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: ishi soichi <soichi777@gmail.com>
Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org,
	Carsten Dominik <carsten.dominik@gmail.com>
Subject: Re: Elisp code to insert a word in table
Date: Sat, 04 Dec 2010 07:29:32 -0500	[thread overview]
Message-ID: <10015.1291465772@gamaville.dokosmarshall.org> (raw)
In-Reply-To: Message from ishi soichi <soichi777@gmail.com> of "Sat, 04 Dec 2010 20:27:46 +0900." <AANLkTiniUTnFA7oGf-OsgSkJO5i52WJdjGq0Lh2y2n0K@mail.gmail.com>

ishi soichi <soichi777@gmail.com> wrote:

> Ah, I need more help, though...
> 
> I have tried this code.  I made it as simple as possible to clarify my
> question.
> 
> (defun add-word ()
>   (interactive)
>   '(org-table-put (@2 $2 "word!")))
> 
> and execute in a buffer having a table already.  It did not work at all.
> 

Four problems:

o point must be *in* the table before you call org-table-put (which
  incidentally also answers your question below about multiple tables).

o line and column are integers: @2 and $2 is syntax for table formulas
  in the spreadsheet, not for providing arguments to this function.

o quoting returns the quoted expression unevaluated, so the last line of
  your function does not do anything much; in particular, it does *not*
  call org-table-put at all (if it had you would have gotten an error).

o lisp functions are called like this: (func arg1 arg2 ...) and *not* like this:
  (func (arg1 arg2 ...))

So your function should look something like this:

(defun add-word ()
   (interactive)
   (save-excursion
      (goto-char <some-place-inside-the-table>)
      (org-table-put 2 2 "word!" t)))

where you'll have to figure out how to get the point somewhere inside
the table.  In the simplest case, providing a character position will
work, but is obviously not very general. I won't try to explain the
save-excursion here: see its documentation for more details.

I'd recommend you spend some time studying the "Introduction to Emacs Lisp"
guide:

   http://www.gnu.org/software/emacs/emacs-lisp-intro/html_node/index.html


> But also I kept wondering what could happen if there are two separate tables
> in the same buffer?  I checked cells with C-c?, then realized that the cell
> locations are not unique in more than one table.  So, there must be a way to
> identify the table in question.
> 

HTH.
Nick

  reply	other threads:[~2010-12-04 12:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-03  9:00 Elisp code to insert a word in table ishi soichi
2010-12-03  9:51 ` Carsten Dominik
2010-12-03 10:52   ` ishi soichi
2010-12-04 11:27     ` ishi soichi
2010-12-04 12:29       ` Nick Dokos [this message]
2010-12-04 23:08         ` ishi soichi

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=10015.1291465772@gamaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=soichi777@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).