[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Auto-Prompt for Password and Raise Privilegies when needed
From: |
Andreas Politz |
Subject: |
Re: Auto-Prompt for Password and Raise Privilegies when needed |
Date: |
Tue, 04 May 2010 22:11:45 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Andreas Politz <politza@fh-trier.de> writes:
> quodlibetor <quodlibetor@gmail.com> writes:
>
>>> Sounds trivial. Though this may not scale well with other hooks.
>>>
>>> (defun find-file-maybe-change-me ()
>>> (when (not (file-writable-p buffer-file-name))
>>> (find-alternate-file
>>> (format "/sudo::%s" buffer-file-name))))
>>>
>>> (add-hook 'find-file-hook 'find-file-maybe-change-me)
>>
>> I think what Per was looking for was more something along the lines of
>>
>> (defun edit-read-only-file-maybe ()
>> (when (y-or-n-p "file is read-only, raise privileges to edit? ")
>> (find-alternate-file
>> (format "/sudo::%s" buffer-file-name))))
>>
>> (add-hook 'first-edit-read-only-file-hook 'edit-read-only-file-maybe)
>>
>> with the main problem being that `first-edit-read-only-file-hook'
>> doesn't exist, and there don't seem to be any analogs. Or at least I
>> can't find them.
>
We can try to implement one. I have not tested this, but the idea
should clear.
(add-hook 'find-file-hook
(unless (file-readable-p buffer-file-name)
(toggle-read-only -1)
(add-hook 'before-change-functions 'first-edit-hook nil t)))
(defvar first-edit-hook nil)
(defun first-edit-hook (&rest _)
(unwind-protect
(run-hooks 'first-edit-hook)
(remove-hook 'before-change-functions 'before-change-magic)))
-ap