Emacs: edit root files with no tramp

二次信任 提交于 2019-12-21 19:39:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!