* query-replace-regexp on a string with '=' sign @ 2022-09-08 8:10 Pankaj Jangid 2022-09-08 9:53 ` Emanuel Berg 2022-09-08 10:49 ` Tassilo Horn 0 siblings, 2 replies; 13+ messages in thread From: Pankaj Jangid @ 2022-09-08 8:10 UTC (permalink / raw) To: Emacs Help I have a line like this, HELLO=WORLD now I want to downcase the part before the equal (=) sign. I am approaching like this M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET But this doesn't work. It works if the equal sign is replaced with another non-special ASCII character. Where am I wrong? ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-08 8:10 query-replace-regexp on a string with '=' sign Pankaj Jangid @ 2022-09-08 9:53 ` Emanuel Berg 2022-09-16 15:15 ` [External] : " Drew Adams 2022-09-08 10:49 ` Tassilo Horn 1 sibling, 1 reply; 13+ messages in thread From: Emanuel Berg @ 2022-09-08 9:53 UTC (permalink / raw) To: help-gnu-emacs Pankaj Jangid wrote: > I have a line like this, > > HELLO=WORLD > > now I want to downcase the part before the equal (=) sign. (while (re-search-forward "\\(.+\\)\\(=\\)" nil t) (replace-match (concat (downcase (match-string-no-properties 1)) (match-string-no-properties 2) ) t)) ;; We= ;; Are= ;; Robots= -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 13+ messages in thread
* RE: [External] : Re: query-replace-regexp on a string with '=' sign 2022-09-08 9:53 ` Emanuel Berg @ 2022-09-16 15:15 ` Drew Adams 2022-09-18 15:24 ` Emanuel Berg 0 siblings, 1 reply; 13+ messages in thread From: Drew Adams @ 2022-09-16 15:15 UTC (permalink / raw) To: Emanuel Berg, help-gnu-emacs@gnu.org > > HELLO=WORLD > > I want to downcase the part before the equal (=) sign. > > (while (re-search-forward "\\(.+\\)\\(=\\)" nil t)... In most cases you don't want the first group to match any `=' chars, in which case it should be something like \([^=]+\). ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [External] : Re: query-replace-regexp on a string with '=' sign 2022-09-16 15:15 ` [External] : " Drew Adams @ 2022-09-18 15:24 ` Emanuel Berg 0 siblings, 0 replies; 13+ messages in thread From: Emanuel Berg @ 2022-09-18 15:24 UTC (permalink / raw) To: help-gnu-emacs Drew Adams wrote: >>> HELLO=WORLD >>> I want to downcase the part before the equal (=) sign. >> >> (while (re-search-forward "\\(.+\\)\\(=\\)" nil t)... > > In most cases you don't want the first group to match any > `=' chars, in which case it should be something like > \([^=]+\). I don't know why mine works, why not everything including the equals sign _and_ the part after that ends up in the first group? But it does work, while replacing the RE with "\\([^=]+\\)\\(=\\)" doesn't, it downcases the whole thing. Here, try it yourself: (while (re-search-forward "\\(.+\\)\\(=\\)" nil t) (replace-match (concat (downcase (match-string-no-properties 1)) (match-string-no-properties 2) ) t)) ;; We=WE ;; Are=ARE ;; Robots=ROBOTS -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-08 8:10 query-replace-regexp on a string with '=' sign Pankaj Jangid 2022-09-08 9:53 ` Emanuel Berg @ 2022-09-08 10:49 ` Tassilo Horn 2022-09-08 11:16 ` Emanuel Berg 2022-09-09 4:11 ` Pankaj Jangid 1 sibling, 2 replies; 13+ messages in thread From: Tassilo Horn @ 2022-09-08 10:49 UTC (permalink / raw) To: Pankaj Jangid; +Cc: help-gnu-emacs Pankaj Jangid <pankaj@codeisgreat.org> writes: > I have a line like this, > HELLO=WORLD > now I want to downcase the part before the equal (=) sign. > I am approaching like this > > M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET > > But this doesn't work. Where "doesn't work" means "doesn't downcase but keeps HELLO", right? Have a look at (info "(emacs) Replacement and Lax Matches") which explains it. I think the default `case-replace' value of t is the problem here. That said, `case-replace' is actually a nice feature. It's just that with an explicit `downcase' it's very counter-intuitive. I'd suggest to report that as a bug. What you can do is instead of saying 'y' when asked to replace the current occurrence do 'E RET' instead. > It works if the equal sign is replaced with another non-special ASCII > character. I don't understand what you mean here. When I change the = in the replacement to, say, the letter t, HELLO= gets replaced with HELLOT which is the same behavior as above... Bye, Tassilo ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-08 10:49 ` Tassilo Horn @ 2022-09-08 11:16 ` Emanuel Berg 2022-09-09 4:11 ` Pankaj Jangid 1 sibling, 0 replies; 13+ messages in thread From: Emanuel Berg @ 2022-09-08 11:16 UTC (permalink / raw) To: help-gnu-emacs Tassilo Horn wrote: > That said, `case-replace' is actually a nice feature. > It's just that with an explicit `downcase' it's very > counter-intuitive. I'd suggest to report that as a bug. Yeah, but does it work like that, explicit or not, isn't it just an arbitrary function, namely `downcase'? -- underground experts united https://dataswamp.org/~incal ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-08 10:49 ` Tassilo Horn 2022-09-08 11:16 ` Emanuel Berg @ 2022-09-09 4:11 ` Pankaj Jangid 2022-09-09 5:10 ` Tassilo Horn 1 sibling, 1 reply; 13+ messages in thread From: Pankaj Jangid @ 2022-09-09 4:11 UTC (permalink / raw) To: Tassilo Horn; +Cc: help-gnu-emacs Tassilo Horn <tsdh@gnu.org> writes: >> I have a line like this, >> HELLO=WORLD >> now I want to downcase the part before the equal (=) sign. >> I am approaching like this >> >> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET >> >> But this doesn't work. > > Where "doesn't work" means "doesn't downcase but keeps HELLO", right? Yes. Suppose I have these lines in a region HELLO=WORLD HELLOXXXXWORLD and if I now execute following sequence, M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET the output is, hello=WORLD HELLOXXXXWORLD but if I execute this, M-x query-replace-regexp RET \(.+\)XXXX RET \,(downcase \1)XXXX RET then the output is, HELLO=WORLD helloXXXXWORLD > Have a look at (info "(emacs) Replacement and Lax Matches") which > explains it. I think the default `case-replace' value of t is the > problem here. > Thanks for pointing me to the right direction. Understood case-replace thing. But the one thing that is still not clear to me is that, why the first command doesn't downcase HELLO in the first line, whereas the second command downcases the HELLO in the second line. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 4:11 ` Pankaj Jangid @ 2022-09-09 5:10 ` Tassilo Horn 2022-09-09 7:46 ` Pankaj Jangid 0 siblings, 1 reply; 13+ messages in thread From: Tassilo Horn @ 2022-09-09 5:10 UTC (permalink / raw) To: Pankaj Jangid; +Cc: help-gnu-emacs Pankaj Jangid <pankaj@codeisgreat.org> writes: >>> I have a line like this, >>> HELLO=WORLD >>> now I want to downcase the part before the equal (=) sign. >>> I am approaching like this >>> >>> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET >>> >>> But this doesn't work. >> >> Where "doesn't work" means "doesn't downcase but keeps HELLO", right? > > Yes. Suppose I have these lines in a region > HELLO=WORLD > HELLOXXXXWORLD > and if I now execute following sequence, > M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET > the output is, > > hello=WORLD > HELLOXXXXWORLD For me (with emacs -Q on the current master), it stays as it is, i.e., all caps. > but if I execute this, > M-x query-replace-regexp RET \(.+\)XXXX RET \,(downcase \1)XXXX RET > then the output is, > > HELLO=WORLD > helloXXXXWORLD I can reproduce that. I think that's documented on the info page I've cited. When the replacement is all lower- or all uppercase (like hello=), `case-replace' has an effect. But when the replacement is mixed-case (like helloXXXX), case will be preserved. >> Have a look at (info "(emacs) Replacement and Lax Matches") which >> explains it. I think the default `case-replace' value of t is the >> problem here. > > Thanks for pointing me to the right direction. Understood case-replace > thing. But the one thing that is still not clear to me is that, why > the first command doesn't downcase HELLO in the first line, whereas > the second command downcases the HELLO in the second line. Huh? You've said the first command does downcase hello in the first line although I cannot reproduce that and would not have an explanation for that behavior. If it's actually the same for you, then see my last paragraph for the explanation. Bye, Tassilo ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 5:10 ` Tassilo Horn @ 2022-09-09 7:46 ` Pankaj Jangid 2022-09-09 9:26 ` Tassilo Horn 0 siblings, 1 reply; 13+ messages in thread From: Pankaj Jangid @ 2022-09-09 7:46 UTC (permalink / raw) To: Tassilo Horn; +Cc: help-gnu-emacs Tassilo Horn <tsdh@gnu.org> writes: > Pankaj Jangid <pankaj@codeisgreat.org> writes: > >>>> I have a line like this, >>>> HELLO=WORLD >>>> now I want to downcase the part before the equal (=) sign. >>>> I am approaching like this >>>> >>>> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET >>>> >>>> But this doesn't work. >>> >>> Where "doesn't work" means "doesn't downcase but keeps HELLO", right? >> >> Yes. Suppose I have these lines in a region >> HELLO=WORLD >> HELLOXXXXWORLD >> and if I now execute following sequence, >> M-x query-replace-regexp RET \(.+\)= RET \,(downcase \1)= RET >> the output is, >> >> hello=WORLD >> HELLOXXXXWORLD > > For me (with emacs -Q on the current master), it stays as it is, i.e., > all caps. Oh this is my mistake. I wanted to point out that only.. It stays caps. >> but if I execute this, >> M-x query-replace-regexp RET \(.+\)XXXX RET \,(downcase \1)XXXX RET >> then the output is, >> >> HELLO=WORLD >> helloXXXXWORLD > > I can reproduce that. I think that's documented on the info page I've > cited. When the replacement is all lower- or all uppercase (like > hello=), `case-replace' has an effect. But when the replacement is > mixed-case (like helloXXXX), case will be preserved. > >>> Have a look at (info "(emacs) Replacement and Lax Matches") which >>> explains it. I think the default `case-replace' value of t is the >>> problem here. >> >> Thanks for pointing me to the right direction. Understood case-replace >> thing. But the one thing that is still not clear to me is that, why >> the first command doesn't downcase HELLO in the first line, whereas >> the second command downcases the HELLO in the second line. > > Huh? You've said the first command does downcase hello in the first > line although I cannot reproduce that and would not have an explanation > for that behavior. If it's actually the same for you, then see my last > paragraph for the explanation. Sorry for creating confusion ... again. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 7:46 ` Pankaj Jangid @ 2022-09-09 9:26 ` Tassilo Horn 2022-09-09 12:50 ` Pankaj Jangid 0 siblings, 1 reply; 13+ messages in thread From: Tassilo Horn @ 2022-09-09 9:26 UTC (permalink / raw) To: Pankaj Jangid; +Cc: help-gnu-emacs Pankaj Jangid <pankaj@codeisgreat.org> writes: >> Huh? You've said the first command does downcase hello in the first >> line although I cannot reproduce that and would not have an >> explanation for that behavior. If it's actually the same for you, >> then see my last paragraph for the explanation. > > Sorry for creating confusion ... again. No problem at all. While the behavior can be explained, I still think there should be a way to have something like "yes, replace, but don't obey case-replace", so bug report might still be appropriate. (As said, E RET does that but requires 2 keys...) Bye, Tassilo ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 9:26 ` Tassilo Horn @ 2022-09-09 12:50 ` Pankaj Jangid 2022-09-09 12:56 ` Tassilo Horn 0 siblings, 1 reply; 13+ messages in thread From: Pankaj Jangid @ 2022-09-09 12:50 UTC (permalink / raw) To: Tassilo Horn; +Cc: help-gnu-emacs Tassilo Horn <tsdh@gnu.org> writes: >> Sorry for creating confusion ... again. > > No problem at all. While the behavior can be explained, I still think > there should be a way to have something like "yes, replace, but don't > obey case-replace", so bug report might still be appropriate. (As said, > E RET does that but requires 2 keys...) E RET does the job. Yes. But there should be an intuitive way. Because asking question will also take another keystroke. ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 12:50 ` Pankaj Jangid @ 2022-09-09 12:56 ` Tassilo Horn 2022-09-10 16:05 ` Pankaj Jangid 0 siblings, 1 reply; 13+ messages in thread From: Tassilo Horn @ 2022-09-09 12:56 UTC (permalink / raw) To: Pankaj Jangid; +Cc: help-gnu-emacs Pankaj Jangid <pankaj@codeisgreat.org> writes: >> While the behavior can be explained, I still think there should be a >> way to have something like "yes, replace, but don't obey >> case-replace", so bug report might still be appropriate. (As said, E >> RET does that but requires 2 keys...) > > E RET does the job. Yes. But there should be an intuitive way. Because > asking question will also take another keystroke. That's why I'm urging you to report that as a bug. :-) Bye, Tassilo ^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: query-replace-regexp on a string with '=' sign 2022-09-09 12:56 ` Tassilo Horn @ 2022-09-10 16:05 ` Pankaj Jangid 0 siblings, 0 replies; 13+ messages in thread From: Pankaj Jangid @ 2022-09-10 16:05 UTC (permalink / raw) To: Tassilo Horn; +Cc: help-gnu-emacs Tassilo Horn <tsdh@gnu.org> writes: >> E RET does the job. Yes. But there should be an intuitive way. Because >> asking question will also take another keystroke. > > That's why I'm urging you to report that as a bug. :-) Sure will do. ^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2022-09-18 15:24 UTC | newest] Thread overview: 13+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-09-08 8:10 query-replace-regexp on a string with '=' sign Pankaj Jangid 2022-09-08 9:53 ` Emanuel Berg 2022-09-16 15:15 ` [External] : " Drew Adams 2022-09-18 15:24 ` Emanuel Berg 2022-09-08 10:49 ` Tassilo Horn 2022-09-08 11:16 ` Emanuel Berg 2022-09-09 4:11 ` Pankaj Jangid 2022-09-09 5:10 ` Tassilo Horn 2022-09-09 7:46 ` Pankaj Jangid 2022-09-09 9:26 ` Tassilo Horn 2022-09-09 12:50 ` Pankaj Jangid 2022-09-09 12:56 ` Tassilo Horn 2022-09-10 16:05 ` Pankaj Jangid
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).