Emacs: edit root files with no tramp

2019-04-09 16:07发布

Here's a way to open root file in a non-root run emacs:

 erf () { SUDO_EDITOR="emacsclient -n -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground

It asks a root password, and once You enter it it opens a copy of file in /tmp. Example:

$ cd /etc/apt
$ erf sources.list

opens: sourcesXXiOSmYN.list. So I edit the thing, and save it with C-x C-s -- but it's not saved:

$ sudoedit: sources.list unchanged

How do I make it save the thing? (the feature will be very neat)

Edit:

 erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $@; } ;; erf = Emacs Root Foreground

sovles it. Save a file and either -- kill the buffer or C-x #. It works.

2条回答
虎瘦雄心在
2楼-- · 2019-04-09 16:24

I don't use emacs, but what's wrong with

export EDITOR=emacs
# or export VISUAL=emacs
sudoedit some-root-file

? Put the export line(s) in your .bashrc and you're done.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-04-09 16:30

Drop the -n option. FWIW I use,

alias E="SUDO_EDITOR=\"emacsclient -c -a emacs\" sudoedit"

taken somewhere...

查看更多
登录 后发表回答