[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bind commands that change buffer contents to `undefined' when read-only?
From: |
Drew Adams |
Subject: |
bind commands that change buffer contents to `undefined' when read-only? |
Date: |
Sat, 22 Sep 2007 15:16:14 -0700 |
>> Generalizing this (note: a topic change) -
>
> Please start another thread with this, with a different subject.
OK. The rest of this is from my mail with subject "TAB for editing modes":
------8<------------------
Why not bind commands that modify buffer content to `undefined' when the
buffer is read-only? I do that in read-only buffers such as
*Buffer List*. Besides preventing the read-only error message, it prevents
users from thinking that a key sequence might be unavailable for their own
use.
I made this suggestion on 2004-10-17 in thread "bind buffer-modifying keys
to `undefined' in buffers where nomodification should occur?". Kim suggested
perhaps using `ignore' instead of `undefined', but he pointed out some
problems with `C-h b' for `ignore'. RMS said he didn't want to make such a
change then, because the release of Emacs 22 was imminent (;-)). Perhaps
this or something similar could be reconsidered now.
FWIW, I do this rather primitively, by just having a list of
buffer-modifying commands and then binding them to `undefined'. Perhaps a
better mechanism could be devised. Here is the code I use. As you can see, I
neglected to include `indent-for-tab-command', and there are no doubt other
buffer-modifying commands that might be included.
(defun undefine-keys-bound-to (command keymap &optional oldmap)
"Bind to `undefined' all keys currently bound to COMMAND in KEYMAP.
If optional argument OLDMAP is specified, rebinds in KEYMAP as
`undefined' all keys that are currently bound to COMMAND in OLDMAP but
are not bound in KEYMAP."
(unless (where-is-internal command keymap 'first-only)
(substitute-key-definition command 'undefined keymap oldmap)))
(defcustom buffer-modifying-cmds
'(delete-char quoted-insert transpose-chars kill-region yank kill-word
indent-new-comment-line kill-sentence fill-paragraph
transpose-words yank-pop zap-to-char just-one-space
indent-for-comment delete-indentation kill-sexp split-line
transpose-sexps backward-kill-sentence)
"*Buffer-modifying commands used in `undefine-killer-commands'."
:type '(repeat symbol))
(defun undefine-killer-commands (keymap &optional oldmap)
"Bind `undefined' to KEYMAP keys bound to buffer-modifying commands.
If optional arg OLDMAP is specified, rebinds in KEYMAP as `undefined'
the keys that are currently bound to buffer-modifying commands in
OLDMAP but are not bound in KEYMAP. The buffer-modifying commands
used: `buffer-modifying-cmds'."
(mapcar (lambda (cmd) (undefine-keys-bound-to cmd keymap oldmap))
buffer-modifying-cmds))
A typical use:
(undefine-killer-commands Buffer-menu-mode-map (current-global-map))
Re: TAB for non-editing modes, Richard Stallman, 2007/09/22
- Re: TAB for non-editing modes, Dan Nicolaescu, 2007/09/22
- Re: TAB for non-editing modes, Dan Nicolaescu, 2007/09/22
- bind commands that change buffer contents to `undefined' when read-only?,
Drew Adams <=
- RE: bind commands that change buffer contents to `undefined' whenread-only?, Drew Adams, 2007/09/22
- RE: bind commands that change buffer contents to `undefined'whenread-only?, Drew Adams, 2007/09/22
- Re: bind commands that change buffer contents to `undefined'whenread-only?, Stefan Monnier, 2007/09/22
- RE: bind commands that change buffer contents to `undefined' when read-only?, Drew Adams, 2007/09/22
- Re: bind commands that change buffer contents to `undefined' when read-only?, Stefan Monnier, 2007/09/23
- RE: bind commands that change buffer contents to `undefined' when read-only?, Drew Adams, 2007/09/23
- Re: bind commands that change buffer contents to `undefined' when read-only?, Stefan Monnier, 2007/09/23
- RE: bind commands that change buffer contents to `undefined' when read-only?, Drew Adams, 2007/09/23
RE: bind commands that change buffer contents to `undefined' when read-only?, Davis Herring, 2007/09/24
RE: bind commands that change buffer contents to `undefined' when read-only?, Drew Adams, 2007/09/24