From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: Seeking advice on writing a "line-based" major mode Date: Sun, 7 Jun 2015 19:17:06 -0700 (PDT) Message-ID: <2687fb9a-c314-4cf4-8c8a-d959e886ed14@default> References: <87wpzf9q38.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1433729863 5271 80.91.229.3 (8 Jun 2015 02:17:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Jun 2015 02:17:43 +0000 (UTC) To: Marcin Borkowski , Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 08 04:17:28 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z1mcs-00046w-Az for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Jun 2015 04:17:22 +0200 Original-Received: from localhost ([::1]:55646 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1mcr-0003DA-E4 for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Jun 2015 22:17:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1mch-0003D1-8S for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 22:17:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z1mcd-0006Rd-VE for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 22:17:11 -0400 Original-Received: from userp1040.oracle.com ([156.151.31.81]:40913) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z1mcd-0006RE-O7 for help-gnu-emacs@gnu.org; Sun, 07 Jun 2015 22:17:07 -0400 Original-Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t582H55L025001 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 8 Jun 2015 02:17:06 GMT Original-Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t582H5oY015481 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Mon, 8 Jun 2015 02:17:05 GMT Original-Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id t582H5in008931; Mon, 8 Jun 2015 02:17:05 GMT In-Reply-To: <87wpzf9q38.fsf@mbork.pl> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6691.5000 (x86)] X-Source-IP: aserv0021.oracle.com [141.146.126.233] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 156.151.31.81 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:104827 Archived-At: > 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'.