Emacs - the editor that STILL doesn't have a simple way to duplicate the current line?
I think the germane point about Emacs here is that some people like writing Lisp and some people hate it. If you hate it Emacs is likely not going to be your best environment, and that’s fine. I really like writing Lisp so Emacs has a simple way of doing anything I want, but it’s not for everyone.
Emacs: The Editor for the Next Forty Years [video]
151–160 of 272 posts
Re: Emacs: The Editor for the Next Forty Years [video]
#152Earlier quoted context omitted.
Well, everyone edits things in different ways. The Emacs way of solving a workflow problem is instructing Emacs how to solve it for you. For instance, you mention: 1. Copy the line the cursor (point) is on; 2. Insert the copied line below/above point; 3. Commenting out the line you copied; By the sound of things you do 1 and 2 with a command in Vim and the 3rd option with another command. In Emacs, I would simply pro…
The point is that "duplicating a line" is a very fundamental building block to other operations, and it should be supported natively. For instance, lets say you have to do several different function calls with only minor differences, you might write it out once and then duplicate a few times, then go in and edit them. "Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" 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.
Re: Emacs: The Editor for the Next Forty Years [video]
#153Earlier quoted context omitted.
Different editors have different patterns of usage. I find I roughly speaking never duplicate lines, so why would this be a problem?
I constantly find myself duplicate lines in vim (shift+y). You've never had to edit a line that's really similar to another? Or when debugging, I don't want to change the old code, so I copy the line, comment it out, and work with the duplicated line. You've never had to do that?
Re: Emacs: The Editor for the Next Forty Years [video]
#154Earlier quoted context omitted.
I think this is a larger problem with Emacs. Duplicating a line is something that should be easy to do out of the box. And if it's a situation where you really need to make the user define a keyboard shortcut, don't make them do C-c followed by the actual shortcut, let them define single keystroke shortcuts to do what they want. Multiple keystroke shortcuts are so damn annoying.
Why? I can't think of any time when I've wanted to duplicate a line.
Re: Emacs: The Editor for the Next Forty Years [video]
#155Earlier quoted context omitted.
I think this is a larger problem with Emacs. Duplicating a line is something that should be easy to do out of the box. And if it's a situation where you really need to make the user define a keyboard shortcut, don't make them do C-c followed by the actual shortcut, let them define single keystroke shortcuts to do what they want. Multiple keystroke shortcuts are so damn annoying.
https://github.com/emacs-evil/evil ;)
Re: Emacs: The Editor for the Next Forty Years [video]
#156Earlier quoted context omitted.
The benefit of Emacs's keybindings is that they're the default keys used by GNU readline (though it also supports Vi-style keys.) That means when you know that Ctrl+E and Ctrl+A (`C-e' / `C-a') goes to the end or beginnings of a line in Emacs, you know it'll also work in your bash shell (or indeed any tool that uses GNU readline.)
That's what I'm using while coding, but it's not friendly to all software (e.g. browsers or other programs that don't have configurable keyboard shortcuts).
Re: Emacs: The Editor for the Next Forty Years [video]
#157Earlier quoted context omitted.
Triple click the line, then middle click somewhere. Or ctrl a ctrl k ctrl k ctrl y (move) ctrl y. Is it really something that’s so common that it needs a command?
duplicate function declaration or code chunk; comment out old and modify new; leave old inline until you're happy with new and verified existing functionality isn't lost. Super useful working pattern I think that I use constantly. If it was more than `V p` Maybe i wouldn't work like that; but I do because it is so frictionless. The more I use Git the more I've been committing/diffing for similar effect; but it's stil…
If you've got a vim setup that works for you, great.
Re: Emacs: The Editor for the Next Forty Years [video]
#158I recommend Emacs to anyone who thinks it would be fun to use Lisp to configure a text editor, even if just a bit. However, that is an "if and only if".
If you choose to go beyond using emacs lisp for configuration, then I would say that emacs-lisp is an extremely fun and productive environment to work in: many programming languages give you a good standard library and package ecosystem, but with Emacs lisp you not only get that, but from the outset your project will be born into a mature and extremely fully-featured text editing environment. It's possible to create useful projects with a very good feel, with relatively few lines of code. If you don't have another excuse to use a lisp in your life, this is a very good one.
I would like it if Emacs would stop distributing itself with the ridiculous splash screen and 1990s menu icons.
Re: Emacs: The Editor for the Next Forty Years [video]
#159A question for Emacs user: Do you use the GUI version or the terminal version? I found the terminal version next to unworkable because I couldn't find any terminal that didn't capture some keystrokes that were meant for Emacs.
Re: Emacs: The Editor for the Next Forty Years [video]
#160Earlier quoted context omitted.
There may be much going on with emacs, but so far it fails to move ahead. The project is just improving the old strenghts, but not fixing the old fails. And as time moves, they start to hurt more and more and more until they break.
What are some old fails that need fixed?