Hot answers tagged

9

Simply use (daemonp) which will return t if emacs is running as a daemon.


6

Description The default behavior when invoking emacsclient is a little conservative. Check out this comment from emacsclient.c: /* Unless we are certain we don't want to occupy the tty, send our tty information to Emacs. For example, in daemon mode Emacs may need to occupy this tty if no other frame is available. */ From your description and ...


6

The functionality is built into Emacs. Run emacsclient and pass it the -a (long form --alternate-editor) option with an empty argument, and it'll start Emacs (in daemon mode, i.e. initially without any window) if it isn't already running. emacsclient -a '' # in sh syntax emacsclient --alternate-editor= # anywhere whitespace-separated ...


6

Closing The Client Keep in mind that when you are running an emacs daemon, the frame in which you are actually editing is simply a client of the server. The file is not buffered in the client, it is buffered in the server. When you close the client you are not killing the server process, nor is the file closed. The file you were editing remains open in ...


5

There is Tramp. You can edit a file on another machine using the syntax /ssh:user@machine:/path/to/file. If you take sudo instead of ssh, and empty user and machine, you can edit a local file as root. Like /sudo::/path/to/file.


5

You cannot useemacsclient this way. The Emacs Server does not create frames on the client side; it always creates them on the server-side X11 display or TTY, but the remote server doesn't have access to your local client side TTYs or X11 displays. The TCP connection of Emacs server is not intended for remote access, it's just a work around for the lack of ...


5

This answer has the general method, though the question was different than yours. You can use emacs --daemon=workspaceN combined with emacsclient -s workspaceN to have an emacs daemon on workspace N. If you need multiple, simply do workspace1, workspace2, etc. Note that the daemon name is entirely arbitrary and you can use whatever naming scheme you like. ...


5

You might check: (and (boundp 'server-process) (processp server-process) (server-running-p)) That should work provided that you've avoided starting a server in the other instances. Assuming a socket-based server, if you were to start a second Emacs instance, and forcibly delete and then restart the server process from that second instance, then ...


5

That FRAME argument to after-make-frame-functions that you're explicitly ignoring? Don't ignore it. (defun my-start-emacs (frame) "Switch client frames of an emacs daemon to the 'server' workgroup." (interactive) (with-selected-frame frame (when (daemonp) (if (not (boundp 'server-wg)) (progn (wg-create-workgroup "server"...


4

Since you said you are already using use-package, you can turn on its own verbose option that reports how long each package takes to load. Use customize-option use-package-verbose or put this in your init file: (setq use-package-verbose t) Then restart Emacs and check your *Messages* buffer. The output will look something like: Loading package dash......


4

It appears daemonp will return the name of the server. I ended up with code that looks something like (cond ((string= "org" (daemonp)) (load-theme 'solarized-light) ) (t (load-theme 'solarized-dark) ) )


4

I am unsure of how to do that strictly within Emacs, but luckily there are other ways to get what you describe. If you don't have something in your .emacs to start a server, you could always make a small script that starts up Emacs with the file you want to edit and start the server forked. Something like: #!/bin/bash emacs --eval '(server-start)' $* &...


4

After a lot of experimenting with writing wrappers around keyboard-quit (the default binding of C-g), I discovered that C-g has special behavior. If you bind C-S-g to keyboard-quit, it will not interrupt emacsclient requests. Only C-g will. In fact, C-g will do so even if you unbind it with global-unset-key! I don't know why, but in the end this gives me the ...


4

You can wrap the relevant portions of you init file in a conditional on (daemonp), whose docstring reads: Return non-nil if the current emacs process is a daemon. If the daemon was given a name argument, return that name. So: (when (daemonp) (do-server-only-stuff-here))


4

Some programs run your editor and ask you to edit some text. (For instance: writing a commit message in git when you didn't specify one in your command.) They expect you to turn off your editor when you're done with editing, but turning off your entire Emacs server would be pointless. server-edit exists so you can use Emacs with programs that work like that ...


3

Since this is running on X, it might be possible to use a program like xdotool , xdo, or wmctrl All these programs allow you to list windows, select one, and simulate typing on them. Another approach would be to run x11vnc on the remote machine and connect to it with a local vnc viewer. The referenced manual page tells you how to forward needed ports using ...


3

Add the following code to your init.el. (require 'server) (unless (server-running-p) (cond ((eq system-type 'windows-nt) (setq server-auth-dir "~\\.emacs.d\\server\\")) ((eq system-type 'gnu/linux) (setq server-auth-dir "~/.emacs.d/server/"))) (setq server-name "emacs-server-file") (server-start)) Then you can get access to server with ...


3

For me, using emacsclient with the '-n' switch prevents me from getting the "no client connection" warning. Invoking emacsclient file from the command line will open file in the current Emacs session. The command line from which you ran emacsclient will be waiting for the file to be closed by the server, and then terminate. You won't be able to execute ...


3

In a client instance the variable server-name is bound and contains the server name. (and (boundp 'server-name) server-name)


3

The directory where the socket is created is controlled by this variable: (defvar server-socket-dir (and (featurep 'make-network-process '(:family local)) (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))) "The directory in which to place the server socket. If local sockets are not supported, this is nil.") If you use tcp sockets (...


3

I used the TCP approach suggested by @wvxvw in the comments. I'm starting a TCP server inside emacs, which, when receiving a package, will eval it as elisp code. I found a piece of code for the TCP server somewhere in the internet (I can't seem to find it again, if anybody knows please leave a comment and I'll add to the answer), and made a few changes for ...


3

This should work with a fairly recent emacsclient, as long as you pass in a prefix that lets the server emacs find remote files over tramp: --tramp=/ssh:remote: I can’t remember if the feature made it in time for 26.1 or not, but it was committed in May 2017. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26591 for details. No changes should be ...


2

Use the -c option to force opening a new graphical frame.


2

If you had started the erroneous example from a terminal, you would have noticed output similiar to the following: $ emacsclient -c --eval '(helm-locate)' […] *ERROR*: Wrong number of arguments: (1 . 1), 0 Comparing the arguments both mu4e and helm-locate require (which can be easily found out with M-x find-function) reveals that while both commands are ...


2

I think that your 2nd attempt is correct. You should, however, use C-x C-c to quit Emacs and not close the frame created by emacsclient directly through the GUI. I use C-x C-c to quit Emacs and it always asks me whether I want to save my modified buffers even if they aren't the ones I'm using. On the other hand, it's to be expected that Emacs won't prompt ...


2

You'll want to look at the environment frame parameter, which the server.el code sets up whenever a frame is created for a particular client: (frame-parameter nil 'environment) This should then hold a list of strings, where some of those strings will be like "SSH_CLIENT=IP PORT1 PORT2".


2

You can either wrap your two forms in a progn: emacsclient --no-wait --eval '(progn (message "hi") (setq abc 123))' Or you can send them separately: emacsclient --no-wait --eval '(message "hi")' '(setq def 456)'


2

You can check out ob-async. It worked well for me. Someone said that you need to implement the feature for Emacs to do that. But ob-async does exactly what you want. It does run the process asynchronously so it doesn't freeze emacs. It's a package for babel and you don't need to write any LISP code. Just install ob-async using el-get or any other preferred ...


2

It's a bug. Upgrade to Emacs-25 to see if we fixed it already, and if not please M-x report-emacs-bug.


2

How to determine if serverN is already launched? server-running-p is a compiled Lisp function in ‘server.el’. (server-running-p &optional NAME) Test whether server NAME is running. Return values: nil the server is definitely not running. t the server seems to be running. something else we cannot determine whether ...


Only top voted, non community-wiki answers of a minimum length are eligible