help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sudo in emacs


From: Richard Riley
Subject: Re: sudo in emacs
Date: Tue, 10 Jan 2012 17:33:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Tassilo Horn <tassilo@member.fsf.org> writes:

> --8<---------------cut here---------------start------------->8---
> (defun th-find-file-sudo (file)
>   "Opens FILE with root privileges."
>   (interactive "F")
>   (set-buffer (find-file (concat "/sudo::" file))))
>
> (defadvice find-file (around th-find-file activate)
>   "Open FILENAME using tramp's sudo method if it's read-only."
>   (if (and (not (file-writable-p (ad-get-arg 0)))
>          (not (file-remote-p (ad-get-arg 0)))
>          (y-or-n-p (concat "File "
>                            (ad-get-arg 0)
>                            " is read-only.  Open it as root? ")))
>       (th-find-file-sudo (ad-get-arg 0))
>     ad-do-it))
> --8<---------------cut here---------------end--------------->8---

Oh, very nice. nicked... ;)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]