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

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

Re: Emacs programming question


From: Pascal J. Bourguignon
Subject: Re: Emacs programming question
Date: Fri, 05 Oct 2012 13:57:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Evan Driscoll <driscoll@cs.wisc.edu> writes:

> Hi,
>
> I want to write an emacs mode to display a particular type of
> file. However, the way I'd like to display the file isn't the literal
> text contents in the file, but rather a (text) rendering of parts of
> the information contained within. Unfortunately, I don't know any
> modes that do something comparable; the closest ones I can think of
> are what you get if you load an image. As a postscript I've included a
> fairly wordy description of what I'm trying to do to set some context;
> It's step (2) in that description that I foresee the most problems
> with.

There are a lot of modes that don't display the literal data.

hexl-mode
forms-mode
etc


As I see it, you have two solutions:

- when you switch to your mode, you can create a new "editing" buffer,
  where the user will give commands, and those commands will update the
  file buffer.

- you can also "parse" the buffer contents and put it in some data
  structures (kept in buffer local variables), and then show in the
  buffer any view of that data you want.  Editing commands will update
  the data structure.  Saving will unparse it into a text file.


There are more variants.  The forms-mode for example, actually use the
forms file to build a meta data structure in the forms buffer, and
actually opens another data file to be edited thru the forms buffer.


> What I want is something to the effect of opening the file normally
> but then (1) saving the contents of the buffer into a lisp variable,
> (2) clearing the buffer, (3) inserting into the buffer some computed
> contents from step (1). (Fortunately, I can set the buffer to
> read-only for my purposes and I don't have to worry about user edits
> to it.)

Indeed, you would define your own commands and key bindings to edit the
data anyways.


> [… some specs …]

Indeed, you can program anything (that's computable).

emacs lisp is a general algorithmic programming language: you can write
any program with it.  As a bonus, you have a big library for text
editing and a lot of libraries for various other things.  Don't let the
libraries obscure your view that emacs lisp is just a programming
language. You have your specifications.  Write the program.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


reply via email to

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