From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Elisp code to insert a word in table Date: Sat, 04 Dec 2010 07:29:32 -0500 Message-ID: <10015.1291465772@gamaville.dokosmarshall.org> References: Reply-To: nicholas.dokos@hp.com Return-path: Received: from [140.186.70.92] (port=52623 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POrFK-0000aj-3X for emacs-orgmode@gnu.org; Sat, 04 Dec 2010 07:29:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POrF9-0002RR-SN for emacs-orgmode@gnu.org; Sat, 04 Dec 2010 07:29:46 -0500 Received: from vms173011pub.verizon.net ([206.46.173.11]:48755) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POrF9-0002Qp-L9 for emacs-orgmode@gnu.org; Sat, 04 Dec 2010 07:29:35 -0500 Received: from gamaville.dokosmarshall.org ([unknown] [173.76.32.106]) by vms173011.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0LCW00M9ULD8TCF0@vms173011.mailsrvcs.net> for emacs-orgmode@gnu.org; Sat, 04 Dec 2010 06:29:33 -0600 (CST) In-reply-to: Message from ishi soichi of "Sat, 04 Dec 2010 20:27:46 +0900." List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: ishi soichi Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org, Carsten Dominik ishi soichi 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 ) (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