[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Auto-Prompt for Password and Raise Privilegies when needed
From: |
Nordlöw |
Subject: |
Re: Auto-Prompt for Password and Raise Privilegies when needed |
Date: |
Tue, 4 May 2010 07:56:09 -0700 (PDT) |
User-agent: |
G2/1.0 |
On May 4, 4:00 pm, quodlibetor <quodlibe...@gmail.com> wrote:
> > 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.
You are right! This is what I was looking for.
But as you say, the first-edit-read-only-file-hook still remains to be
implemented. For now we could advice
- self-insert-command
- delete-char, delete-word, etc.
- tranpose, etc.
of course it is impossible to keep track of all these functions.
We should add a hook somewhere in the c sources that detects any
buffer modifications. Something for the Emacs developers...
We could of course also make the query a bit more clever;
Query for permission-change only if we open a that is read-only by
me but writable by another user or group.
But