* hook for buffers becoming writable/read-only
@ 2009-07-22 3:39 Steve Yegge
2009-07-22 17:44 ` Lennart Borgman
2009-07-22 18:23 ` Stefan Monnier
0 siblings, 2 replies; 4+ messages in thread
From: Steve Yegge @ 2009-07-22 3:39 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 933 bytes --]
I have a minor mode that wishes to disable itself when the bufferbecomes
writable, but I do not see a way to do it.
The closest existing scenario I can see is view-mode, but view-mode
is special-cased in toggle-read-only, rather than listening on a hook.
This does not seem clean.
Moreover, most modes do not use toggle-read-only; they set the
buffer-read-only variable directly. This has the (in my mind) unwanted
side-effect of leaving a writable buffer in view-mode if it is made
writable by setting the variable directly.
The semantics are admittedly a bit vague with respect to temporary
changes from let-binding buffer-read-only or inhibit-read-only, but
I would be satisfied if the hook were run on any persistent change
to the buffer-read-only variable.
Perhaps rather than creating a new hook, we could simply call the
before-change-functions and after-change-functions when the buffer
read-only status changes.
-steve
[-- Attachment #2: Type: text/html, Size: 1174 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: hook for buffers becoming writable/read-only
2009-07-22 3:39 hook for buffers becoming writable/read-only Steve Yegge
@ 2009-07-22 17:44 ` Lennart Borgman
2009-07-22 18:23 ` Stefan Monnier
1 sibling, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2009-07-22 17:44 UTC (permalink / raw)
To: Steve Yegge; +Cc: emacs-devel
On Wed, Jul 22, 2009 at 5:39 AM, Steve Yegge<stevey@google.com> wrote:
> I have a minor mode that wishes to disable itself when the buffer
> becomes writable, but I do not see a way to do it.
Don't you have to define "when" a bit closer here?
> The closest existing scenario I can see is view-mode, but view-mode
> is special-cased in toggle-read-only, rather than listening on a hook.
> This does not seem clean.
> Moreover, most modes do not use toggle-read-only; they set the
> buffer-read-only variable directly. This has the (in my mind) unwanted
> side-effect of leaving a writable buffer in view-mode if it is made
> writable by setting the variable directly.
> The semantics are admittedly a bit vague with respect to temporary
> changes from let-binding buffer-read-only or inhibit-read-only, but
> I would be satisfied if the hook were run on any persistent change
> to the buffer-read-only variable.
> Perhaps rather than creating a new hook, we could simply call the
> before-change-functions and after-change-functions when the buffer
> read-only status changes.
> -steve
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: hook for buffers becoming writable/read-only
2009-07-22 3:39 hook for buffers becoming writable/read-only Steve Yegge
2009-07-22 17:44 ` Lennart Borgman
@ 2009-07-22 18:23 ` Stefan Monnier
2009-07-22 20:42 ` Steve Yegge
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2009-07-22 18:23 UTC (permalink / raw)
To: Steve Yegge; +Cc: emacs-devel
> I have a minor mode that wishes to disable itself when the buffer becomes
> writable, but I do not see a way to do it.
Indeed, there is no such hook. I can think of two ways to get something
similar:
- use the usual post-command-hook to check the state of the
variable and react accordingly.
- if your minor mode is mostly a bunch of key-bindings, you can do what
I did in diff-mode and use buffer-read-only as the minor-mode
variable:
[...]
;; Neat trick from Dave Love to add more bindings in read-only mode:
(lexical-let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
(add-to-list 'minor-mode-overriding-map-alist ro-bind)
;; Turn off this little trick in case the buffer is put in view-mode.
(add-hook 'view-mode-hook
(lambda ()
(setq minor-mode-overriding-map-alist
(delq ro-bind minor-mode-overriding-map-alist)))
nil t))
[...]
-- Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: hook for buffers becoming writable/read-only
2009-07-22 18:23 ` Stefan Monnier
@ 2009-07-22 20:42 ` Steve Yegge
0 siblings, 0 replies; 4+ messages in thread
From: Steve Yegge @ 2009-07-22 20:42 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1140 bytes --]
The post-command-hook approach worked like a charm. Thanks!
-steve
On Wed, Jul 22, 2009 at 11:23 AM, Stefan Monnier
<monnier@iro.umontreal.ca>wrote:
> > I have a minor mode that wishes to disable itself when the buffer becomes
> > writable, but I do not see a way to do it.
>
> Indeed, there is no such hook. I can think of two ways to get something
> similar:
> - use the usual post-command-hook to check the state of the
> variable and react accordingly.
> - if your minor mode is mostly a bunch of key-bindings, you can do what
> I did in diff-mode and use buffer-read-only as the minor-mode
> variable:
>
> [...]
> ;; Neat trick from Dave Love to add more bindings in read-only mode:
> (lexical-let ((ro-bind (cons 'buffer-read-only diff-mode-shared-map)))
> (add-to-list 'minor-mode-overriding-map-alist ro-bind)
> ;; Turn off this little trick in case the buffer is put in view-mode.
> (add-hook 'view-mode-hook
> (lambda ()
> (setq minor-mode-overriding-map-alist
> (delq ro-bind minor-mode-overriding-map-alist)))
> nil t))
> [...]
>
>
> -- Stefan
>
[-- Attachment #2: Type: text/html, Size: 1564 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-07-22 20:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-22 3:39 hook for buffers becoming writable/read-only Steve Yegge
2009-07-22 17:44 ` Lennart Borgman
2009-07-22 18:23 ` Stefan Monnier
2009-07-22 20:42 ` Steve Yegge
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).