unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Marcin Borkowski <mbork@mbork.pl>,
	Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: RE: Seeking advice on writing a "line-based" major mode
Date: Sun, 7 Jun 2015 19:17:06 -0700 (PDT)	[thread overview]
Message-ID: <2687fb9a-c314-4cf4-8c8a-d959e886ed14@default> (raw)
In-Reply-To: <87wpzf9q38.fsf@mbork.pl>

> the buffer will contain a bunch of lines, each of them
> correspoding to some object (basically, I have a vector
> of these "objects", and I want to display them in some way).

Sounds like a candidate for `tabulated-list-mode'.  You can
use that to print lines that are composed of one or more
columns, and a header line that let you sort by any column
(if you want).

> 1. I want to be able to display these objects using some kind of
> a "template" (not unlike org's "property table", or dired's format
> etc.).  I'd like this "template" to be configurable using a user
> option (with possibilities like "x characters for a name, then y
> characters for description, etc. for other fields").

That sounds like exactly what `tabulated-list.el' lets you do.
See (buffer-local) variable `tabulated-list-format'.

> 2. When the point is one one of these lines, I want various
> keybindings to perform some actions on the object in question
> (like, again, in Dired or org-agenda).

By default, RET on an entry in the table (i.e., in a given row
and column) just sorts that column.  But you can bind it to do
anything you like.

You might take a look at my library apu.el, which uses t-l-mode
this way.  The info in each row of the table is info about a
given Unicode char.  When you hit RET anywhere in that row a
buffer pops up with more complete info about that char.  Various
keys perform other actions on the given char.
http://www.emacswiki.org/emacs/apu.el (I haven't yet put it on
MELPA.)

> Is there anything in Emacs or its libraries which might help with
> these tasks?  For instance, each "object" is identified by a name
> (it's the "primary key", so to speak), but it need not be e.g.
> the first thing on the line.

Same thing with t-l-mode.

> The displaying function could use text properties of the
> particular lines so that Emacs knows which object to act
> upon when point is in some place, but maybe there is a
> ready-made library for that?

You can use text properties that way with t-l-mode, but you
should not need to.

> And maybe there is even a more general library to establish
> a correspondence between some vector/list of objects and a buffer
> whose lines contain some textual representation of these objects,
> so that I wouldn't have to code e.g. the displaying routine from
> scratch?

Again, that description sounds just like t-l-mode.

> Of course I could code all that myself - it doesn't seem to be too
> much work - but why reinvent the wheel?

Right.

[BTW, I would recommend against looking to things like Dired as
examples for this kind of thing.  Dired is very complex and does
lots of things in special ways.  And its code has evolved
organically, so to speak. ;-)  It is not something simple like what
you describe.  Look instead to things like buff-menu.el (which now
uses t-l-mode) and `list-faces-display' and `list-colors-display'.



  reply	other threads:[~2015-06-08  2:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-07 21:16 Seeking advice on writing a "line-based" major mode Marcin Borkowski
2015-06-08  2:17 ` Drew Adams [this message]
2015-06-18  8:06   ` Marcin Borkowski
2015-06-18 16:10     ` Drew Adams
2015-06-18 18:47       ` Marcin Borkowski
2015-06-18 19:50         ` Drew Adams
2015-06-18 20:44           ` Marcin Borkowski
2015-06-18 21:28             ` Drew Adams
2015-07-18 23:20           ` Marcin Borkowski
2015-07-19  0:26             ` Robert Thorpe
     [not found]     ` <mailman.5261.1434643820.904.help-gnu-emacs@gnu.org>
2015-06-18 16:23       ` Emanuel Berg
     [not found]   ` <mailman.5215.1434614824.904.help-gnu-emacs@gnu.org>
2015-06-18 15:57     ` Emanuel Berg
2015-06-18 22:01       ` Emanuel Berg
2015-06-20  1:28         ` Emanuel Berg
2015-06-08 13:37 ` Tom Tromey
2015-06-17 21:14   ` Marcin Borkowski
     [not found]   ` <mailman.5205.1434575686.904.help-gnu-emacs@gnu.org>
2015-06-18  1:50     ` Stefan Monnier
2015-06-18  7:58       ` Marcin Borkowski
     [not found] <mailman.4548.1433712325.904.help-gnu-emacs@gnu.org>
2015-06-07 22:23 ` Emanuel Berg
2015-06-07 22:48   ` Marcin Borkowski
2015-06-07 22:28 ` Emanuel Berg
2015-06-07 22:49   ` Marcin Borkowski
2015-06-08  0:09 ` Joost Kremers

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=2687fb9a-c314-4cf4-8c8a-d959e886ed14@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=mbork@mbork.pl \
    /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.
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).