Emacs musings (was: Re: put cursor on found text in less or vi?)
Paul Smith
paul at mad-scientist.net
Thu Sep 26 18:50:13 UTC 2024
Out of curiosity I tried your must-have items.
I did my experiment with Emacs 29.4, started with "emacs -q" so it did
not load any of my personal customizations.
On Thu, 2024-09-26 at 11:59 -0400, Little Girl wrote:
> I've got four requirements for any editor, all of which are accepted
> as standards most of the time in Linux and Windows:
>
> * Shift+Del and Shift+Ins should cut and paste from and to the
> PRIMARY clipboard (CUA standard) and that should also be the
> editor's clipboard.
I think we may be used to different terms. I wasn't able to find out
precisely what PRIMARY means in CUA. In X (and Wayland I assume),
PRIMARY refers to whatever text is selected (without pressing any keys
to make a copy). So, if you select some text it's now the PRIMARY
selection and if you click Mouse-2 (on most setups) then the PRIMARY
selection is pasted.
The CLIPBOARD is what's updated (from the PRIMARY selection) when you
use C-c and pasted when you use C-v (in most programs, not Emacs).
See: https://en.wikipedia.org/wiki/X_Window_selection
If by PRIMARY you mean the same thing as what I call CLIPBOARD, then
this is the default behavior in Emacs. That is, if I select text in my
browser and use C-c to copy it, then in an Emacs buffer pressing S-Ins
will paste it. Similarly, if I select text in an Emacs buffer and
press S-Del it is cut in the Emacs buffer, then in some other program
using C-v will paste that text.
> * Home and End should take me to the beginning or end of
> the current line and not the actual beginning or end of the
> current sentence if it wraps onto another line (my cursor
> should never change lines when doing either of those
> operations).
This is not the default behavior: by default Home and End move to the
beginning/end of the logical line, not the beginning/end of the
physical line if it wraps. However you can change this by adding:
(global-set-key [home] 'beginning-of-visual-line)
(global-set-key [end] 'end-of-visual-line)
to your ~/.emacs.d/init.el file.
> * Ctrl+Home and Ctrl+End should take me to the beginning or
> end of the document.
This is the default behavior.
> * Ins and Del should insert or delete at the position of the
> cursor.
I'm not sure I understand this. In Emacs the cursor is conceptually
between two characters (even if you display it as a block cursor
instead of a bar cursor). The Del key deletes the character to the
right of the cursor, and Backspace deletes the character to the left of
the cursor. The Ins key toggles overwrite mode.
> My understanding is also that Emacs uses a two-key key-combination to
> get to the beginning and end of a line and it's still not clear to me
> whether Emacs takes wrapping into account in determining where that
> beginning or end is. I'm not sure whether it would accept my Home and
> End keys for that.
In Emacs each key is bound to a command and you can rebind every key
(including all the modifiers like shift, meta, ctrl, etc.) to a
different command, like I show above. You can also bind keys to do
different things in different modes (Emacs chooses a "mode" for each
buffer, typically based on the filename or content of the file that is
loaded into that buffer: e.g., C/C++ mode, Python mode, Text mode,
etc.)
Different keys can (and do) map to the same command. So, the
"traditional" C-a maps to beginning-of-line, but so does Home. I'm not
sure if C-a is an example of what you mean by "two-key key-
combination".
> My understanding is that Emacs uses Home and End to get to the
> beginning and end of the document
That is not true for Emacs "out of the box". Maybe it was true at some
point in the past, but current versions of Emacs do not work like this.
> > I know people who don't use Emacs, but they do use Magit: they
> > start up an Emacs instance with a simple setup file that drops into
> > Magit automatically, and use it as a kind of "Git interface stand-
> > alone app".
>
> Interesting. I found a YouTube video for it:
>
> https://www.youtube.com/watch?v=X_iX5US1_xE
I've seen that one. This is better than some but to me it still gets
too far down in the weeds, certainly in the beginning. Plus he's using
Evil mode which means he's using a vi interface, not actually using
normal Emacs keybindings. IMO a good introductory video should be all
about features and not mention things like "how to move the cursor" at
all, and it shouldn't rely on highly user-specific configurations.
Also he is (by his own admission) not a full-time developer and misses
some of the most powerful parts of Magit, such as staging individual
chunks of diffs, using interactive rebase to reorder changes, etc.
There is also Forge https://github.com/magit/forge which provides a
Magit-based integration with forges like GitLab and GitHub: it allows
fetching issues, managing PRs, etc. I don't use this much myself.
> I can see why you like it, but I still prefer the command-line. Using
> it would involve learning lots of new shortcuts.
That is true, although they're pretty mnemonic: "s" to stage, "u" to
unstage, "p" to push, "f" to fetch, etc. etc.
There is also great pop-up help by typing "?".
More information about the ubuntu-users
mailing list