4

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.

Adobe
  • 12,967
  • 10
  • 85
  • 126

2 Answers2

5

Drop the -n option. FWIW I use,

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

taken somewhere...

thisirs
  • 790
  • 6
  • 6
0

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.

dhardy
  • 11,175
  • 7
  • 38
  • 46
  • I just tried Your solution with `export EDITOR=emacsclient` (one needs `emacsclient` instead of `emacs` in order to open the file in the running emacs). It seem to be working. – Adobe May 10 '13 at 10:53