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

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

RE: Seeking advice on writing a "line-based" major mode


From: Drew Adams
Subject: RE: Seeking advice on writing a "line-based" major mode
Date: Sun, 7 Jun 2015 19:17:06 -0700 (PDT)

> 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 via email to

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