23

[NOTE] this answer was heavily edited to follow the updates of with-editor developments. Most comments likely won't make much sense anymore. There are some new comments which do make sense. Magit contains a library named with-editor available at https://github.com/magit/with-editor which allows you to use your local Emacs as an $EDITOR on remote machines ...


21

You cannot use emacsclient to connect to an Emacs instance running on a remote computer. This client-server concept is related to (local) processes, not network nodes. However, you can use various network technologies to log in to the remote computer, attach to an emacs server running there and display the emacsclient's screen locally. Depending on the ...


16

I'm using Ubuntu, so the location of the desktop file may be different but I think the contents should be similar. $ cat ~/.local/share/applications/emacsclient.desktop #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Name=GNU Emacs 24 GenericName=Text Editor Comment=View and edit files MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;...


13

Interestingly enough, there appears to be no built-in function to do that. The following code works by inserting a unique marker on the buffer-undo-list at the beginning of a collapsible block, and removing all boundaries (nil elements) at the end of a block, then removing the marker. In case something goes wrong, the marker is of the form (apply identity ...


13

I do this by starting an emacs daemon when I login. Where you put this command depends on your desktop manager. I use i3, which is configured to run a script on login that includes the following: emacs --daemon & With that, emacs is always running in the background, and I open a new client with emacsclient -c -n, bound to a convenient keybinding in the ...


11

I'm guessing that you are not really looking for a way to "execute the hook only once". I'm guessing that you are looking for a way to execute that particular function only once, whenever the hook is run. The conventional, and simple, answer to that question is for your function to remove itself from the hook, after carrying out the one-time action that ...


11

You might be able to use the server-switch-hook and raise the frame. Something like: (add-hook 'server-switch-hook #'raise-frame) If that leaves you without focus on the new frame you might try something like this instead: (add-hook 'server-switch-hook (lambda () (select-frame-set-input-focus (selected-frame)))) If you are looking to have a shell command ...


10

Emacs has in-built support for many databases, including Postgres. M-x sql-postgres RET


9

Probably not what you asked for but assuming you have ssh setup with X-forwarding, you could start emacsclient on the server and forward it to remote DISPLAY. (Disclaimer: code typed directly into webform) local> ssh server -f emacsclient -c --display=$DISPLAY


9

Set VISUAL to emacsclient -c (or some other variation without -n). The option -n causes emacsclient to return as soon as it's contacted the running Emacs instance to tell it to edit the file. The program calling the editor (here, zsh, but this applies equally to any other program that invokes $VISUAL) knows that you've finished editing because the program ...


8

Nothing in your function tells Emacs where to insert the text, you need to tell it where to go. If you’d like Emacs to place this link in a buffer named BUFFER-NAME (which you know will be open), you can use with-current-buffer. The following code inserts the link wherever point happens to currently be in a window displaying that buffer. If no window ...


7

Your included option of -c is causing this. Per the man page, -c, --create-frame create a new frame instead of trying to use the current Emacs frame. Remove this option from your command and Emacs should refrain from creating a new frame (AKA Window).


7

Check the manual for initial-buffer-choice If non-nil, this variable is a string that specifies a file or directory for Emacs to display after starting up, instead of the startup screen. If its value is a function, Emacs calls that function which must return a buffer which is then displayed. If its value is t, Emacs displays the *scratch* buffer. The web ...


7

exec-path-from-shell provides the exec-path-from-shell-copy-env command, which lets you copy the value of environment variables to Emacs sessions. For instance, M-x exec-path-from-shell-copy-env RET FOO sets the value of $FOO in Emacs as well. Note that exec-path-from-shell-copy-env spawns a new shell to extract the value of the environment variable. ...


7

I think one of the things unclear from the FAQ is the necessity that both server and client be resolveable from each other. You can see this thread from 2009. Eventually, back then I did get it to work, but now I do see the same as the OP. This is what I tried: setup.el: (require 'server) (setq server-name "sx-test" ; name of the server ...


7

Some packages managers provides two different Emacs, emacs and emacs-nox. The core is the same and behave in a very similar way. The nox version (no X means without X11 support) and should be installed on systems that don't provide a X Window System. These nox versions are compiled without support of X11. The standalone version can be run in the terminal ...


7

Run this in terminal (copy-paste it, then press Enter): cat - <<EOFEOF > ~/.local/share/applications/my_emacsclient.desktop [Desktop Entry] Name=my Emacsclient Exec=/usr/bin/emacsclient --alternate-editor="" %F Icon=emacs Type=Application EOFEOF Then open your file-manager and change the default program for opening that file type(s) you desire, to ...


7

If "start emacs gui in a similar fashion" is hoping to create a gui frame backed by the same daemon, then alias ec="emacsclient --create-frame" will instantiate another emacs frame backed by the same daemon. --create-frame can also be abbreviated with -c. -t or -nw or --tty are requesting the default for emacsclient which is to open another frame in a tty ...


6

I really don't mind Emacs.app always running, but the fact that I couldn't close the window without accidentally killing the Emacs server was annoying. And even if you try really hard to kill the last frame, it still doesn't let you: "Attempt to delete the sole visible or iconified frame". ...So we cheat. This solution just hides Emacs (like Command+h) when ...


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

Essentially, find-alternate-file kills the current buffer and immediately opens another file (creating a new buffer in its stead). Normally, this is fine. When the buffer is killed, Emacs switches to the last most recent buffer, and then immediately switches to the new buffer. In emacsclient, things work differently. If you kill all buffers created by that ...


6

May well be due to you're using the wrong emacsclient. I had the same (i.e., can't find socket and/or -error Unknown&_command:&_THEFILENAME Turned out I used /usr/bin/emacsclient, whereas my emacs is actually ~/Applications/MacPorts/Emacs.app/Contents/MacOS/Emacs . Creating a symlink from ~/Applications/Emacs.app/Contents/MacOS/bin/emacsclient to a ...


6

This is because last-kbd-macro is a terminal-local variable. See C-hig (elisp) Multiple Terminals There aren't a large number of such variables in Emacs, so it's easy to get caught out by the fact that they exist at all, but also very helpful to be aware of the concept, as it helps you to jump to the correct conclusion in such situations. Note that C-hv ...


6

Thunar implements Freedesktop's desktop entry specification, so a .desktop entry is the answer you are looking for. Try saving this to $XDG_DATA_HOME/applications/emacs.desktop or $HOME/.local/share/applications/emacs.desktop if you don't have that set. [Desktop Entry] Name=Emacs GenericName=Text Editor Comment=Edit text MimeType=text/english;text/plain;...


6

As mentionned in the comments, their installation is pretty much the same across Windows 8, 8.1 and 10 computers, but I prefer a slightly different method. Chocolatey offers simple and straightforward installation on Windows 7+. The downside is, you need administrator account access. The emacs package there is not always up to date, but it gets updated ...


6

This is explained in the manual here: C-hig (emacs)emacsclient Options RET The new graphical or text terminal frames created by the ‘-c’ or ‘-t’ options are considered “client frames”. Any new frame that you create from a client frame is also considered a client frame. If you type ‘C-x C-c’ (‘save-buffers-kill-terminal’) in a client frame, that ...


6

It is possible to read and write the contents of a buffer with the combination of an emacs server and an emacsclient. (If you want you can run the server as daemon.) Demo: Start emacs. M-x server-start RET starts the server. Before you start the server you can set the name through the option server-name. Create a buffer with known name, e.g. by C-x b mybuf ...


5

No, you can't "prevent emacsclient from blocking other [emacsclient] instances", because that's not what's happening. emacsclient isn't running any elisp at all, so it's not the cause of the blockage. The Emacs server is running the elisp code, and Emacs is single-threaded -- so if the server thread is blocked then none of the clients will be receiving any ...


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

As a workaround, the following can be used (Linux, Bash): First run printenv -0 > env.txt from the Bash terminal window, Then from within Emacs, run (defun my-update-env () (interactive) (let ((str (with-temp-buffer (insert-file-contents "env.txt") (buffer-string))) lst) (setq lst (split-string str "\000")) (...


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