From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: sudo in emacs Date: Tue, 10 Jan 2012 16:09:44 +0100 Message-ID: <87fwfnbnlz.fsf@tsdh.uni-koblenz.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1326208225 25973 80.91.229.12 (10 Jan 2012 15:10:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Jan 2012 15:10:25 +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 16:10:22 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 1RkdLA-0006Mh-60 for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jan 2012 16:10:20 +0100 Original-Received: from localhost ([::1]:47763 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkdL9-0001j8-L8 for geh-help-gnu-emacs@m.gmane.org; Tue, 10 Jan 2012 10:10:19 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:36939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkdL1-0001io-MP for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 10:10:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RkdKr-00088v-Qw for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 10:10:11 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:36028) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RkdKr-00088H-Ls for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 10:10:01 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RkdKm-0006B6-RV for help-gnu-emacs@gnu.org; Tue, 10 Jan 2012 16:09:56 +0100 Original-Received: from tsdh.uni-koblenz.de ([141.26.67.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jan 2012 16:09:56 +0100 Original-Received: from tassilo by tsdh.uni-koblenz.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Jan 2012 16:09:56 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: tsdh.uni-koblenz.de User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:GJg4MAIzOxZNM9pNPBSDK9DTb3U= 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:83432 Archived-At: Chris Poole writes: > On Thu, Jan 5, 2012 at 4:47 PM, Rajanikanth Jammalamadaka > wrote: > >> Is there a way I can do this using tramp? > > On a file by file basis, I use this: > >     (defun find-alternative-file-with-sudo () >       "Open the current buffer with privileges given by `sudo'." >       (interactive) >       (when buffer-file-name >         (find-alternate-file >          (concat "/sudo:root@localhost:" >         buffer-file-name)))) First of all as an answer to the OP, you can just do C-x C-f /sudo:userid@localhost:/foo/bar/baz.txt RET Because I'm lazy, I have a similar hack in my .emacs: --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--- So if I try to open a file for which I don't have permissions for, I'm queried if I want to open it as root using the sudo tramp method. Bye, Tassilo