问题
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.
回答1:
Drop the -n option. FWIW I use,
alias E="SUDO_EDITOR=\"emacsclient -c -a emacs\" sudoedit"
taken somewhere...
回答2:
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.
来源:https://stackoverflow.com/questions/12672294/emacs-edit-root-files-with-no-tramp