4 ms·
> "Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" is fundamental in the same way that "go to start of line" or
by TeMPOraL 7y ago
> "Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" is fundamental in the same way that "go to start of line" or "indent this line one more tabstop" is.
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.
- Rediscover 7y agoI 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.
- TeMPOraL 7y agoOh, 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).