emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* changing cells in an org-mode table with Emacs lisp
@ 2014-12-27 16:37 Tamas Papp
  2014-12-28 18:38 ` Michael Brand
  0 siblings, 1 reply; 2+ messages in thread
From: Tamas Papp @ 2014-12-27 16:37 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I would like to manipulate cells in an org-mode table using Emacs lisp
code. Suppose I have a function (FORMAT-CELL CELL ROW COL) that takes a
cell (string), row and column numbers, and returns a new string if I
want to replace content in a cell, and NIL otherwise.

I need help with writing code that makes Emacs walk the table (all
cells), and then the new row when I insert a row (eg after capture).

For example, if my formatting function is

  (defun format-cell (cell row col)
    ;; toy example, actual code would be more complicated
    (when (<= (length cell) col)
      (concat "*" cell "*")))

then the table

| a   | a   |
| aa  | aa  |
| aaa | aaa |

would be replaced by

| *a* | *a*  |
| aa  | *aa* |
| aaa | aaa  |

I need the replacement in place, I don't want to make a new table. I
would like to re-align the table when done.

Any help with this would be appreciated, in particular, the names of the
functions that would help me get started, I could not figure this out.

Best,

Tamas

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

* Re: changing cells in an org-mode table with Emacs lisp
  2014-12-27 16:37 changing cells in an org-mode table with Emacs lisp Tamas Papp
@ 2014-12-28 18:38 ` Michael Brand
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Brand @ 2014-12-28 18:38 UTC (permalink / raw)
  To: Tamas Papp; +Cc: Org Mode

Hi Tamas

On Sat, Dec 27, 2014 at 5:37 PM, Tamas Papp <tkpapp@gmail.com> wrote:
> | a   | a   |
> | aa  | aa  |
> | aaa | aaa |
>
> would be replaced by
>
> | *a* | *a*  |
> | aa  | *aa* |
> | aaa | aaa  |

#+BEGIN_SRC emacs-lisp :results silent
  (defun format-cell (cell row col)
    (if (<= (length cell) col)
        (concat "*" cell "*")
      cell))
#+END_SRC

| *a* | *a*  |
| aa  | *aa* |
| aaa | aaa  |
#+TBLFM: @<$<..@>$> = '(format-cell @0$0 (org-table-current-dline)
(org-table-current-column))

or

#+TBLFM: @<$<..@>$> = '(format-cell @0$0 @# $#)

For explanations please see the manual.

Michael

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

end of thread, other threads:[~2014-12-28 18:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-27 16:37 changing cells in an org-mode table with Emacs lisp Tamas Papp
2014-12-28 18:38 ` Michael Brand

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