* Bug Report -- replace-regexp-in-string from subr.el
@ 2014-04-19 23:50 Sam Fiechter
2014-04-20 6:40 ` Andreas Schwab
0 siblings, 1 reply; 3+ messages in thread
From: Sam Fiechter @ 2014-04-19 23:50 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 938 bytes --]
Hi,
I noticed that the lisp function replace-regexp-in-string from emacs
24.4.50.1 does not pass the sub-expression match when the rep is a function
call rather than a string.
For Example:
(progn
(defun samscat (s)
(concat "[" s "]"))
(replace-regexp-in-string "\\(foo\\).*\\'" 'samscat " foo foo" nil nil 1))
returns:
" [foo foo] foo"
not:
" [foo] foo"
looking at the code, I notice that the sub-expression is hard-coded on line
3642 of subr.el.gz:
(funcall rep (match-string 0 str)))
rather than:
(funcall rep (match-string (or subexp 0) str)))
I hope this is helpful!
Here's my about emacs screen:
This is GNU Emacs, one component of the GNU/Linux operating system.
GNU Emacs 24.4.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10)
of 2014-03-30 on lenovo-laptop
Copyright (C) 2014 Free Software Foundation, Inc.
If you would like any other info please let me know.
Best,
Sam
--
Sam Fiechter
(302) 689-3798
[-- Attachment #2: Type: text/html, Size: 1599 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug Report -- replace-regexp-in-string from subr.el
2014-04-19 23:50 Bug Report -- replace-regexp-in-string from subr.el Sam Fiechter
@ 2014-04-20 6:40 ` Andreas Schwab
2014-04-21 14:06 ` Davis Herring
0 siblings, 1 reply; 3+ messages in thread
From: Andreas Schwab @ 2014-04-20 6:40 UTC (permalink / raw)
To: Sam Fiechter; +Cc: emacs-devel
Sam Fiechter <sam.fiechter@gmail.com> writes:
> I noticed that the lisp function replace-regexp-in-string from emacs
> 24.4.50.1 does not pass the sub-expression match when the rep is a function
> call rather than a string.
Which matches the documentation:
REP is either a string used as the NEWTEXT arg of `replace-match' or a
function. If it is a function, it is called with the actual text of each
match, and its value is used as the replacement text. When REP is called,
the match data are the result of matching REGEXP against a substring
of STRING.
The "actual text of each match" is (match-string 0), not (match-string
subexp).
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Bug Report -- replace-regexp-in-string from subr.el
2014-04-20 6:40 ` Andreas Schwab
@ 2014-04-21 14:06 ` Davis Herring
0 siblings, 0 replies; 3+ messages in thread
From: Davis Herring @ 2014-04-21 14:06 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Sam Fiechter, emacs-devel
> REP is either a string used as the NEWTEXT arg of `replace-match' or a
> function. If it is a function, it is called with the actual text of each
> match, and its value is used as the replacement text. When REP is called,
> the match data are the result of matching REGEXP against a substring
> of STRING.
>
> The "actual text of each match" is (match-string 0), not (match-string
> subexp).
If it's not obvious, you can write (match-string 1 s) in your
replacement function to get the desired behavior.
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-21 14:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-19 23:50 Bug Report -- replace-regexp-in-string from subr.el Sam Fiechter
2014-04-20 6:40 ` Andreas Schwab
2014-04-21 14:06 ` Davis Herring
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.