[comp.emacs] Elisp challenges: narrowing without hiding, display unlike buffer

mernst@THEORY.LCS.MIT.EDU (Michael Ernst) (06/04/91)

I am toying with the idea of writing a simple database in Emacs Lisp.  Has
anyone else implemented something that I could use, build upon, or learn
from?  (I know about db-mode, rolo, rolo-2, form-mode, and forms-mode; the
latter comes closest, but none of these solve the following problems.)

The most challenging part of such a project seems to be the front end.
There are two problems which have me puzzled; I'm especially eager to see
the first solved.


1)  How can I restrict changes to a certain rectangle or region of the window?

This would be something like narrow-to-region, but more than the modifiable
text would be visible.  I'd like to have a buffer that looks something like

	Fieldname-1:  Value of field 1, which may be long.  It
		      might even span more than one line.
	Another-fieldname:  22		Fieldname-3:  Field Three
	Final-fieldname:  Data

then permit the user to edit (only) the values; permitting editing of only
one value at a time would be good enough for me.

An ugly solution would involve remembering the modifiable region or
rectangle and rebinding every key so that its behavior did not extend
outside that area.


2) How can I make a buffer's display different than the buffer itself?

The window could show formatted data (say, rearranged and with fieldnames)
but the buffer itself would hold the unformatted data.  The straightforward
way to do this involves two buffers, one containing the unformatted data
and the other, not associated with any file, containing the formatted data;
the user is intended to interact only with the formatted one, and
keystrokes to it change both buffers.  This solution isn't so horrible, but
I'd like to have only a single buffer so that the usual save-file will work
and so that there isn't any unformatted buffer sitting around for a user to
munge, accidentally or not.


Any help with these problems will be much appreciated.

					-Michael Ernst
					 mernst@theory.lcs.mit.edu

aks%anywhere@hub.ucsb.edu (Alan Stebbens) (06/05/91)

> I am toying with the idea of writing a simple database [...]  The most
> challenging part of such a project seems to be the front end. 
> 
> 1) How can I restrict changes to a certain rectangle or region of the
> window?

> An ugly solution would involve remembering the modifiable region or
> rectangle and rebinding every key so that its behavior did not extend
> outside that area.

Why is this ugly?  Each key can be rebound to a common function which
checks the location of the cursor, and if in an editable field, does
"self-insert-character", otherwise does nothing or an error.

> 2) How can I make a buffer's display different than the buffer itself?

What's wrong with another buffer, which is marked readonly (thereby
avoiding accidental "munging", as you say), which contains the
"display", which is the buffer being viewed.  The characters you type
cause the hidden, associated buffer containing the raw data to be
modified, as well as updates to the "display" buffer, which are the
results you see.  When you "save" the display buffer, it would be the
associated raw data buffer which would actually be saved.

The "forms" mode is not a bad start; it just needs more work to be a
"real" database GUI.  Perhaps, the fable "Version 19" will have features
to help with this.

Alan