7

I'm looking for functionality that can do source-to-source transformation of elisp programs given a set of rewriting rules. For example, given a rule like:

(set (make-local-variable (quote ?var) ?value)) => 
   (setq-local ?var ?value)

It will find all occurrences of the pattern and replace it with replacement. A welcome feature would be to do minimum amount of changes.

Edit: I found this http://www.informatik.uni-bremen.de/st/lehre/Arte-fakt/Seminar/papers/06/Formal/pattern-language-for-refactoring.pdf sadly no implementation.

7

I believe you're looking for the el-search package, available in the GNU ELPA repository. It lets you match using pcase patterns and does implement the search&replace functionality that you're describing.

You'd use el-search-query-replace and provide the pattern

`(set (make-local-variable ',var) ,val)

and replace it with

`(setq-local ,var ,val)
  • This is exactly what I had in mind. Thanks. – Gracjan Polak May 9 '16 at 14:14
0

Lisp macro expansion is exactly that: a mapping from Lisp sexps to Lisp sexps. Your friends for this are defmacro or -- more especially -- macrolet (aka cl-macrolet for Emacs Lisp) and macroexpand (also macroexpand-all).

Note that I am not referring to macro expansion followed by evaluation of the resulting Lisp code, which is how Lisp macros are usually used.

In this case, you do not want to evaluate the result of macro expansion. You want only to "expand" an input Lisp sexp to produce a different Lisp sexp. (In computer science and logic this is sometimes called "reduction" or "rewriting".)

(Of course, to deal with sexps that are not lists you will need to also provide mappings between known symbols and the like. But macro expansion takes care of most sexp-pattern mappings.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.