* efficient replacing – really faster compared to using the mouse?
@ 2012-08-10 15:21 Ferdinand
2012-08-10 16:00 ` Filipp Gunbin
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Ferdinand @ 2012-08-10 15:21 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Hi,
I am currently trying to get used to emacs.
Before I heavily relied on TextMate (on Mac OS).
A lot of people claim that, once you learned all the shortcuts, emacs is much faster without ever using the mouse.
I just ran into a problem where I really couldn't figure out how to do this with emacs at all.
Eventually I switched back to TextMate ...
So, probably I just am not aware of some key-combinations or there are other tricks I don't know, so I thought I just ask some emacs-professionals here on the list.
Here is the specific problem:
I have a html table with a lot of radio buttons.
These radio buttons have names (xyz + a number).
Now I have to change all the numbers in the following way:
- orignal:
----------
print("<tr>\n");
... something else ...
print("<td class='Button'> <input type='radio' name='xyz23' value='0'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz23' value='1'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz23' value='2'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz23' value='3'> </td>\n");
print("</tr>\n");
print("<tr>\n");
... something else ...
print("<td class='Button'> <input type='radio' name='xyz54' value='0'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz54' value='1'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz54' value='2'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz54' value='3'> </td>\n");
print("</tr>\n");
[....]
edited:
-------
print("<tr>\n");
... something else ...
print("<td class='Button'> <input type='radio' name='xyz1' value='0'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz1' value='1'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz1' value='2'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz1' value='3'> </td>\n");
print("</tr>\n");
print("<tr>\n");
... something else ...
print("<td class='Button'> <input type='radio' name='xyz2' value='0'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz2' value='1'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz2' value='2'> </td>\n");
print("<td class='Button'> <input type='radio' name='xyz2' value='3'> </td>\n");
print("</tr>\n");
[and so on]
Now in TextMate I just switch to column-mode with my mouse (by pressing alt while selecting).
Then I draw a rectangle with the mouse to select the number behind xyz of one <tr>-block and type in the right number.
This is fairly easy to me and quite quick.
In emacs I just have no idea how to do this in a reasonable amount of time.
Only to navigate to the next block with C-n / C-p and to get to the right place in the line with C-b / C-f takes a lot of time.
And then to mark the beginning (with C-space) navigate to the end to replace it ...
That is much less efficient compared to using the mouse (in my opinion).
So what am I doing wrong here?
How do you solve such edits in emacs efficiently?
Thanks for any suggestions!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
@ 2012-08-10 15:40 ` Carson Chittom
2012-08-10 16:46 ` Raffaele Ricciardi
` (3 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Carson Chittom @ 2012-08-10 15:40 UTC (permalink / raw)
To: help-gnu-emacs
Ferdinand <Ferdinand.Gruebler@gmx.de> writes:
> So what am I doing wrong here?
> How do you solve such edits in emacs efficiently?
If I'm reading you correctly, I think M-% will do what you want. Or if
you're not running Emacs in a terminal, you can use a mouse:
Edit->Replace->Replace String.
But that seems a little simple. Perhaps I misunderstood?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
2012-08-10 15:21 efficient replacing – really faster compared to using the mouse? Ferdinand
@ 2012-08-10 16:00 ` Filipp Gunbin
2012-08-10 16:46 ` Peter Dyballa
2012-08-10 18:14 ` Aurélien Aptel
2 siblings, 0 replies; 11+ messages in thread
From: Filipp Gunbin @ 2012-08-10 16:00 UTC (permalink / raw)
To: Ferdinand; +Cc: help-gnu-emacs
Ferdinand <Ferdinand.Gruebler@gmx.de> writes:
> In emacs I just have no idea how to do this in a reasonable amount of time.
> Only to navigate to the next block with C-n / C-p and to get to the
> right place in the line with C-b / C-f takes a lot of time.
You could use incremental search (C-s and C-r) to jump faster, but this
still would be inefficient, of course.
> So what am I doing wrong here?
> How do you solve such edits in emacs efficiently?
You can do M-x query-replace-regexp (bound to C-M-%).
Type in the regexp when asked: "xyz[[:digit:]]+" (without quotes) and
the replacement: "xyz1".
Then continuously press <SPC> until you get to another section. At this
time press "e", edit the replacement string to xyz2 and begin pressing
<SPC> again.
Refer to "(emacs) Query Replace" info node for more information.
You could also record a macros which is a very natural way in Emacs to
perform complex repetitive editing. Read more about that in the manual.
Editing via a keyboard only is really faster!
--
Filipp Gunbin
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
2012-08-10 15:21 efficient replacing – really faster compared to using the mouse? Ferdinand
2012-08-10 16:00 ` Filipp Gunbin
@ 2012-08-10 16:46 ` Peter Dyballa
2012-08-10 18:14 ` Aurélien Aptel
2 siblings, 0 replies; 11+ messages in thread
From: Peter Dyballa @ 2012-08-10 16:46 UTC (permalink / raw)
To: Ferdinand; +Cc: help-gnu-emacs@gnu.org
Am 10.08.2012 um 17:21 schrieb Ferdinand:
> Now in TextMate I just switch to column-mode with my mouse (by pressing alt while selecting).
Something similar exists in GNU Emacs: working with rectangles. Try C-h i m emac RET m rect RET.
The commands you need are C-SPACE to mark a region, C-x r k to kill a rectangle, C-x r t <TEXT> RET to insert new text instead of the old.
--
Greetings
Pete
These are my principles and if you don't like them... well, I have others.
- Groucho Marx
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
2012-08-10 15:40 ` Carson Chittom
@ 2012-08-10 16:46 ` Raffaele Ricciardi
2012-08-10 16:47 ` Ralf Fassel
` (2 subsequent siblings)
4 siblings, 0 replies; 11+ messages in thread
From: Raffaele Ricciardi @ 2012-08-10 16:46 UTC (permalink / raw)
To: help-gnu-emacs
When editing with the keyboard, you move around with incremental search.
Emacs
allows to select and edit rectangles with the keyboard as well. Read
the GNU
Emacs Manual for how to accomplish both tasks.
In your case, one may have chosen as well to use a replacing command.
If you are curious about the fastest way to edit code in general, then
have a
look at Vim (remapping the Esc key will be the only glitch). Emacs is more
flexible, but it's more of an editor for either text documents or
programming
languages for which it has dedicated packages. Albeit it can be tweaked
to be as
efficient as you want in any context, but then such a task is beyond the
novice
user.
Neither editor caters to the casual user. If you wish to use them
efficiently,
you'll have to commit yourself to read the manuals thoroughly and think
about
how commands may be composed, and how you can apply such commands in your
everyday editing. Otherwise, fellows who use "more user-friendly"
editors will
eat in your plate and laugh in your face.
Happy editing, mate ;-)
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
2012-08-10 15:40 ` Carson Chittom
2012-08-10 16:46 ` Raffaele Ricciardi
@ 2012-08-10 16:47 ` Ralf Fassel
2012-08-10 18:44 ` B. T. Raven
2012-08-11 3:50 ` rusi
4 siblings, 0 replies; 11+ messages in thread
From: Ralf Fassel @ 2012-08-10 16:47 UTC (permalink / raw)
To: help-gnu-emacs
* Ferdinand <Ferdinand.Gruebler@gmx.de>
| [change "name='xyz23'" to "name='xyz1'" in multiple lines]
| In emacs I just have no idea how to do this in a reasonable amount of time.
See
replace-rectangle
for the direct equivalent, though the optical feedback might be
different. (I don't know whether emacs supports marking a rectangular
block different than the region in the meantime).
'replace-regexp-region' also does the trick if the replacements are
constant like in your case.
R'
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
2012-08-10 15:21 efficient replacing – really faster compared to using the mouse? Ferdinand
2012-08-10 16:00 ` Filipp Gunbin
2012-08-10 16:46 ` Peter Dyballa
@ 2012-08-10 18:14 ` Aurélien Aptel
2 siblings, 0 replies; 11+ messages in thread
From: Aurélien Aptel @ 2012-08-10 18:14 UTC (permalink / raw)
To: Ferdinand; +Cc: help-gnu-emacs@gnu.org
On Fri, Aug 10, 2012 at 5:21 PM, Ferdinand <Ferdinand.Gruebler@gmx.de> wrote:
> Now in TextMate I just switch to column-mode with my mouse (by pressing alt while selecting).
> Then I draw a rectangle with the mouse to select the number behind xyz of one <tr>-block and type in the right number.
> This is fairly easy to me and quite quick.
There is a very similar thing in emacs which has not been mentionned
yet: cua-selection
You have to enable it first in your .emacs or via M-x
cua-selection-mode. Then, the default keybinding is C-RET. It will let
you make rectangle selection with visual feedback, etc. Look at the
help message in the minibuffer while using it.
That being said, I think I would simply replace xyz25 with xyz42 using
M-%. If you select (mark) a region before, the search&replace will
only look in the marked text.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
` (2 preceding siblings ...)
2012-08-10 16:47 ` Ralf Fassel
@ 2012-08-10 18:44 ` B. T. Raven
2012-08-11 3:50 ` rusi
4 siblings, 0 replies; 11+ messages in thread
From: B. T. Raven @ 2012-08-10 18:44 UTC (permalink / raw)
To: help-gnu-emacs
Die Fri Aug 10 2012 10:21:48 GMT-0500 (Central Daylight Time) Ferdinand
<Ferdinand.Gruebler@gmx.de> scripsit:
> Hi,
>
> I am currently trying to get used to emacs.
> Before I heavily relied on TextMate (on Mac OS).
>
> A lot of people claim that, once you learned all the shortcuts, emacs is much faster without ever using the mouse.
>
>
> I just ran into a problem where I really couldn't figure out how to do this with emacs at all.
> Eventually I switched back to TextMate ...
>
>
> So, probably I just am not aware of some key-combinations or there are other tricks I don't know, so I thought I just ask some emacs-professionals here on the list.
>
>
> Here is the specific problem:
>
> I have a html table with a lot of radio buttons.
> These radio buttons have names (xyz + a number).
> Now I have to change all the numbers in the following way:
>
>
> - orignal:
> ----------
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz23' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='3'> </td>\n");
>
> print("</tr>\n");
>
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz54' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='3'> </td>\n");
>
> print("</tr>\n");
>
> [....]
>
>
>
> edited:
> -------
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz1' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='3'> </td>\n");
>
> print("</tr>\n");
>
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz2' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='3'> </td>\n");
>
> print("</tr>\n");
>
> [and so on]
>
>
>
> Now in TextMate I just switch to column-mode with my mouse (by pressing alt while selecting).
> Then I draw a rectangle with the mouse to select the number behind xyz of one <tr>-block and type in the right number.
> This is fairly easy to me and quite quick.
>
> In emacs I just have no idea how to do this in a reasonable amount of time.
> Only to navigate to the next block with C-n / C-p and to get to the right place in the line with C-b / C-f takes a lot of time.
> And then to mark the beginning (with C-space) navigate to the end to replace it ...
>
> That is much less efficient compared to using the mouse (in my opinion).
>
>
> So what am I doing wrong here?
> How do you solve such edits in emacs efficiently?
>
>
> Thanks for any suggestions!
It depends on what you mean by a lot of radio buttons, 20 or 20000? In
your specific example it seems to me that M-% z23 z1 ent spc spc spc
spc, and likewise with the rest of names would accomplish your task as
fast in Emacs as in textmate and would even work if columns are not
aligned. An elisp programmer could probably write a short routine using
regular expressions and some kind of counter to rename 20000 blocks of 4
names ending in xyz##### into xyz%%%% where numbers ##### are not in
order and %%%% are forced to be sequential.
Ed
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
` (3 preceding siblings ...)
2012-08-10 18:44 ` B. T. Raven
@ 2012-08-11 3:50 ` rusi
2012-08-11 11:55 ` Ferdinand
4 siblings, 1 reply; 11+ messages in thread
From: rusi @ 2012-08-11 3:50 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 10, 8:21 pm, Ferdinand <Ferdinand.Grueb...@gmx.de> wrote:
> Here is the specific problem:
>
> I have a html table with a lot of radio buttons.
> These radio buttons have names (xyz + a number).
> Now I have to change all the numbers in the following way:
>
> - orignal:
> ----------
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz23' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz23' value='3'> </td>\n");
>
> print("</tr>\n");
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz54' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz54' value='3'> </td>\n");
>
> print("</tr>\n");
>
> [....]
>
> edited:
> -------
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz1' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz1' value='3'> </td>\n");
>
> print("</tr>\n");
>
> print("<tr>\n");
>
> ... something else ...
>
> print("<td class='Button'> <input type='radio' name='xyz2' value='0'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='1'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='2'> </td>\n");
> print("<td class='Button'> <input type='radio' name='xyz2' value='3'> </td>\n");
>
> print("</tr>\n");
Seen this?
http://vimeo.com/1168225
One or two caveats
1. Its badly documented (That video is the best document I know for
this)
2. You need cua mode for that. Turning on cua in .emacs is however
overkill for this. Just turn it on with M-x and when done turn it off
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
2012-08-11 3:50 ` rusi
@ 2012-08-11 11:55 ` Ferdinand
2012-08-11 13:13 ` Filipp Gunbin
0 siblings, 1 reply; 11+ messages in thread
From: Ferdinand @ 2012-08-11 11:55 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
>
> On Aug 10, 8:21 pm, Ferdinand <Ferdinand.Grueb...@gmx.de> wrote:
>> Here is the specific problem:
>>
>> I have a html table with a lot of radio buttons.
>> These radio buttons have names (xyz + a number).
>> Now I have to change all the numbers in the following way:
>>
>> - orignal:
>> ----------
>>
>> print("<tr>\n");
>>
>> ... something else ...
>>
>> print("<td class='Button'> <input type='radio' name='xyz23' value='0'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz23' value='1'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz23' value='2'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz23' value='3'> </td>\n");
>>
>> print("</tr>\n");
>>
>> print("<tr>\n");
>>
>> ... something else ...
>>
>> print("<td class='Button'> <input type='radio' name='xyz54' value='0'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz54' value='1'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz54' value='2'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz54' value='3'> </td>\n");
>>
>> print("</tr>\n");
>>
>> [....]
>>
>> edited:
>> -------
>>
>> print("<tr>\n");
>>
>> ... something else ...
>>
>> print("<td class='Button'> <input type='radio' name='xyz1' value='0'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz1' value='1'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz1' value='2'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz1' value='3'> </td>\n");
>>
>> print("</tr>\n");
>>
>> print("<tr>\n");
>>
>> ... something else ...
>>
>> print("<td class='Button'> <input type='radio' name='xyz2' value='0'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz2' value='1'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz2' value='2'> </td>\n");
>> print("<td class='Button'> <input type='radio' name='xyz2' value='3'> </td>\n");
>>
>> print("</tr>\n");
>
Thanks for all the feedback!
Probably, I just have to get used to the replace and search-shortcuts.
I will try it again in emacs and will see how it works out.
What would be perfect in this particular case, would be a search-function that lets me edit the replacement-string after each occurrence.
You would search for xyz, toggle through all the occurrences and for each occurrence you can type in an individual replacement string.
(like M-% xyz ent 1 spc 1 spc 1 spc 2 spc 2 spc 2 spc 2 …..)
Is there something like this?
thanks again!
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: efficient replacing – really faster compared to using the mouse?
2012-08-11 13:13 ` Filipp Gunbin
@ 2012-08-12 2:49 ` Eric Abrahamsen
0 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2012-08-12 2:49 UTC (permalink / raw)
To: help-gnu-emacs
On Sat, Aug 11 2012, Filipp Gunbin wrote:
>> What would be perfect in this particular case, would be a search-function that lets me edit the replacement-string after each occurrence.
>>
>> You would search for xyz, toggle through all the occurrences and for each occurrence you can type in an individual replacement string.
>>
>> (like M-% xyz ent 1 spc 1 spc 1 spc 2 spc 2 spc 2 spc 2 …..)
>>
>>
>> Is there something like this?
>
> That's exactly the thing I wrote about in
> http://lists.gnu.org/archive/html/help-gnu-emacs/2012-08/msg00149.html. Emacs
> saves the last replacement so you only have to change it at the
> beginning of the section.
One more (!) option, is to use a keyboard macro to do this. When
recording, delete the string you want to replace, then hit `C-u C-x q',
which will query you for the new string. `C-M-c' to tell it you're done.
Now every time you run the macro, it will stop at the same place and ask
you for a new string. I guess functionally no different from Filipp's
solution, but a good thing to know about.
See (emacs) Keyboard Macro Query
--
GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.11)
of 2012-08-06 on pellet
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-08-12 2:49 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-10 15:21 efficient replacing – really faster compared to using the mouse? Ferdinand
2012-08-10 16:00 ` Filipp Gunbin
2012-08-10 16:46 ` Peter Dyballa
2012-08-10 18:14 ` Aurélien Aptel
[not found] <mailman.6706.1344612116.855.help-gnu-emacs@gnu.org>
2012-08-10 15:40 ` Carson Chittom
2012-08-10 16:46 ` Raffaele Ricciardi
2012-08-10 16:47 ` Ralf Fassel
2012-08-10 18:44 ` B. T. Raven
2012-08-11 3:50 ` rusi
2012-08-11 11:55 ` Ferdinand
2012-08-11 13:13 ` Filipp Gunbin
2012-08-12 2:49 ` Eric Abrahamsen
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).