tag:blogger.com,1999:blog-3992530807750384868.post6197615112978020971..comments2022-03-28T08:42:20.497+03:00Comments on emacs-fu: keyboard macrosUnknownnoreply@blogger.comBlogger16125tag:blogger.com,1999:blog-3992530807750384868.post-52480210446670820952014-01-06T07:08:38.167+02:002014-01-06T07:08:38.167+02:00Hi, useful blog. please post on how to list all th...Hi, useful blog. please post on how to list all the saved macros.<br />Thanks,<br />Sagarsagarhttps://www.blogger.com/profile/01485134202842008383noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-35150292706863565922011-01-07T13:25:05.872+02:002011-01-07T13:25:05.872+02:00I would do it by wrapping the following in a macro...I would do it by wrapping the following in a macro and repeating it 3 times after the initial run:<br /><br />(forward-word) ; M-f<br />(delete-char) ; C-d<br />(transpose-words) ; C-p (C-t for me; it's faster because I use Dvorak, not QWERTY)<br />(forward-char) ; C-f<br /><br />--elimisteveSteve Phillipshttps://www.blogger.com/profile/04401794045739027707noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-66464575994500210522010-08-27T21:15:06.241+03:002010-08-27T21:15:06.241+03:00You could also use text to columns, using the spac...You could also use text to columns, using the space as to delimit and then replace the comma with nothing.rebeccahttps://www.blogger.com/profile/09327228853915763013noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-46536376408126914312010-07-29T16:41:10.799+03:002010-07-29T16:41:10.799+03:00@Todd Kaufmann: sure, the macro could be improved ...@Todd Kaufmann: sure, the macro could be improved in various ways and indeed in real life you could make at bit more tolerant for small differences in the lines.<br /><br />maybe we should have a competition for some data manipulation using the shortest possible keyboard macros, somewhat like 'perl golf' for emacs...djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-31490058454249831632010-07-27T10:02:43.435+03:002010-07-27T10:02:43.435+03:00From the beginning of the line, I would use
M-z , ...From the beginning of the line, I would use<br />M-z , ;; 1. zap to the comma<br />M-\ ;; 2. delete-horizontal-space<br />C-e<br />M-\<br />spc<br />C-y<br />bkspc ;; backward-delete, whever you have it<br /><br />notes:<br />1. M-z (zap-to-char) is very useful and will take care of names like 'van Helsing' or 'Haifin-Dache'.<br />2. delete-horizontal-space is useful in a number of cleanup situations (M-^ too). Twice here, just in case there is extra whitespace, make sure there's only one.<br /><br />There are a number of commands that I probably only use inside of keyboard macros because they do the right thing in multiple situations.toddhttps://www.blogger.com/profile/15102634550979910775noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-39688269904840579992010-07-24T10:29:18.487+03:002010-07-24T10:29:18.487+03:00@Bruneel Michaël: fixed, thanks!@Bruneel Michaël: fixed, thanks!djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-23319983499436847022010-07-24T03:05:23.877+03:002010-07-24T03:05:23.877+03:00@djcb,
Probably typo :
- start defining a keyboa...@djcb,<br /><br />Probably typo : <br />- start defining a keyboard macro (start-kbd-macro) with "<b>C-x (</b>", not "C-("<br />- end the definition of a keyboard macro (end-kbd-macro) with "<b>C-x )</b>", not "C-)".Bruneel Michaëlnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-66891498375523014962010-07-21T23:01:13.479+03:002010-07-21T23:01:13.479+03:00You mention how to save macros for future use. I ...You mention how to save macros for future use. I wrote up some code which automatically makes this key string the readable version. You might want to check it out at Stack Overflow <a href="http://stackoverflow.com/questions/3121274/emacs-keystroke-representation-confusion/3121383#3121383" rel="nofollow">emacs keystroke representation confusion</a>ahttps://www.blogger.com/profile/03202031495623868181noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-63583761354581384152010-07-17T10:14:56.161+03:002010-07-17T10:14:56.161+03:00@Erik: ah, didn't know that, thanks; updated.
...@Erik: ah, didn't know that, thanks; updated.<br />@Bill Night,@Anonymous: indeed, F4 always works. Unless you're defining a macro while defining a macro.... Anyway, updated.djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-15817672203229005912010-07-17T07:48:46.657+03:002010-07-17T07:48:46.657+03:00Repeated 'e' presses only seem to work if ...Repeated 'e' presses only seem to work if you used C-x e to invoke it the first time. Pressing F4 will should repeat the macro in either case.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-90870233071271919202010-07-17T02:23:29.458+03:002010-07-17T02:23:29.458+03:00In the example, I would have used isearch-forward ...In the example, I would have used isearch-forward (C-s) to find the comma and used a selection to go back to the beginning of the line (C-s , RET del del C-space C-a C-w C-e space C-y). <br /><br />I only mention it to help folks see different ways to define macros that need to be more flexible.Eric Larsonhttp://ionrock.orgnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-47566510262802841312010-07-17T02:08:59.868+03:002010-07-17T02:08:59.868+03:00Hmmm... the trick of pressing 'e' repeated...Hmmm... the trick of pressing 'e' repeatedly doesn't work for me in emacs 21.3. Must have come in with some later version.Bill Nighthttps://www.blogger.com/profile/09202318621724165312noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-83071722182505307662010-07-17T00:59:32.826+03:002010-07-17T00:59:32.826+03:00You can repeat something more than 9 times using t...You can repeat something more than 9 times using the digit-keys. If you press M-1 2 8 C-x e the macro will be repeated 128 times. You do not have to release the Meta-button, so M-1 M-2 M-8 C-x e works too.Unknownhttps://www.blogger.com/profile/15960651706768386273noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-43130518239388447022010-07-16T23:27:10.878+03:002010-07-16T23:27:10.878+03:00One thing that I didn't realise for a very lon...One thing that I didn't realise for a very long time was that you're free to jump around between buffers (C-x b, C-x o, etc.) within a macro. There's nothing restricting you to just a single buffer. I've generally tended to use this ability with one buffer supplying data to a macro to control its operation on another buffer.<br /><br />For example, you could have one buffer with a list of strings that you kill one at a time with C-k, hop over to a target buffer with C-x o, isearch for it with C-s M-y, do some work at that spot, and then hop back to the control buffer with C-x o and advance to the next string for the next macro repetition with C-n.<br /><br />This approach can be really powerful, and lets keyboard macros go far beyond the kinds of basic transforms that regexps could do.Boojumnoreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-15321930615560353702010-07-16T22:31:50.110+03:002010-07-16T22:31:50.110+03:00@danlei: thanks, added.@danlei: thanks, added.djcbhttps://www.blogger.com/profile/15938154009846040711noreply@blogger.comtag:blogger.com,1999:blog-3992530807750384868.post-90067049543479547662010-07-16T22:22:19.822+03:002010-07-16T22:22:19.822+03:00You could also mention that, once a macro has been...You could also mention that, once a macro has been invoked via <i>C-x e</i>, you can repeat its invocation by pressing <i>e</i> repeatedly.Unknownhttps://www.blogger.com/profile/09880112500555037398noreply@blogger.com