Using Emacs as $EDITOR
magnus.therning.org
magnus.therning.org
Piece of fun trivia: EMACS used to have a mode for use on a printing terminal. It worked, as long as you had an idea of what your file looked like, same as any other non-visual editor (like ed before a display mode was grafted onto it to form vi). Of course this was as crazy as using vi on a printing terminal, since EMACS started out as an easier way to use TECO after a visual mode had been added to that. I guess the printing mode was worth it for EMACS users who never learned TECO.
More usefully it had a "slow terminal" mode. Printing terminals were slow, but many people connected to computers at 300 baud or even slower! So in slow terminal mode you could use the full display power of EMACS but it was very selective about how it updated your display. Back then most terminals had very limited cursor control, and you couldn't always change an arbitrary character. Still, avoiding a full screen repaint at 110 baud was a win.
I doubt either of these modes survived the relatively recent (1980s) ports of emacs (as it is now known) to C/Lisp. But a special line for single-line editing through an emacsclient could be a win in this case.
Searching incrementally on slow terminals, such as displays connected to remote machines over slow connection, could be annoying due to the need to redraw large portions of the display as the search proceeds. Emacs provides a special display mode for slow terminals, whereby search pops up a separate small window and displays the text surrounding the match in that window.
— <https://www.gnu.org/software/emacs/manual/html_node/emacs/Se...>
In a normal terminal control-r <characters> recalls the last command with those keys, and control-p/n will go back/forward in the history.
with the shell buffer I move upwards in the buffer to recall a command.
(is there a way to configure this differently?)
EDIT: ok it seems like meta-r and meta-p/n do the same thing - kind of.
hmmm, but meta-r doesn't seem to recall from the shell history? It is either a different history or truncated.
It also turns emacs (server-mode) into a really great replacement for tmux/screen. tmux behaves very strangely in how it instantiates the very first window, calling the process after that window and killing that window can kill all your tmux sessions. I run emacs as a daemon on my HPC clusters and have it monitor jobs and more via vterm.
The great thing about emacs is you can use what works for you!
But TBH I mostly just use the ordinary ! syntax (e.g. `!!` or `!bla:*` or !200 etc) because it’s even faster and works fine even when no editing is available at all.
So if I used find to search for an executable it’s just so effortless to type ./`!!|head -1` rather than searching up, selecting and copying a region, going back to the end, editing it, blah blah. Or even worse, reaching for the mouse.
To be fair, I'm old and was thrilled to go from 300 to 1200 baud at one point.
Unfortunately my hands are wired for control-r (caps lock = ctrl) and not meta-r.
Hard to figure out the ROI of re-learning.
(still emacs recall history doesn't seem to reflect bash history, which I routinely set to 10k commands)
As someone who lives in org, this is the way. I'm still shell bound for a lot of things, but M-x shell is far superior, there's just no contest. Only thing that is annoying is stupid things like git diff that think they know better than you and want to do their own paging resulting in "WARNING: terminal is not fully functional". Thankfully I use EGG, but when I forget (and other things do it too), it's annoying.
(setenv "EDITOR" "/usr/bin/emacsclient -c")
If you do that, it should cause any child processes (e.g.: vterm) to inherit the replaced EDITOR variable and properly open new editor frames instead of trying to do a terminal takeover. (defun open-term-here ()
"open st in `default-directory`"
(interactive)
(call-process-shell-command
(concat "st bash -c \"cd "
default-directory
" && exec zsh\"")
nil 0)) (defun tmux-here ()
(interactive)
(if (not (eq (getenv "TMUX") ""))
(shell-command (format "tmux new-window -c %s" default-directory))
(error "Not inside a tmux session.")))
I know, I know, tmux is slow and should never be used. I like it, OK.But definitely out of the box with a stock emacs install it seems too interested in doing a bunch of stuff that gets in the way.
My EDITOR has been just regular "emacs" for years now.
That is a fair point, though not really fitting my workflow. (Also, my Emacs needs ~20 seconds to start, and I tend to have Emacs uptime of several days or sometimes even weeks.)
> I cannot stand using multiple frames on a non-daemon Emacs due to it not always being obvious when I close just a frame and when I close the whole process.
This is strange. In my Emacs, C-x 5 0 on the last frame results in "Attempt to delete the sole visible or iconified frame". (And I have `(setq confirm-kill-emacs #'yes-or-no-p)` in my init.el anyway.)
This is useful for segregating groups of work related to a set of files but I would be interested if there's anything for arbitrary unsaved buffers in general.
I’m by no means a package maniac, and I lazyload with use-package almost entirely, but a cold start still takes a second or two. To me, a choice between a second or two and instantly is a no brainer.
I run emacs as a daemon, but it doesn't have to be. You can also run `(server-mode)` from any emacs process. A nice snippet for the init.el is: `(or (server-running-p) (server-mode))` which works whether you run the daemon or not.
`alias ec="emacsclient -s console -a '' -nw -r"`
It doesn't start a new doom workspace /most/ of the time. Sometimes i'll get a new one if i've got multiple editors opening up the same file, I think. But the `-s` flag starts a console server that at least keeps those out of my main emacs window (I use the gui version from emacs-plus)
And since we're all talking about our favorite uses of $VISUAL and/or $EDITOR, this is mine:
tcv() {
if [ "$#" -ge 1 ]; then
touch $@
chmod 755 $@
${VISUAL:-`which emacs` --color=never} $@
fi
}
I use this when I want to write a shell script that's instantaneously executable. I'm much too busy to issue the chmod command after editing the file for the first time.https://www.masteringemacs.org/article/fuzzy-finding-emacs-i...
I should point out that there is exactly one case of someone implemented enough of vim to make me happy, and that's evil-mode. Even there I had to tweak some settings because the defaults were too different from vim (specifically the + and * registers behave completely wrong by default).
Also, zsh's vi bindings are surprisingly good. Obviously, it won't be useful as a full-fledged text editor. But it's more than good enough for command line editing. It even has visual mode and registers, which you rarely see implemented in an interpreter.
It's true that it requires some configuration though. At least around 20 lines. Zsh's vi mode inherits vi's quirks that are normally disabled in Vim, including the weird backspace behavior in insert mode. Those have to be overridden individually. Text objects and surround bindings need to be explicitly bound too.
I've never fully made this transition, but have at times played with it, when I've been feeling extra-emacs-excited.
https://www.masteringemacs.org/article/running-shells-in-ema...
Also, Emacs in general can't replace tabbed terminals because there are so many blocking operations that make it unresponsive for a while.
I know every few months there's a new "I'm rewriting emacs/something-like-emacs" and it's, yeah, a nogo. But I'd actually just really like it if someone really really tried and addressed some of the architecture things :-(
Not that much, as it is rather limited on the terminal.
Why are you short-circuiting the opportunity to start a vim/emacs flamewar? The authorities should revoke your ability to use either editor. And perhaps block you from using rust and c++ as well.
Just today, from this thread, I learned about 'emacsclient -t'. This was exactly what I didn't know I needed.
It opens a frame in the terminal (very quickly..) still have everything that my running GUI emacs has.
Perfect.