[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hook for buffers becoming writable/read-only
From: |
Stefan Monnier |
Subject: |
Re: hook for buffers becoming writable/read-only |
Date: |
Wed, 22 Jul 2009 14:23:12 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) |
> 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