execute function in replace-regexp

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

execute function in replace-regexp

Emanuel Berg-4
How can I execute a Lisp function, namely
`downcase', on the match from `replace-regexp'?

I Googled it and found [1] the syntax

    \, (downcase \1)

but doesn't get executed, just replaced as is.

[1] https://emacs.stackexchange.com/questions/26492/how-do-i-lowercase-downcase-a-group-with-replace-regexp

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Tomas Zerolo
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Oct 01, 2017 at 05:22:28AM +0200, Emanuel Berg wrote:
> How can I execute a Lisp function, namely
> `downcase', on the match from `replace-regexp'?
>
> I Googled it and found [1] the syntax
>
>     \, (downcase \1)
>
> but doesn't get executed, just replaced as is.

 - There should be no space between the comma and the paren:
   \,(...)

 - I *think* you should string-quote the \1 (the \1 itself gets,
   AFAIR, replaced literally: to have correct elisp you need
   quotes, but I might be wrong on that)

This would make:

     \,(downcase "\1")

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlnQn1QACgkQBcgs9XrR2kaiNwCfbH21XW7lqm1mSOGmk1xpnI74
0hEAniA4jqwA5Vi/YvKyYnwwbCUECzzZ
=cfqz
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Emanuel Berg-4
t wrote:

>  - There should be no space between the comma
> and the paren: \,(...)
>
>  - I *think* you should string-quote the \1
> (the \1 itself gets, AFAIR, replaced
> literally: to have correct elisp you need
> quotes, but I might be wrong on that)
>
> This would make:
>
>      \,(downcase "\1")

Did you get it to work? I did :)

(progn
  (push 13 unread-command-events)
  (dolist (c (reverse (string-to-list "\\,(downcase \\1)")))
    (push c unread-command-events))
  (push 13 unread-command-events)
  (dolist (c (reverse (string-to-list "\\(DOWNCASE ME\\)")))
    (push c unread-command-events))
  (call-interactively #'replace-regexp))
                                     ;; ^ eval here
;; DOWNCASE ME

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Tomas Zerolo
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Oct 01, 2017 at 10:44:23AM +0200, Emanuel Berg wrote:

> t wrote:
>
> >  - There should be no space between the comma
> > and the paren: \,(...)
> >
> >  - I *think* you should string-quote the \1
> > (the \1 itself gets, AFAIR, replaced
> > literally: to have correct elisp you need
> > quotes, but I might be wrong on that)
> >
> > This would make:
> >
> >      \,(downcase "\1")
>
> Did you get it to work? I did :)

Well, I admit I did a cursory test before spamming the list, yes :-)

> (progn
  [...]

Hmmm...

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlnQrBwACgkQBcgs9XrR2kYJ0wCeLdDUIB0QFHdM31jeNWFpWHZE
4FgAninL8sw78P+SNrunG2tFiOb5jeMK
=ikcK
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Marcin Borkowski-3
In reply to this post by Emanuel Berg-4

On 2017-10-01, at 05:22, Emanuel Berg <[hidden email]> wrote:

> How can I execute a Lisp function, namely
> `downcase', on the match from `replace-regexp'?
>
> I Googled it and found [1] the syntax
>
>     \, (downcase \1)
>
> but doesn't get executed, just replaced as is.
>
> [1] https://emacs.stackexchange.com/questions/26492/how-do-i-lowercase-downcase-a-group-with-replace-regexp

BTW, did you see this:
http://mbork.pl/2013-09-18_Selective_replacement_in_LaTeX_documents_(en)
and this:
https://www.masteringemacs.org/article/evaluating-lisp-forms-regular-expressions
?

Hth,

--
Marcin Borkowski

Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Emanuel Berg-4
Marcin Borkowski wrote:

> BTW, did you see this:
> http://mbork.pl/2013-09-18_Selective_replacement_in_LaTeX_documents_(en)
> and this:
> https://www.masteringemacs.org/article/evaluating-lisp-forms-regular-expressions
> ?

Man, that's like reading a Stanislaw Lem novel!

Do you have a coupla' lines of Lisp to convey
the idea?

--
underground experts united
http://user.it.uu.se/~embe8573


Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Marcin Borkowski-3

On 2017-10-01, at 22:26, Emanuel Berg <[hidden email]> wrote:

> Marcin Borkowski wrote:
>
>> BTW, did you see this:
>> http://mbork.pl/2013-09-18_Selective_replacement_in_LaTeX_documents_(en)
>> and this:
>> https://www.masteringemacs.org/article/evaluating-lisp-forms-regular-expressions
>> ?
>
> Man, that's like reading a Stanislaw Lem novel!

This is pure flattering.  (Even though Lem was soooo mistaken most of
the time, he was still a great writer.)

> Do you have a coupla' lines of Lisp to convey
> the idea?

Embedded in that post of mine, also in Mickey's one.

Best,

--
Marcin Borkowski

Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Tomas Zerolo
In reply to this post by Marcin Borkowski-3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Oct 01, 2017 at 08:41:50PM +0200, Marcin Borkowski wrote:
[...]

> BTW, did you see this:
> http://mbork.pl/2013-09-18_Selective_replacement_in_LaTeX_documents_(en)
> and this:
> https://www.masteringemacs.org/article/evaluating-lisp-forms-regular-expressions
> ?

Nifty, thanks :-)
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlnR5gsACgkQBcgs9XrR2kYrtgCfWXLj9YG/RFhdaXR0xM0BFR7D
iCkAn1VjZPi7mGY+loSX6O+py3qYAL6i
=oGNo
-----END PGP SIGNATURE-----

Reply | Threaded
Open this post in threaded view
|

Re: execute function in replace-regexp

Emanuel Berg-4
In reply to this post by Marcin Borkowski-3
Marcin Borkowski wrote:

>> Do you have a coupla' lines of Lisp to
>> convey the idea?
>
> Embedded in that post of mine, also in
> Mickey's one.

Why not embed it here as well?

--
underground experts united
http://user.it.uu.se/~embe8573