Re: Editor support for refactoring with macros?



"phr" <philrand@xxxxxxxxx> writes:

Pascal Bourguignon wrote:

The first idea would be:

M-x replace-regexp RET (purchk \(.*\) "QFC" \(.*\)) RET (qfc \1 \2) RET

but indeed, since the forms are not regular expressions, this cannot
work in most cases.>

So what I do is:

(replace-sexps "source.lisp"
(lambda (sexp)
(if (eq (car sexp) 'purchk)
`(qfc (second sexp) (third sexp) "QFC" (cdddr sexp))
sexp))
:deeply t :atoms nil)

http://darcs.informatimago.com/darcs/public/emacs/pjb-sources.el
http://darcs.informatimago.com/darcs/public/emacs/

Well actually, it should work ok on emacs lisp sources, but on Common
Lisp sources, there may be some problems relative to reader macros.
I've got some code in
http://darcs.informatimago.com/darcs/public/lisp/common-lisp/source.lisp
but it's incomplete (I've not implemented most of the standard reader
macros yet).


Cool code, Pascal.

It seems to me that it ought to be possible to generate your
transformer lambda expression directly from the defmacro form, though
now that I've looked at your code, I see that's the easy part.

Do experienced Lisp programmers use transformation tools like that a
lot, or are they simply better than me at spotting the need for a macro
early? I suspect the latter. Also they seem to be much better with
emacs than me.

I must confess that I don't use it a lot. I've used it twice or
thrice to do some such transforms, (or one of the variants to search
for specific forms). Perhaps the most often use I make of this code
is in insert-generics which scans the source for DEFMETHOD forms and
inserts corresponding DEFGENERIC forms.

But not for plain "refactoring": as soon as a pattern emerge (which
may be as soon as I type twice the same thing), I usually factor it
out immediately, be it in a function or a macro depending on the
cases.


--
__Pascal Bourguignon__ http://www.informatimago.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d? s++:++ a+ C+++ UL++++ P--- L+++ E+++ W++ N+++ o-- K- w---
O- M++ V PS PE++ Y++ PGP t+ 5+ X++ R !tv b+++ DI++++ D++
G e+++ h+ r-- z?
------END GEEK CODE BLOCK------
.



Relevant Pages

  • Re: Editor support for refactoring with macros?
    ... Pascal Bourguignon wrote: ... but indeed, since the forms are not regular expressions, this cannot ... Well actually, it should work ok on emacs lisp sources, but on Common ... there may be some problems relative to reader macros. ...
    (comp.lang.lisp)
  • Re: An idea for making define-macro more convenient to use
    ... this is the major alternative to the very complicated hygiene ... in a way that is just as complex as SYNTAX-CASE (although I might be way ... macros - does every pass create a new transformer environment for the same ...
    (comp.lang.lisp)
  • Re: An idea for making define-macro more convenient to use
    ... in a way that is just as complex as SYNTAX-CASE (although I might be wayoff ... what do syntactic closures have to say about nested orrecursive ... macros - does every pass create a new transformer environment for the same ...
    (comp.lang.lisp)
  • Re: removing comment
    ... You cannot reliably detect comments using regular expressions. ... The preprocessor has no knowledge of comments, ... of macros is required or desired. ...
    (comp.lang.c)
  • Re: for a laught (???)
    ... regular expressions in editors that support them, often with macros. ...
    (comp.lang.cobol)