emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: hook for buffers becoming writable/read-only


From: Steve Yegge
Subject: Re: hook for buffers becoming writable/read-only
Date: Wed, 22 Jul 2009 13:42:49 -0700

The post-command-hook approach worked like a charm.  Thanks!

-steve

On Wed, Jul 22, 2009 at 11:23 AM, Stefan Monnier <address@hidden> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]