From: Michael Heerdegen <michael_heerdegen@web.de>
To: Chunyang Xu <mail@xuchunyang.me>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Can el-search-query-replace replace mapcar with --map ?
Date: Sat, 23 Dec 2017 15:03:36 +0100 [thread overview]
Message-ID: <87a7y94k3r.fsf@web.de> (raw)
In-Reply-To: <m2k1xe7ytm.fsf@xuchunyang.me> (Chunyang Xu's message of "Sat, 23 Dec 2017 14:17:25 +0800")
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.
prev parent reply other threads:[~2017-12-23 14:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-22 11:45 Can el-search-query-replace replace mapcar with --map ? Chunyang Xu
2017-12-22 17:17 ` Michael Heerdegen
2017-12-23 6:17 ` Chunyang Xu
2017-12-23 14:03 ` Michael Heerdegen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a7y94k3r.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=help-gnu-emacs@gnu.org \
--cc=mail@xuchunyang.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.