[Top][All Lists]

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

Re: use Elisp to improve your Elisp - some code issues

From: Pascal J. Bourguignon
Subject: Re: use Elisp to improve your Elisp - some code issues
Date: Sun, 02 Aug 2015 18:44:06 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Robert Thorpe <address@hidden> writes:

> Emanuel Berg <address@hidden> writes:
>> "Pascal J. Bourguignon" <address@hidden>
>> writes:
>>> No.
>>> I said that if you went beyond those simple case,
>>> your regexp solution would break lamentably.
>> This is an interface to regexps so it sure doesn't go
>> anywhere beyond what can be expressed by regexps.
> I agree with Pascal & Marcin.
> Why not use the "read" function to read in the code of the file.  Then
> you have everything as a tree.  You can use car and cdr to walk the tree
> and find the relevant function calls.  Then you're in the right place in
> the Chomsky heirachy.

Careful, there's a reason why not to use read and instead to use
forward-sexp and other emacs editing function.

read will drop comments, newlines, indentation, etc.

Since most of the case, you will transform only some form or subform,
you may want to keep the rest of the source file intact.  Therefore
using primarily forward-sexp/down-list/up-list to navigate the source is
better. You may then use read-from-string+buffer-substring to transform
a sexp identified with forward-sexp, to process it, and insert+pp to
format it back into the buffer.

On the other hand, you may consider that comments have nothing to do in
source databases, and that pp is authoritative, and therefore use read
and pp to build an editor that will maintain the source database
automatically for yourself.  Then you always work at the sexp level.

It's probably to be able to work at the sexp level that docstrings were
invented, since even in LISP 1.5, comments existed (in the form of
comment cards).

__Pascal Bourguignon__       
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

reply via email to

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