Other emacsclient

After using emacs on a daily basis for the last six months, although not having used emacsclient so far, I'm wondering if it's worth investigating.

Any opinions would be welcomed.
 
you really should be using emacsclient


you have emacs running as a server which the emacsclient connects to
this lets you open multiple emacsclient windows much faster than opening another instance of emacs

here's the command i use as a keyboard shortcut
to open emacs using emacsclient

what it does is start emacs running as a server in the background if it isnt already
and then creates a new emacs frame

Code:
emacsclient -a= -c

which is the shortened version of this command

Code:
emacsclient --create-frame --alternate-editor=""

you dont need to start the server with this command in your emacs init.el
because you start the emacs server if it isnt running with emacsclient

Code:
(server-start)

my emacs config


my dotfiles


emacs notes


emacs videos


emacs screenshot showing an rss feed from youtube
which displays the title, date, duration and thumbnail

the youtube video is opened with mpv
and you can also control mpv from within emacs

if you look at the modeline
it also displays current video position and duration and title using playerctl and mpris
you need to install mpv-mpris and playerctl on freebsd

emacs.png

using these package

elfeed elfeed-tube elfeed-tube-mpv mpv
doom-modeline doom-modeline-now-playing

and a transcript of the video which can scroll
as the video is playing and highlight the text that is spoken

emacs2.png


emacs3.png
 
Many thanks NapoleonWils0n for this comprehensive guide. I'm very much a novice when it comes to emacs, and a lot of this is way over my head, but hopefully some of it will sink in.


I use emacs almost all the time now, but not sure when to start it, because sometimes I do work at the command line and don't always use startx. Also, I'm only just gettng used to tmux, so what the best way to start tmux and connect to the server?
 
It's been many many years since I touched emacs but I think you can use emacs-nox in tmux if you don't use X.
emacs-client opens instantly when emacs-server runs in background, that's the reason why I did it IIRC because emacs-server is quite heavy.
 
It's been many many years since I touched emacs but I think you can use emacs-nox in tmux if you don't use X.
emacs-client opens instantly when emacs-server runs in background, that's the reason why I did it IIRC because emacs-server is quite heavy.

I use emacs -nw in tmux whether I'm in X or not and not really sure what emacs-nox would give me.
 
if you run emacs on a headless server installing emacs-nox could avoid to pull down all the X11 dependencies, other than that I don't think it'll change anything.
 
My two cents:

As gotnull said, on a headless machine (server) installing emacs-nox creates a much lighter-weight installation; installing the regular emacs (with X support) pulls in an enormous number of dependencies which are absolutely not needed. My personal opinion: I use the command line (non-X) version of emacs even on windowing environments, even under X or on a Mac. Like that, I have a consistent user interface, whether over ssh, local console, or in a terminal emulator. Old joke: Beware of the guy with just one gun, because he knows how to use it.

I tried using emacsclient once, maybe 15 or 20 years ago, when machines were still much slower and had less memory. I found the speedup to be minimal, and not worth the hassle. Before committing to using it, I would measure whether it's worth it.
 
BTW, why the cursor blinks on xterm when calling emacs -nw?

I have in .emacs: (blink-cursor-mode 0)

And it does not blink in console.

EDIT:

if I start xterm with "xterm -bc", then the cursor blinks in the xterm, and if I start "emacs -nw" there,
then it does not blink.

Is there any explanation for this wonderful behaviour?
 
I use emacs -nw in tmux whether I'm in X or not and not really sure what emacs-nox would give me.
I did not try a package any more since long, but I suspect that is the configuration "without toolkit".

I compile with: --without-all --with-x-toolkit=no

And get too much, of course also X.
 
I think using emacsclient is a good idea, like others said. But if you organize your Emacs setup efficiently, it won't take long to start up. Check out the attached picture. It's a 12 years old HP Probook laptop.

Nowadays, many Emacs users go for fancy literate Org configurations, but that can slow things down because Org mode needs to load at startup and it's a heavy beast. I found a better alternative: you can get similar folding capabilities with pure Emacs Lisp files using the Outshine package. Take a look at my Emacs config, it's just one .el file and it starts up a lot quicker than a fancy Org setup. https://github.com/zoliky/playground

The headlines are denoted with semicolons ;;;; . When you enable the Outshine package those headlines will act just like in Org mode, you can press TAB on them and they fold and unfold, or do that globally with SHIFT+TAB.
 

Attachments

  • fbsd.png
    fbsd.png
    164 KB · Views: 17
having your emacs config in a literate org file doesnt slow down starting emacs
because you tangle all the source code blocks into place, so there is no difference in startup time


 
having your emacs config in a literate org file doesnt slow down starting emacs

That's true, but it introduces an unnecessary layer of abstraction. I find myself constantly pressing C-' in code blocks, which can lead to more errors, such as accidentally uncommenting blocks by mistyping. Not a fan of it, to be honest. Opening a pure Lisp file just feels more natural and is much easier to edit. However, everyone has their own preferences. I also began with a literate config, so I understand the appeal. Prof. Colin Mclear wrote more about this subject in a reddit post.
 
the advantage of keeping all of your config in a org file
is you have one file to edit and then tangle into place

much faster than burrowing through directories and editing files one by one
which is harder to keep track of the changes

also it acts as a dashboard so you can see at a glance the config files that you use

i also tangle the config files into my git repo alongside the org file
that way i have layout of the directory structure in the git repository

i use org mode to manage all my root dotfiles as well
so rather than editing the files directly i edit them in the org file and tangle them into place

that lets me keep everything under version control and is very easy to deploy
 
the advantage of keeping all of your config in a org file
is you have one file to edit and then tangle into place

much faster than burrowing through directories and editing files one by one
which is harder to keep track of the changes
You can achieve the same with Lisp folding. I mentioned the outshine package for that but as far as I know since Emacs 29.x native folding has been added to Emacs core. You can keep everything in one file, there is no need to split up, and have a table of contents just like Org mode. You can even move, refile, or sort entire headings and their content easily. But as I mentioned, it's really up to each individual. If Org works for you, then by all means, stick with it. I don't think there's a right or wrong method.

foldunfold.png
 
the advantage of keeping all of your config in a org file
is you have one file to edit and then tangle into place

You seem to have things very well organised.

I can see that I have a steep learning cliff ahead of me.

Apologies in advance for lots of questions :) ...
 
If I'm going to use emacs client, presumably I need to start the server at some point, but where is the most appropriate place?
Can I add an entry to /etc/rc.conf ?

And if I'm using Doom emacs, do I just start it using emacsclient ?
 
There are various ways to run it:

1. Add /usr/bin/emacs --daemon to your ~/.xinitrc so that the server starts when you start your desktop
2. Run the command M-x server-start in an existing Emacs process
3. Put the expression (server-start) in your init file and restart Emacs

Once an Emacs server is started, you can use emacsclient to connect to the Emacs process and tell it to visit a file. You can also set the EDITOR environment variable to ‘emacsclient’, so that external programs will use the Emacs server process.

As always, the documentation is your friend: https://emacsdocs.org/docs/emacs/Emacs-Server
 
Back
Top