0

I use the following alias:

alias e='emacsclient -a '\'''\'' -t alias sudo='sudo ' 

That way I can execute both, commands and aliases, with sudo, including e, which launchs the emacs server if it is not launched yet.

The thing is that, if I have the emacs-daemon running, for example because I have edited a file before, and then I open the editor with sudo, every file which is written by the server, like .historian, changes its owner to root. So, when trying to launch the server again, the server is launched but the client doesn't show up (it frozes just after launching the server) and I have to open the client in another terminal, but emacs doesn't behave correctly anyway. For example, the minibuffer is incorrectly displayed for commands that requires input, like C-x C-f.

How can I solve that situation? How could I launch an emacs server per user basis? Or there's any other solution?e

1
  • n.b. You're missing a final ' on your alias e definition -- but also, alias e="emacsclient -a '' -t" is a much simpler way to write that. Commented Aug 30, 2020 at 4:15

2 Answers 2

1

This is the solution I use to edit files as root using a single running emacs daemon:

export EDITOR="emacsclient --tty --create-frame" alias e="$EDITOR" alias E=sudoedit 
0

Provisionally, I have end up with the following function bound to C-x C-F:

(defun reopen-with-sudo () (interactive) (if buffer-file-name (counsel-find-file (concat "/sudo:root@localhost:" buffer-file-name)) (counsel-find-file (concat "/sudo:root@localhost:" (ido-real-file-name "File:"))))) 

which solves the problem without any apparent downside, except that the file will be opened twice in two different buffers.

1
  • You could use find-alternate-file to reuse just a single buffer for the file. Commented May 8, 2019 at 0:30

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.