* Emacs equivalent of the ":g" command in vi @ 2011-07-22 8:42 C K Kashyap 2011-07-22 9:27 ` Peter Dyballa 2011-07-22 20:27 ` MBR 0 siblings, 2 replies; 18+ messages in thread From: C K Kashyap @ 2011-07-22 8:42 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 265 bytes --] Hi, Could someone please tell me how I could go about something like this - I need to perform a certain action (such as delete the line) on each line of a buffer if the line matches a regular expression. In vim, we can use the :g command for this. Regards, Kashyap [-- Attachment #2: Type: text/html, Size: 308 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 8:42 Emacs equivalent of the ":g" command in vi C K Kashyap @ 2011-07-22 9:27 ` Peter Dyballa 2011-07-22 9:48 ` Thierry Volpiatto 2011-07-22 20:27 ` MBR 1 sibling, 1 reply; 18+ messages in thread From: Peter Dyballa @ 2011-07-22 9:27 UTC (permalink / raw) To: C K Kashyap; +Cc: help-gnu-emacs Am 22.07.2011 um 10:42 schrieb C K Kashyap: > I need to perform a certain action (such as delete the line) on each line of > a buffer if the line matches a regular expression. In vim, we can use the :g > command for this. I don't know that :g in vim that exactly, I prefer to use ``.´´ from time to time. GNU Emacs allows to use three commands: repeat repeat-complex-command repeat-matching-complex-command See which one can be used! (Deleting a single line is simple: C-k, deleting a bunch of lines is also quite simple: C-u <number> C-k – which could be as simple as in vi/vim.) -- Greetings Pete There's no place like ~ – (UNIX Guru) ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 9:27 ` Peter Dyballa @ 2011-07-22 9:48 ` Thierry Volpiatto 2011-07-22 10:02 ` C K Kashyap 0 siblings, 1 reply; 18+ messages in thread From: Thierry Volpiatto @ 2011-07-22 9:48 UTC (permalink / raw) To: help-gnu-emacs Peter Dyballa <Peter_Dyballa@Web.DE> writes: > Am 22.07.2011 um 10:42 schrieb C K Kashyap: > >> I need to perform a certain action (such as delete the line) on each line of >> a buffer if the line matches a regular expression. In vim, we can use the :g >> command for this. > > I don't know that :g in vim that exactly, I prefer to use ``.´´ from time to time. > > GNU Emacs allows to use three commands: > > repeat > repeat-complex-command > repeat-matching-complex-command > > See which one can be used! (Deleting a single line is simple: C-k, > deleting a bunch of lines is also quite simple: C-u <number> C-k – > which could be as simple as in vi/vim.) I think he want to delete lines matching a regexp, so C-k is not what he wants here. `query-replace-regexp' can be used with a regexp like this: ^.*\(your_regexp\).*$ and you replace with nothing (empty prompt). -- A+ Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997 ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 9:48 ` Thierry Volpiatto @ 2011-07-22 10:02 ` C K Kashyap 2011-07-22 10:12 ` Peter Dyballa ` (3 more replies) 0 siblings, 4 replies; 18+ messages in thread From: C K Kashyap @ 2011-07-22 10:02 UTC (permalink / raw) To: Thierry Volpiatto; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 415 bytes --] > > > which could be as simple as in vi/vim.) > I think he want to delete lines matching a regexp, so C-k is not what he > wants here. > > `query-replace-regexp' can be used with a regexp like this: > > ^.*\(your_regexp\).*$ > > and you replace with nothing (empty prompt). > > -- > replace-regexp is indeed closer to what I am looking for. However, I'd like the result to not leave blank lines. Regards, Kashyap [-- Attachment #2: Type: text/html, Size: 729 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:02 ` C K Kashyap @ 2011-07-22 10:12 ` Peter Dyballa 2011-07-22 10:41 ` C K Kashyap 2011-07-22 10:34 ` Thien-Thi Nguyen ` (2 subsequent siblings) 3 siblings, 1 reply; 18+ messages in thread From: Peter Dyballa @ 2011-07-22 10:12 UTC (permalink / raw) To: C K Kashyap; +Cc: help-gnu-emacs, Thierry Volpiatto Am 22.07.2011 um 12:02 schrieb C K Kashyap: > I'd like the result to not leave blank lines. Then modify the regexp to: ^.*\(your_regexp\).*^J The final ^J (LINEFEED character) can be input as C-q C-j or as C-o. -- Greetings Pete Globalisation – communism from above. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:12 ` Peter Dyballa @ 2011-07-22 10:41 ` C K Kashyap 0 siblings, 0 replies; 18+ messages in thread From: C K Kashyap @ 2011-07-22 10:41 UTC (permalink / raw) To: Peter Dyballa; +Cc: help-gnu-emacs, Thierry Volpiatto [-- Attachment #1: Type: text/plain, Size: 457 bytes --] On Fri, Jul 22, 2011 at 3:42 PM, Peter Dyballa <Peter_Dyballa@web.de> wrote: > > Am 22.07.2011 um 12:02 schrieb C K Kashyap: > > > I'd like the result to not leave blank lines. > > Then modify the regexp to: > > ^.*\(your_regexp\).*^J > > The final ^J (LINEFEED character) can be input as C-q C-j or as C-o. > > -- > Greetings > > Pete > > Globalisation – communism from above. > > Thanks Pete ... this works for me. Kashyap [-- Attachment #2: Type: text/html, Size: 811 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:02 ` C K Kashyap 2011-07-22 10:12 ` Peter Dyballa @ 2011-07-22 10:34 ` Thien-Thi Nguyen 2011-07-22 10:44 ` C K Kashyap 2011-07-22 10:45 ` Deniz Dogan 2011-07-22 19:03 ` Eric Abrahamsen 3 siblings, 1 reply; 18+ messages in thread From: Thien-Thi Nguyen @ 2011-07-22 10:34 UTC (permalink / raw) To: C K Kashyap; +Cc: help-gnu-emacs () C K Kashyap <ckkashyap@gmail.com> () Fri, 22 Jul 2011 15:32:10 +0530 However, I'd like the result to not leave blank lines. Try ‘M-x flush-lines’. Use ‘C-h f flush-lines RET’ first to avoid surprises. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:34 ` Thien-Thi Nguyen @ 2011-07-22 10:44 ` C K Kashyap 0 siblings, 0 replies; 18+ messages in thread From: C K Kashyap @ 2011-07-22 10:44 UTC (permalink / raw) To: Thien-Thi Nguyen; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 292 bytes --] > > () C K Kashyap <ckkashyap@gmail.com> > () Fri, 22 Jul 2011 15:32:10 +0530 > > However, I'd like the > result to not leave blank lines. > > Try ‘M-x flush-lines’. > Use ‘C-h f flush-lines RET’ first to avoid surprises. > this does exactly what I was looking for. Kashyap [-- Attachment #2: Type: text/html, Size: 548 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:02 ` C K Kashyap 2011-07-22 10:12 ` Peter Dyballa 2011-07-22 10:34 ` Thien-Thi Nguyen @ 2011-07-22 10:45 ` Deniz Dogan 2011-07-22 10:46 ` Deniz Dogan 2011-07-22 19:03 ` Eric Abrahamsen 3 siblings, 1 reply; 18+ messages in thread From: Deniz Dogan @ 2011-07-22 10:45 UTC (permalink / raw) To: help-gnu-emacs On 2011-07-22 12:02, C K Kashyap wrote: > > which could be as simple as in vi/vim.) > I think he want to delete lines matching a regexp, so C-k is not what he > wants here. > > `query-replace-regexp' can be used with a regexp like this: > > ^.*\(your_regexp\).*$ > > and you replace with nothing (empty prompt). > > -- > > > replace-regexp is indeed closer to what I am looking for. However, I'd > like the result to not leave blank lines. > > Regards, > Kashyap First, either move to the start of where you want to search OR make an active region (select) the parts where you want it to take effect. M-< goes to the beginning of the buffer and C-x h marks the whole buffer, FYI. Now, M-x delete-matching-lines RET your_regexp RET Deniz ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:45 ` Deniz Dogan @ 2011-07-22 10:46 ` Deniz Dogan 0 siblings, 0 replies; 18+ messages in thread From: Deniz Dogan @ 2011-07-22 10:46 UTC (permalink / raw) To: help-gnu-emacs On 2011-07-22 12:45, Deniz Dogan wrote: > On 2011-07-22 12:02, C K Kashyap wrote: >> > which could be as simple as in vi/vim.) >> I think he want to delete lines matching a regexp, so C-k is not what he >> wants here. >> >> `query-replace-regexp' can be used with a regexp like this: >> >> ^.*\(your_regexp\).*$ >> >> and you replace with nothing (empty prompt). >> >> -- >> >> >> replace-regexp is indeed closer to what I am looking for. However, I'd >> like the result to not leave blank lines. >> >> Regards, >> Kashyap > > First, either move to the start of where you want to search OR make an > active region (select) the parts where you want it to take effect. M-< > goes to the beginning of the buffer and C-x h marks the whole buffer, FYI. > > Now, M-x delete-matching-lines RET your_regexp RET > You may also want to know about: Global Bindings Starting With M-s: key binding --- ------- M-s h Prefix Command M-s o occur M-s w isearch-forward-word M-s h f hi-lock-find-patterns M-s h l highlight-lines-matching-regexp M-s h p highlight-phrase M-s h r highlight-regexp M-s h u unhighlight-regexp M-s h w hi-lock-write-interactive-patterns As you can see, e.g. M-s h r can be very useful at times. Deniz ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 10:02 ` C K Kashyap ` (2 preceding siblings ...) 2011-07-22 10:45 ` Deniz Dogan @ 2011-07-22 19:03 ` Eric Abrahamsen 3 siblings, 0 replies; 18+ messages in thread From: Eric Abrahamsen @ 2011-07-22 19:03 UTC (permalink / raw) To: help-gnu-emacs On Fri, Jul 22 2011, C K Kashyap wrote: > > which could be as simple as in vi/vim.) > I think he want to delete lines matching a regexp, so C-k is not > what he > wants here. > > `query-replace-regexp' can be used with a regexp like this: > > ^.*\(your_regexp\).*$ > > and you replace with nothing (empty prompt). > > -- > > > replace-regexp is indeed closer to what I am looking for. However, > I'd like the result to not leave blank lines. > > Regards, > Kashyap Isn't this what flush-lines and keep-lines are for? ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 8:42 Emacs equivalent of the ":g" command in vi C K Kashyap 2011-07-22 9:27 ` Peter Dyballa @ 2011-07-22 20:27 ` MBR 2011-07-22 20:37 ` Andreas Röhler 2011-07-23 3:02 ` C K Kashyap 1 sibling, 2 replies; 18+ messages in thread From: MBR @ 2011-07-22 20:27 UTC (permalink / raw) To: C K Kashyap; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 6136 bytes --] On 7/22/2011 4:42 AM, C K Kashyap wrote: > Hi, > Could someone please tell me how I could go about something like this - > I need to perform a certain action (such as delete the line) on each > line of a buffer if the line matches a regular expression. In vim, we > can use the :g command for this. > Regards, > Kashyap I looked for the same thing ages ago when I switched from vi to emacs. Eventually I figured out that: :g/regular expression/operation reflects an 'ed' mindset, and that an Emacs macro with a repeat count is actually far more powerful . (In case you're wondering what 'ed' is, it was the original, line-oriented, Unix editor. 'vi' was Bill Joy's visual mode version of 'ex', which was his enhanced version of 'ed'.) An Emacs macro is a series of emacs commands that you can replay. You use C-( and C-) as follows to create a macro: C-( type any commands you want Emacs to remember C-) Then, whenever you type C-x e, Emacs will replay the commands. At this point, you're probably wondering how this can substitute for vi's g//. Simple. Just start your macro off with a regular expression search, do whatever you want, and then replay it multiple times with: C-u /count/ C-x e Specify a large enough repeat count, and you can make your macro apply to the whole file. For example, to delete each line of a buffer if the line matches a regular expression, you'd define the macro with: C-( ;; Begin recording macro C-M-s regexp ;; Search for regular expression C-a ;; Go to beginning of line C-k ;; Kill one line by typing C-k twice C-k ;; C-) ;; End recording macro Then you'd execute the macro with: C-u 10000 C-x e Of course, there's an easier way to delete lines that match a regular expression: M-x delete-matching-lines But you described the general problem as needing to perform a certain action on each line of a buffer if the line matches a regular expression. And the approach of defining a macro to do what you want and then executing it with a large repeat count gives you a general purpose mechanism to do arbitrary operations rather than just delete the line. For example, if I have a file of lines of the format: zip,street address,city,state,phone,name That I wanted to rearrange to: name,phone,street address,city,state,zip I could run: M-x replace-regexp ^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$ \6,\5,\2,\3,\4,\1 which is the equivalent of vi's: :g/^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$/s//\6,\5,\2,\3,\4,\1/g But making sure you've got that regular expression right can be tricky. It can be much easier to just do it with emacs commands applied to a single line. Although the following is difficult to read, I think if you try it out you'll find it pretty straightforward. First fill an emacs buffer with lots of lines of the form: name,phone,street address,city,state,zip Then type these emacs keystrokes (omitting the comments): ;; Begin recording macro C-( ;; Narrow the buffer to the current line: C-SPC C-n C-x n n M-< ;; Move the part after the fifth "," ;; to the beginning of the line C-s , C-s C-s C-s C-s C-b C-k C-a C-y , C-a C-d ;; Move the part that's now after the fifth "," ;; to the second comma-delimited position C-s , 4*C-s C-b C-k C-a M-f C-y ;; Move the third comma-delimited part to the end M-d C-e C-y ;; Move forward over the newline to the next line C-f ;; Widen so you can see the whole buffer C-x n w ;; End recording macro C-) Replay it 10,000 times with: C-u 10000 C-x e It will stop as soon as it runs out of matching lines. The point is that the operations you can repeat this way are limited only by your imagination. There's a variant of this that I use frequently. I often find that a non-emacs application wants me to type lots of information into individual fields of an input screen. It's a pain to have to type all that data, especially when I have that data in a text file. In emacs I can organize the data into the same order as the input fields in the application, putting each field's data on a separate line of the emacs buffer. Then I do the following in emacs: ;; Begin recording macro C-( ;; Mark region from beginning to end of line C-aC-SPCC-e ;; Copy region so it can be pasted into another application C-w ;; Move forward over the newline to the next line C-f ;; End recording macro C-) Once I've defined that macro, I can repeatedly type: ;; This is not an Emacs command. It tells the window manager ;; to give keyboard focus to the other application. ALT-TAB ;; Paste into the input field C-v ;; Move focus to the next input field TAB ;; Give keyboard focus to Emacs. ALT-TAB ;; Repeat the macro, which copies the next line. C-x e At that point, I repeatedly type: C-x e ALT-TAB C-v TAB ALT-TAB While it's not fully automated, If I've got lots of data that has to be entered through a GUI interface, it makes things go a whole lot faster. If you should want to save a macro you've created this way so you can use it in future Emacs sessions: Open your .emacs file: C-x C-f ~/.emacs Give it a name by with:M-x name-last-kbd-macro Insert it into your .emacs with: M-x insert-kbd-macro Save your .emacs file: C-x C-s Mark Rosenthal mbr@arlsoft.com <mailto:mbr@arlsoft.com> P.S. - Interesting side-note. Did you know that the ed command: g/regular expression/operation is where the name "grep" came from? In ed and ex, the "g" means do a global search for the immediately following regular expression, and apply the operation to every matching line. One such operation is "p" meaning "print". Using "re" as shorthand for "regular expression", the ed command to print every line that matches a particular regular expression is: g/re/p [-- Attachment #2: Type: text/html, Size: 8969 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 20:27 ` MBR @ 2011-07-22 20:37 ` Andreas Röhler 2011-07-22 20:51 ` MBR 2011-07-23 3:02 ` C K Kashyap 1 sibling, 1 reply; 18+ messages in thread From: Andreas Röhler @ 2011-07-22 20:37 UTC (permalink / raw) To: help-gnu-emacs Am 22.07.2011 22:27, schrieb MBR: > On 7/22/2011 4:42 AM, C K Kashyap wrote: >> Hi, >> Could someone please tell me how I could go about something like this - >> I need to perform a certain action (such as delete the line) on each >> line of a buffer if the line matches a regular expression. In vim, we >> can use the :g command for this. >> Regards, >> Kashyap > > I looked for the same thing ages ago when I switched from vi to emacs. > Eventually I figured out that: > > :g/regular expression/operation > > reflects an 'ed' mindset, and that an Emacs macro with a repeat count is > actually far more powerful . (In case you're wondering what 'ed' is, it > was the original, line-oriented, Unix editor. 'vi' was Bill Joy's visual > mode version of 'ex', which was his enhanced version of 'ed'.) > > An Emacs macro is a series of emacs commands that you can replay. You > use C-( and C-) as follows to create a macro: > > C-( > type any commands you want Emacs to remember > C-) > > Then, whenever you type C-x e, Emacs will replay the commands. > > At this point, you're probably wondering how this can substitute for > vi's g//. Simple. Just start your macro off with a regular expression > search, do whatever you want, and then replay it multiple times with: > > C-u /count/ C-x e > > Specify a large enough repeat count, and you can make your macro apply > to the whole file. > > For example, to delete each line of a buffer if the line matches a > regular expression, you'd define the macro with: > > C-( ;; Begin recording macro > C-M-s regexp ;; Search for regular expression > C-a ;; Go to beginning of line > C-k ;; Kill one line by typing C-k twice > C-k ;; > C-) ;; End recording macro > > Then you'd execute the macro with: > > C-u 10000 C-x e > > Of course, there's an easier way to delete lines that match a regular > expression: > > M-x delete-matching-lines > > But you described the general problem as needing to perform a certain > action on each line of a buffer if the line matches a regular > expression. And the approach of defining a macro to do what you want and > then executing it with a large repeat count gives you a general purpose > mechanism to do arbitrary operations rather than just delete the line. > > For example, if I have a file of lines of the format: > > zip,street address,city,state,phone,name > > That I wanted to rearrange to: > > name,phone,street address,city,state,zip > > I could run: > > M-x replace-regexp > ^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$ > \6,\5,\2,\3,\4,\1 > > which is the equivalent of vi's: > > :g/^\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$/s//\6,\5,\2,\3,\4,\1/g > > > But making sure you've got that regular expression right can be tricky. > It can be much easier to just do it with emacs commands applied to a > single line. Although the following is difficult to read, I think if you > try it out you'll find it pretty straightforward. First fill an emacs > buffer with lots of lines of the form: > > name,phone,street address,city,state,zip > > Then type these emacs keystrokes (omitting the comments): > > ;; Begin recording macro > C-( > ;; Narrow the buffer to the current line: > C-SPC C-n C-x n n M-< > ;; Move the part after the fifth "," > ;; to the beginning of the line > C-s , C-s C-s C-s C-s C-b C-k C-a C-y , C-a C-d > ;; Move the part that's now after the fifth "," > ;; to the second comma-delimited position > C-s , 4*C-s C-b C-k C-a M-f C-y > ;; Move the third comma-delimited part to the end > M-d C-e C-y > ;; Move forward over the newline to the next line > C-f > ;; Widen so you can see the whole buffer > C-x n w > ;; End recording macro > C-) > > Replay it 10,000 times with: > > C-u 10000 C-x e > > It will stop as soon as it runs out of matching lines. > > The point is that the operations you can repeat this way are limited > only by your imagination. > > There's a variant of this that I use frequently. I often find that a > non-emacs application wants me to type lots of information into > individual fields of an input screen. It's a pain to have to type all > that data, especially when I have that data in a text file. In emacs I > can organize the data into the same order as the input fields in the > application, putting each field's data on a separate line of the emacs > buffer. Then I do the following in emacs: > > ;; Begin recording macro > C-( > ;; Mark region from beginning to end of line > C-aC-SPCC-e > ;; Copy region so it can be pasted into another application > C-w > ;; Move forward over the newline to the next line > C-f > ;; End recording macro > C-) > > Once I've defined that macro, I can repeatedly type: > > ;; This is not an Emacs command. It tells the window manager > ;; to give keyboard focus to the other application. > ALT-TAB > ;; Paste into the input field > C-v > ;; Move focus to the next input field > TAB > ;; Give keyboard focus to Emacs. > ALT-TAB > ;; Repeat the macro, which copies the next line. > C-x e > > At that point, I repeatedly type: > > C-x e ALT-TAB C-v TAB ALT-TAB > > While it's not fully automated, If I've got lots of data that has to be > entered through a GUI interface, it makes things go a whole lot faster. > > If you should want to save a macro you've created this way so you can > use it in future Emacs sessions: > > Open your .emacs file: C-x C-f ~/.emacs > Give it a name by with:M-x name-last-kbd-macro > Insert it into your .emacs with: M-x insert-kbd-macro > Save your .emacs file: C-x C-s > > Mark Rosenthal > mbr@arlsoft.com <mailto:mbr@arlsoft.com> > > P.S. - Interesting side-note. Did you know that the ed command: > > g/regular expression/operation > > is where the name "grep" came from? In ed and ex, the "g" means do a > global search for the immediately following regular expression, and > apply the operation to every matching line. One such operation is "p" > meaning "print". Using "re" as shorthand for "regular expression", the > ed command to print every line that matches a particular regular > expression is: > > g/re/p > > > Hi, from my feeling: finally much easier then fighting which recorded keyboard-macros is writing it's own little functions. Running them under edebug then and a breakpoint set allows neatly control Keyboard macros are good for really limited and easy repeats. Andreas ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 20:37 ` Andreas Röhler @ 2011-07-22 20:51 ` MBR 2011-07-23 7:10 ` Andreas Röhler 2011-08-15 0:27 ` Ken Goldman 0 siblings, 2 replies; 18+ messages in thread From: MBR @ 2011-07-22 20:51 UTC (permalink / raw) To: Andreas Röhler; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 1110 bytes --] Personally, I don't find I'm "fighting" with macros. You can get an astounding amount done with macros without having to do the mental context switch to coding mode. And if I'm already in coding mode, I find putting the real application I was working on (in Java or C or PHP or JavaScript or whatever) on short-term hold and switching context to writing Elisp code for editing the application code, leaves me struggling to remember what I was trying to accomplish with my changes to the application code when I finally finish writing the Elisp code and need to pop that context off my mental stack and return to thinking about the application code. But other people's mental processes may well be different. To each his own. Or, as they say, YMMV. Mark On 7/22/2011 4:37 PM, Andreas Röhler wrote: > Hi, > > from my feeling: finally much easier then fighting which recorded > keyboard-macros is writing it's own little functions. > > Running them under edebug then and a breakpoint set allows neatly control > > Keyboard macros are good for really limited and easy repeats. > > Andreas > [-- Attachment #2: Type: text/html, Size: 1677 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 20:51 ` MBR @ 2011-07-23 7:10 ` Andreas Röhler 2011-08-15 0:27 ` Ken Goldman 1 sibling, 0 replies; 18+ messages in thread From: Andreas Röhler @ 2011-07-23 7:10 UTC (permalink / raw) To: MBR; +Cc: help-gnu-emacs Am 22.07.2011 22:51, schrieb MBR: > Personally, I don't find I'm "fighting" with macros. You can get an > astounding amount done with macros without having to do the mental > context switch to coding mode. And if I'm already in coding mode, I find > putting the real application I was working on (in Java or C or PHP or > JavaScript or whatever) on short-term hold and switching context to > writing Elisp code for editing the application code, leaves me > struggling to remember what I was trying to accomplish with my changes > to the application code when I finally finish writing the Elisp code and > need to pop that context off my mental stack and return to thinking > about the application code. > > But other people's mental processes may well be different. To each his > own. Or, as they say, YMMV. > > Mark Sure. If you like, it might be of interest for others too comparing a real example. If you may provide a piece of code and a kbd-macro dealing with it, let's see how a function might come up with. BTW as for functions you will have templates. So quite often creating a new function isn't much more finally than specifying a regexp. Andreas ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 20:51 ` MBR 2011-07-23 7:10 ` Andreas Röhler @ 2011-08-15 0:27 ` Ken Goldman 1 sibling, 0 replies; 18+ messages in thread From: Ken Goldman @ 2011-08-15 0:27 UTC (permalink / raw) To: help-gnu-emacs On 7/22/2011 4:51 PM, MBR wrote: > Personally, I don't find I'm "fighting" with macros. You can get an > astounding amount done with macros without having to do the mental > context switch to coding mode. I agree with this. I use keyboard macros all the time for complicated editing functions that I only have to do once. Define it, then M-x big number. True, they can be slow, but they're still faster than trying to code up the 'right way' to do it. ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-22 20:27 ` MBR 2011-07-22 20:37 ` Andreas Röhler @ 2011-07-23 3:02 ` C K Kashyap 2011-07-23 8:44 ` suvayu ali 1 sibling, 1 reply; 18+ messages in thread From: C K Kashyap @ 2011-07-23 3:02 UTC (permalink / raw) To: MBR; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 768 bytes --] > > Save your .emacs file: C-x C-s > > Mark Rosenthal > mbr@arlsoft.com > > P.S. - Interesting side-note. Did you know that the ed command: > > g/regular expression/operation > > is where the name "grep" came from? In ed and ex, the "g" means do a > global search for the immediately following regular expression, and apply > the operation to every matching line. One such operation is "p" meaning > "print". Using "re" as shorthand for "regular expression", the ed command > to print every line that matches a particular regular expression is: > > g/re/p > > > Thank you very much Mark for the detailed explanation and the interesting side note :) I am inclined to the macro approach since the possibilities are endless. Regards, Kashyap [-- Attachment #2: Type: text/html, Size: 1445 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: Emacs equivalent of the ":g" command in vi 2011-07-23 3:02 ` C K Kashyap @ 2011-07-23 8:44 ` suvayu ali 0 siblings, 0 replies; 18+ messages in thread From: suvayu ali @ 2011-07-23 8:44 UTC (permalink / raw) To: C K Kashyap; +Cc: help-gnu-emacs On Sat, Jul 23, 2011 at 5:02 AM, C K Kashyap <ckkashyap@gmail.com> wrote: > I am inclined to the macro approach since the possibilities are endless. Keyboard macros are great and all, but I wouldn't recommend repeating it more than a few hundred times. They are slow and sensitive to external conditions. If your use case requires a repetition of a thousand or more times, I would recommend `eval' (M-:) or an elisp function. I have gone down the keyboard macro route once and regretted it with a large file (~10,000 lines long). -- Suvayu Open source is the future. It sets us free. ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2011-08-15 0:27 UTC | newest] Thread overview: 18+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-07-22 8:42 Emacs equivalent of the ":g" command in vi C K Kashyap 2011-07-22 9:27 ` Peter Dyballa 2011-07-22 9:48 ` Thierry Volpiatto 2011-07-22 10:02 ` C K Kashyap 2011-07-22 10:12 ` Peter Dyballa 2011-07-22 10:41 ` C K Kashyap 2011-07-22 10:34 ` Thien-Thi Nguyen 2011-07-22 10:44 ` C K Kashyap 2011-07-22 10:45 ` Deniz Dogan 2011-07-22 10:46 ` Deniz Dogan 2011-07-22 19:03 ` Eric Abrahamsen 2011-07-22 20:27 ` MBR 2011-07-22 20:37 ` Andreas Röhler 2011-07-22 20:51 ` MBR 2011-07-23 7:10 ` Andreas Röhler 2011-08-15 0:27 ` Ken Goldman 2011-07-23 3:02 ` C K Kashyap 2011-07-23 8:44 ` suvayu ali
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).