Keyboard Macros are Misunderstood reddit / emacs ---------------------------------------------------------------------- mickeyp · 2022-07-12 15:10 ---------------------------------------------------------------------- mickeyp · 2022-07-12 15:13 It's all too easy to discount keyboard macros as a blunt instrument of text editing. It's a really effective tool for automating diverse tasks, like window configuration, as that's easily one of the more frustrating things for new users. Ditto combining disparate activities into a single 'action'. So I'd love to hear from people who use keyboard macros for more than "basic" text editing. ---------------------------------------------------------------------- 00-11 · 2022-07-12 15:43 Mickey rightfully used the best terms for those new to Emacs: ***record*** and ***play back***. Everyone understands such behavior, and how, when, and why it's useful. And it's important to realize that this is about pretty much *all* user interactions, not just *"keyboard"* use. The name *"keyboard macro"* is fine from an Emacs point of view (even mouse actions are handled in Emacs with "key bindings" in "keymaps"). But for discovery and introduction, Emacs should put **record** and **play back** front & center. I can't emphasize this enough, I think. Imagine if the other record- and-play-back experiences in your life had names like "keyboard macro"? Ridiculous, right? ---------------------------------------------------------------------- mickeyp · 2022-07-12 15:54 Yeah, the nomenclature's not great. But I suppose it's just human nature to underestimate the power of recording user actions. Most implementations suck, so it's easy to see why people don't bother exploring. The only other macro recorder I can think of that doesn't suck is Microsoft Excel's macro recorder. It's pretty amazing, and it generates quite sane VBA that people can then edit and build on for their own scripts. ---------------------------------------------------------------------- LordOfSwines · 2022-07-12 16:08 Something I do quite often when writing a elisp macro is record a kb macro to jump to some place where I'm using the macro and macroexpand it and then have another macro to undo that expansion and jump back to where I'm defining said macro. Saves me from having to do that manually on every iteration of the macro. ---------------------------------------------------------------------- columbcille · 2022-07-12 16:41 I’m a newb, and just discovered macros. I use one to layout my windows for my morning review—basically to open my org agenda to a certain view and open up the day’s journal. It’s a simple macro, but has opened my eyes to a whole new dimension of things. ---------------------------------------------------------------------- [deleted] · 2022-07-12 16:52 [deleted] ---------------------------------------------------------------------- Imaltont · 2022-07-12 16:55 I would say vim's macros are pretty nice as well. You record them to the wanted register, shared with the "clipboard". It persists between sessions. Since it shares the registers with the clipboard, you can also paste in the macro or copy it from somewhere, including special characters for F-keys, escape etc. ---------------------------------------------------------------------- mickeyp · 2022-07-12 16:59 You may want to give `pp-macroexpand-last-sexp` a try for stuff like this. ---------------------------------------------------------------------- [deleted] · 2022-07-12 17:17 [deleted] ---------------------------------------------------------------------- timmymayes · 2022-07-12 17:31 The bit where you can insert the elisp from a macro is fantastic. Love your book btw! ---------------------------------------------------------------------- LordOfSwines · 2022-07-12 17:41 Yeah that's pretty useful :) Still need to navigate to the expression and do the expansion though, still very handy. ---------------------------------------------------------------------- F4il3d · 2022-07-12 17:55 I usually write elisp code based on strategic significance. The task that the macro is intended to address is of a regular nature so I will use the function again. I used keyboard macros for "one-off" repetitive tasks. They are especially useful when using multiple buffers and when used in conjunction with register commands. There is a dazzling amount of complexity you can achieve. I like and have used keyboard macros for about 30 years. ---------------------------------------------------------------------- hmelman · 2022-07-12 18:07 I’ll setup a (typically dried) buffer with a specific list of files I want to make bulk changes to and then use a macro to: (1) open the file under point in another window (2) switch to that window (3) make some change (4) save and kill the buffer (5) return to my file list (6) move to the next line. Depending on which files I’m working on or what the changes are, it is much more interactive than writing a one- off shell script. ---------------------------------------------------------------------- agumonkey · 2022-07-12 19:22 I still want to make a macro to elisp thingy, with variable inference and other things ---------------------------------------------------------------------- 7890yuiop · 2022-07-12 19:58 The day I realised keyboard macros were awesome was the day when I was looking at a buffer of grep results which effectively formed a to-do list for some non-trivial-but-similar changes in each of those files (not just at the line in the grep results), and thought to myself "I wonder if..." and the answer was "yes; yes you can". More generally, using some collection of data in one buffer to process things elsewhere in other buffers, is really powerful. I also think keyboard macros really highlight the advantages of a keyboard-centric everything-is-text application. ---------------------------------------------------------------------- arthurno1 · 2022-07-12 23:50 There is a 3D animation anf fx package called Maya, by former Alias|Wawefront and now Autodesk. I think they have even nicer alternative to macro recorder. They use a sxripting language based on TCL but with some extras tossed in which they call MEL, which is used pretty similar to Lisp in Emacs. Everything is scriptable similar as in Emacs, and every action is a command, similar to interactive functions in elisp. What they do is to echo/record every command to a built-in (simple) text editor. "Recording" is always on so to say. One can then just select with mouse and grab a bunch of commands from the editor and drag the text selection into a "shelf" (toolbar) and it automatically becomes a clickable button ready to be used. It is not as same as start/stop recording paradigm, but it is maybe even simpler as paradigm. ---------------------------------------------------------------------- eadmund · 2022-07-13 02:41 You’re not wrong, _but_ it does make sense from the general Lisp perspective of having reader macros, compiler macros, normal macros &c. ---------------------------------------------------------------------- whompyjaw · 2022-07-13 13:47 Can you elaborate on how you do it? I have not messed with macros really yet. ---------------------------------------------------------------------- whompyjaw · 2022-07-13 13:49 May I ask exactly what you did? I’m not too knowledgeable in macros yet. ---------------------------------------------------------------------- whompyjaw · 2022-07-13 14:13 I am wondering if someone could give me some direction for creating 2 macros for 2 things I like to do while coding: 1. Insert a TODO commented out with a time stamp in my code. I tried to create a function, but I’m not good at that either (yet) Syntax would be: “# TODO