emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Elisp code to insert a word in table
@ 2010-12-03  9:00 ishi soichi
  2010-12-03  9:51 ` Carsten Dominik
  0 siblings, 1 reply; 6+ messages in thread
From: ishi soichi @ 2010-12-03  9:00 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 310 bytes --]

Hi. I'm trying to write an elisp code to enter words into a table of
org-mode.

after designating a buffer, which already contains a table, I simply wrote,

    '(insert "test!" @2$2)

does not work obviously.

Do I need to move the "point" to the particular cell before inserting?

Thanks in advance.

soichi

[-- Attachment #1.2: Type: text/html, Size: 485 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Elisp code to insert a word in table
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Carsten Dominik @ 2010-12-03  9:51 UTC (permalink / raw)
  To: ishi soichi; +Cc: emacs-orgmode

Hi Ishi,

On Dec 3, 2010, at 10:00 AM, ishi soichi wrote:

> Hi. I'm trying to write an elisp code to enter words into a table of  
> org-mode.
>
> after designating a buffer, which already contains a table, I simply  
> wrote,
>
>     '(insert "test!" @2$2)
>
> does not work obviously.

indeed.


>
> Do I need to move the "point" to the particular cell before inserting?

You could to that, using the functions org-table-goto-line and then  
org-table-goto-column.

However, it is easier to use, for programmatic access to fields, the  
functions
`org-table-put' and `org-table-get'.

- Carsten

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Elisp code to insert a word in table
  2010-12-03  9:51 ` Carsten Dominik
@ 2010-12-03 10:52   ` ishi soichi
  2010-12-04 11:27     ` ishi soichi
  0 siblings, 1 reply; 6+ messages in thread
From: ishi soichi @ 2010-12-03 10:52 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 735 bytes --]

Thanks for such a quick response!

soichi

2010/12/3 Carsten Dominik <carsten.dominik@gmail.com>

> Hi Ishi,
>
>
> On Dec 3, 2010, at 10:00 AM, ishi soichi wrote:
>
>  Hi. I'm trying to write an elisp code to enter words into a table of
>> org-mode.
>>
>> after designating a buffer, which already contains a table, I simply
>> wrote,
>>
>>    '(insert "test!" @2$2)
>>
>> does not work obviously.
>>
>
> indeed.
>
>
>
>
>> Do I need to move the "point" to the particular cell before inserting?
>>
>
> You could to that, using the functions org-table-goto-line and then
> org-table-goto-column.
>
> However, it is easier to use, for programmatic access to fields, the
> functions
> `org-table-put' and `org-table-get'.
>
> - Carsten
>

[-- Attachment #1.2: Type: text/html, Size: 1400 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Elisp code to insert a word in table
  2010-12-03 10:52   ` ishi soichi
@ 2010-12-04 11:27     ` ishi soichi
  2010-12-04 12:29       ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: ishi soichi @ 2010-12-04 11:27 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1372 bytes --]

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.

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.

Thanks again.

soichi

2010/12/3 ishi soichi <soichi777@gmail.com>

> Thanks for such a quick response!
>
> soichi
>
> 2010/12/3 Carsten Dominik <carsten.dominik@gmail.com>
>
> Hi Ishi,
>>
>>
>> On Dec 3, 2010, at 10:00 AM, ishi soichi wrote:
>>
>>  Hi. I'm trying to write an elisp code to enter words into a table of
>>> org-mode.
>>>
>>> after designating a buffer, which already contains a table, I simply
>>> wrote,
>>>
>>>    '(insert "test!" @2$2)
>>>
>>> does not work obviously.
>>>
>>
>> indeed.
>>
>>
>>
>>
>>> Do I need to move the "point" to the particular cell before inserting?
>>>
>>
>> You could to that, using the functions org-table-goto-line and then
>> org-table-goto-column.
>>
>> However, it is easier to use, for programmatic access to fields, the
>> functions
>> `org-table-put' and `org-table-get'.
>>
>> - Carsten
>>
>
>

[-- Attachment #1.2: Type: text/html, Size: 2453 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Elisp code to insert a word in table
  2010-12-04 11:27     ` ishi soichi
@ 2010-12-04 12:29       ` Nick Dokos
  2010-12-04 23:08         ` ishi soichi
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2010-12-04 12:29 UTC (permalink / raw)
  To: ishi soichi; +Cc: nicholas.dokos, emacs-orgmode, Carsten Dominik

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Elisp code to insert a word in table
  2010-12-04 12:29       ` Nick Dokos
@ 2010-12-04 23:08         ` ishi soichi
  0 siblings, 0 replies; 6+ messages in thread
From: ishi soichi @ 2010-12-04 23:08 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: emacs-orgmode, Carsten Dominik


[-- Attachment #1.1: Type: text/plain, Size: 279 bytes --]

I'd recommend you spend some time studying the "Introduction to Emacs Lisp"
> guide:
>
>
>
Thanks for pointing this out.  I have recently started programming in elisp,
and am still having difficulty in basic understanding.

But the code worked.  So thanks for your help.

soichi

[-- Attachment #1.2: Type: text/html, Size: 592 bytes --]

[-- Attachment #2: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-12-04 23:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2010-12-04 23:08         ` ishi soichi

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).