From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Nordl=F6w?= Newsgroups: gmane.emacs.help Subject: Re: Auto-Prompt for Password and Raise Privilegies when needed Date: Wed, 5 May 2010 13:25:09 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <146fc610-6a5e-4607-b61d-248c926f1d67@b7g2000yqk.googlegroups.com> <87bpcwsncr.fsf@fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1273105099 26391 80.91.229.12 (6 May 2010 00:18:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 6 May 2010 00:18:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 06 02:18:18 2010 connect(): No such file or directory Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1O9on0-0000RR-Fe for geh-help-gnu-emacs@m.gmane.org; Thu, 06 May 2010 02:18:14 +0200 Original-Received: from localhost ([127.0.0.1]:59325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O9omy-0004zv-EA for geh-help-gnu-emacs@m.gmane.org; Wed, 05 May 2010 20:18:04 -0400 Original-Path: usenet.stanford.edu!postnews.google.com!b18g2000yqb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-NNTP-Posting-Host: 81.170.219.22 Original-X-Trace: posting.google.com 1273091109 25172 127.0.0.1 (5 May 2010 20:25:09 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 5 May 2010 20:25:09 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b18g2000yqb.googlegroups.com; posting-host=81.170.219.22; posting-account=ytJKAgoAAAA1tg4ScoRszebXiIldA5vg User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.5pre) Gecko/20100501 Ubuntu/9.10 (karmic) Namoroka/3.6.5pre,gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:177963 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:73488 Archived-At: On 5 Maj, 06:14, Stefan Monnier wrote: > > with the main problem being that `first-edit-read-only-file-hook' > > doesn't exist, and there don't seem to be any analogs. > > There's first-change-hook, which is somewhat close. > Of course, this only works if the buffer is writable (i.e. if the buffer > is read-only, attempts to modify the buffer will signal an error before > getting a chance to run this hook). > > =A0 =A0 =A0 =A0 Stefan This works really nicely for me. (defvar post-ro-edit-hook nil "Hooks to run first time a root-read-only buffer gets modified.") (defun post-ro-edit-hook () "Hook run when the user tries to modify a read-only buffer file owned by root." (when (y-or-n-p (format "Reopen buffer file %s as root to edit? " buffer-file-name)) (let ((p (point))) (find-alternate-file (concat "/sudo::" buffer-file-name)) ;open with sudo instead (goto-point p)) ;goto same point in reopened file so that pending changes occurr at right position (unwind-protect (run-hooks 'post-ro-edit-hook)))) (defun find-file-auto-raise-privs () "If current buffer is read-only, but writable by root, raise priviligies." (interactive "") (when (and buffer-read-only ;buffer is readonly buffer-file-name ;buffer is a file (not (file-writable-p buffer-file-name)) ;file it is not writable (=3D (nth 2 (file-attributes buffer-file-name)) 0)) ;file is owned by root (toggle-read-only -1) ;make it writable so that `before-change- functions' is run (add-hook 'first-change-hook 'post-ro-edit-hook nil t) ;activate before-change-hook locally in this buffer )) (add-hook 'find-file-hook 'find-file-auto-raise-privs) /Per