Re:Emacs: The Editor for the Next Forty Years [video]
by Rediscover on Tuesday November 26, 2019 @09:59PM
(#21644894)
I love view-lossage. How often do You use C-x <esc> <esc> which shows elisp for what ya just did? Eg, switch buffer then try it.
Re:Emacs: The Editor for the Next Forty Years [video]
by TeMPOraL on Wednesday November 27, 2019 @02:02AM
(#21645892)
Oh, I didn't even know about that! That's great!
Also, it reads straight from command-history variable (another thing I didn't know about). You can preview and browse it via C-h v command-history. Or, write your own elisp operating on it (perhaps interactively, by IELM - the elisp REPL).
So write a function for "duplicate line" and use it from now on. It's very easy to do. Just as it's easy to write function for a full edit.
A general algorithm to get one started:
1) Execute the edit you want to reuse.
2) Press C-h l, or M-x view-lossage, to see all the keypresses you made recently, along with elisp commands they executed.
3) You now know all the operations you did. Most of the time, you can recreate the edit by just wrapping them in parens, and then wrapping the whole block with (progn).
4) You're now ready to turn it into a function. Read up on 'defun and 'interactive forms. For best results, check out the documentation for each command you used during edit, via C-h f - some commands are meant for direct usage, and have a (faster, better) variant meant for use from within code; this is usually documented.
5) Tweak your function to make it more general along the dimensions you need, bind it to a key, and now you've just implemented what elsewhere would take a large plugin.