[emacs-berlin] Automatic sudo

Michael Albinus michael.albinus at gmx.de
Mon Aug 24 12:07:13 UTC 2015


Arne Brasseur <arne.brasseur at gmail.com> writes:

> Hi everyone,

Hi Arne,

> I would love to get some feedback on this snippet. What it does is,
> whenever you try to type in a read-only buffer, it will ask if you
> want to re-open the file with sudo. I think it's pretty cool, and it
> turned out to be relatively easy to set up.

Well, you might check whether `path' is already a remote file name. In
this case, you do either nothing, or you try to open the file on the
remote machine as root.

It would also be nice, if the cursor goes to the same position in the
new buffer. And maybe even inserts the character you have typed :-)

> The only downside I've noticed so far is that e.g. pressing enter does
> not work, because that issues the command "newline" instead of
> "self-insert-command". You could of course repeat this snippet for
> newline, and indent-for-tab-command, etc. Does anyone have a better
> idea?

Well, what about remapping the commands? I believe it is more clean than
an advice. See (info "(elisp) Remapping Commands")

> Cheers,
> Arne

Best regards, Michael.


More information about the emacs-berlin mailing list