all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: output data into table
Date: Tue, 27 Dec 2011 11:38:30 +0800	[thread overview]
Message-ID: <87aa6en0p5.fsf@ericabrahamsen.net> (raw)
In-Reply-To: 87y5tzw1m0.fsf@cica.brc

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	other threads:[~2011-12-27  3:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-26 19:53 output data into table Petro Khoroshyy
2011-12-27  3:38 ` Eric Abrahamsen [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87aa6en0p5.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.