From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard Riley Newsgroups: gmane.emacs.help Subject: Re: sudo in emacs Date: Tue, 10 Jan 2012 17:33:14 +0100 Organization: aich tea tea pea dicky riley dot net Message-ID: References: <87fwfnbnlz.fsf@tsdh.uni-koblenz.de> Reply-To: help-gnu-emacs@gnu.org NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1326213237 1718 80.91.229.12 (10 Jan 2012 16:33:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Jan 2012 16:33:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 10 17:33:52 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Rkedx-0008EB-2T for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jan 2012 17:33:49 +0100 Original-Received: from localhost ([::1]:42958 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rkedw-0006xB-IR for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jan 2012 11:33:48 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:51788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rkedm-0006gq-H5 for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 11:33:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rkedd-0008En-0s for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 11:33:33 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:45799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rkedc-0008EX-RB for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 11:33:28 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Rkedb-00080f-An for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 17:33:27 +0100 Original-Received: from 85.183.18.158 ([85.183.18.158]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jan 2012 17:33:27 +0100 Original-Received: from rileyrg by 85.183.18.158 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jan 2012 17:33:27 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Original-Lines: 20 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 85.183.18.158 Mail-Copies-To: never User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:Qs19aJHRbFZfVMVjhbyU1HcKFJ8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83433 Archived-At: Tassilo Horn 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... ;)