How to use emacsclient on root files, using sudo and a single daemon
Asked Answered
H

2

16

I always run emacs as daemon but when I want to make something alike

sudo emacsclient /etc/make.conf

I can't do it because root is using another emacs and I don't really want to run 2 daemons or wait usual emacs load for simple file.

I need some solution alike emacsclientsudo /etc/make.conf :) to edit system files with user emacs client.

Hearsh answered 17/4, 2012 at 11:28 Comment(0)
P
23

add to your ~/.profile:

alias E="SUDO_EDITOR=\"emacsclient\" sudo -e"

then

E /etc/hosts

You should be able to use sudoedit instead of sudo -e, but I couldn't find the former on my Mac.

Parasang answered 17/4, 2012 at 12:40 Comment(1)
Neat. I think you can just set SUDO_EDITOR in your init scripts and directly call sudo -e or sudoedit on whatever file you want though.Mythologize
M
10

I'm not sure about it directly but here's a trick

emacsclient -e '(find-file "/sudo::/etc/passwd")'

Uses tramp and the sudo method to open /etc/passwd as root.

You can alias this and use it directly from your shell.

Mythologize answered 17/4, 2012 at 11:36 Comment(3)
The question is not clear, whether Emacs server runs as root or not. The other answer assumes that the server runs as root. Your answer assumes that the server runs unprivileged.Finegan
This doesn't work for me on Spacemacs ... sudo -e does, though.Tanager
How to wait for Ctrl-x #?Finegan

© 2022 - 2024 — McMap. All rights reserved.