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

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

Re: Can el-search-query-replace replace mapcar with --map ?


From: Michael Heerdegen
Subject: Re: Can el-search-query-replace replace mapcar with --map ?
Date: Sat, 23 Dec 2017 15:03:36 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Chunyang Xu <mail@xuchunyang.me> writes:

> It works fine for my example:
>
>   (mapcar (lambda (x) (* x x)) '(1 2 3))
>
> but not
>
>   (mapcar (lambda (x) (let ((x (1+ x))) (* x x))) '(1 2 3))
>
> with the exact same patterns, 'el-search-query-replace' reports
>
>   el-search--format-replacement: Error in
>   ‘el-search--format-replacement’ - please make a bug report
>
> I guess this is excepted by you, even though
> 'transform-lambda-form-for---map' is correct for both cases:
>
>   (transform-lambda-form-for---map
>    (lambda (x) (* x x)))
>        => (* it it)
>
>   (transform-lambda-form-for---map
>    (lambda (x) (let ((x (1+ x))) (* x x))))
>        => (let ((x (1+ it))) (* x x))

It's not that simple.  If you bind print-circle and print-gensym to t,
you see that `symbol-macrolet' renames the let-bound variable x to an
uninterned symbol:

#+begin_src emacs-lisp
(transform-lambda-form-for---map '(lambda (x) (let ((x (1+ x))) (* x x))))
==>
(let
    ((#1=#:x
      (1+ it)))
  (* #1# #1#))
#+end_src

The current version of el-search doesn't yet allow uninterned symbols in
the replacement.  The result is not what you want in your case anyway.
As I said - making every case work correctly would need something more
complicated than what I had suggested.

> By the way, is there a way to tidy the code after
> 'el-search-query-replace' ? For the same example above, it produces
>
>   (--map
>    (* it it)
>    '(1 2 3))
>
> but I want
>
>   (--map (* it it) '(1 2 3))
>
> right now I have to do it manually via M-^ ('delete-indentation'), which
> is not very convenient.

I know about that problem, but currently, you must do it manually.
el-search currently use "pp.el" to format the replacement.  It is not
very sophisticated, I want to replace it with something better in the
future.  Nobody has written a nicer printer yet.  Printing an expression
that is lisp code in a way that is appealing to humans is a challenge of
its own.


Regards,

Michael.



reply via email to

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