From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Steve Yegge <stevey@google.com>
Cc: emacs-devel@gnu.org
Subject: Re: hook for buffers becoming writable/read-only
Date: Wed, 22 Jul 2009 14:23:12 -0400 [thread overview]
Message-ID: <jwv7hy0shpt.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <9c768dc60907212039k5025c1adq583f00898e18cf82@mail.gmail.com> (Steve Yegge's message of "Tue, 21 Jul 2009 20:39:42 -0700")
> 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
next prev parent reply other threads:[~2009-07-22 18:23 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2009-07-22 20:42 ` Steve Yegge
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv7hy0shpt.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=stevey@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).