help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: output data into table


From: Eric Abrahamsen
Subject: Re: output data into table
Date: Tue, 27 Dec 2011 11:38:30 +0800
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)

On Tue, Dec 27 2011, Petro Khoroshyy wrote:

> Hi all.
> I want to build a table similar to the one GNUS uses to display
> messages in a newsgroup.
> Could somebody direct me to a code example which does it?
> Thanks.
> P.S. Does anybody knows a dedicated elisp mailinglist  or newsgroup?

It's hard to know exactly what you want to see -- what's your current
difficulty? The basic pattern you want is to loop over elements in a
list (each element being a "row" in your table), and then insert each
element into the buffer, perhaps after formatting it in some way.
Looping over elements in a list is generally done either with setq,
mapcar (or mapconcat), or the loop macro in the 'cl package. Gnus does
it with setq:

(while threads
  (setq thread (car threads)
        threads (cdr threads))
  ; do something with thread here, probably ending up with insert
)

`mapcar' or `mapconcat' wants you to write a function, perhaps one
called `my-format-line', and then you call

(insert (mapconcat 'my-format-line threads "\n"))

That will call `my-format-line' once for every element of `threads',
then take all the resulting strings, put newlines between them, and
insert them into the buffer.

I'm no good at the `loop' macro, look at the documentation (not a great
place to start learning elisp!).

I'm not sure if this was what you were really asking. As you can see,
making a "table" is just a matter of inserting a series of
similarly-formatted lines in a buffer. Each line is a table row. Each
cell will be one bit of information in the line -- if you're concerned
about the cells lining up tidily, you can use the `format' function,
which gives you a way to insert a flexible space.

Hope that was useful! As always, check the docstrings for all the
above-mentioned functions.

Yours,
Eric

-- 
GNU Emacs 24.0.92.1 (i686-pc-linux-gnu, GTK+ Version 2.24.6)
 of 2011-12-07 on pellet




reply via email to

[Prev in Thread] Current Thread [Next in Thread]