all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* execute function in replace-regexp
@ 2017-10-01  3:22 Emanuel Berg
  2017-10-01  7:55 ` tomas
  2017-10-01 18:41 ` Marcin Borkowski
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2017-10-01  3:22 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01  3:22 execute function in replace-regexp Emanuel Berg
@ 2017-10-01  7:55 ` tomas
  2017-10-01  8:44   ` Emanuel Berg
  2017-10-01 18:41 ` Marcin Borkowski
  1 sibling, 1 reply; 9+ messages in thread
From: tomas @ 2017-10-01  7:55 UTC (permalink / raw)
  To: help-gnu-emacs

-----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-----



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01  7:55 ` tomas
@ 2017-10-01  8:44   ` Emanuel Berg
  2017-10-01  8:49     ` tomas
  0 siblings, 1 reply; 9+ messages in thread
From: Emanuel Berg @ 2017-10-01  8:44 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01  8:44   ` Emanuel Berg
@ 2017-10-01  8:49     ` tomas
  0 siblings, 0 replies; 9+ messages in thread
From: tomas @ 2017-10-01  8:49 UTC (permalink / raw)
  To: help-gnu-emacs

-----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-----



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01  3:22 execute function in replace-regexp Emanuel Berg
  2017-10-01  7:55 ` tomas
@ 2017-10-01 18:41 ` Marcin Borkowski
  2017-10-01 20:26   ` Emanuel Berg
  2017-10-02  7:08   ` tomas
  1 sibling, 2 replies; 9+ messages in thread
From: Marcin Borkowski @ 2017-10-01 18:41 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


On 2017-10-01, at 05:22, Emanuel Berg <moasen@zoho.com> 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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01 18:41 ` Marcin Borkowski
@ 2017-10-01 20:26   ` Emanuel Berg
  2017-10-02  4:49     ` Marcin Borkowski
  2017-10-02  7:08   ` tomas
  1 sibling, 1 reply; 9+ messages in thread
From: Emanuel Berg @ 2017-10-01 20:26 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01 20:26   ` Emanuel Berg
@ 2017-10-02  4:49     ` Marcin Borkowski
  2017-10-02  8:11       ` Emanuel Berg
  0 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2017-10-02  4:49 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs


On 2017-10-01, at 22:26, Emanuel Berg <moasen@zoho.com> 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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-01 18:41 ` Marcin Borkowski
  2017-10-01 20:26   ` Emanuel Berg
@ 2017-10-02  7:08   ` tomas
  1 sibling, 0 replies; 9+ messages in thread
From: tomas @ 2017-10-02  7:08 UTC (permalink / raw)
  To: help-gnu-emacs

-----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-----



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: execute function in replace-regexp
  2017-10-02  4:49     ` Marcin Borkowski
@ 2017-10-02  8:11       ` Emanuel Berg
  0 siblings, 0 replies; 9+ messages in thread
From: Emanuel Berg @ 2017-10-02  8:11 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-10-02  8:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-01  3:22 execute function in replace-regexp Emanuel Berg
2017-10-01  7:55 ` tomas
2017-10-01  8:44   ` Emanuel Berg
2017-10-01  8:49     ` tomas
2017-10-01 18:41 ` Marcin Borkowski
2017-10-01 20:26   ` Emanuel Berg
2017-10-02  4:49     ` Marcin Borkowski
2017-10-02  8:11       ` Emanuel Berg
2017-10-02  7:08   ` tomas

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.