unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: <emacs-devel@gnu.org>
Subject: bind commands that change buffer contents to `undefined' when read-only?
Date: Sat, 22 Sep 2007 15:16:14 -0700	[thread overview]
Message-ID: <BNELLINCGFJLDJIKDGACAEPHCCAA.drew.adams@oracle.com> (raw)
In-Reply-To: <200709222151.l8MLpUkY014551@oogie-boogie.ics.uci.edu>

>> 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))

  reply	other threads:[~2007-09-22 22:16 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-22  1:18 TAB for non-editing modes Dan Nicolaescu
2007-09-22  8:22 ` Lennart Borgman (gmail)
2007-09-25 20:29   ` S-SPC for non-editing modes (was: TAB for non-editing modes) Juri Linkov
2007-09-25 21:14     ` Drew Adams
2007-09-25 21:59       ` S-SPC for non-editing modes Juri Linkov
2007-09-25 22:12         ` Drew Adams
2007-09-25 22:09       ` S-SPC for non-editing modes (was: TAB for non-editing modes) Andreas Schwab
2007-09-22 15:47 ` TAB for non-editing modes Richard Stallman
2007-09-22 16:35   ` Dan Nicolaescu
2007-09-22 19:01     ` Drew Adams
2007-09-22 21:23       ` Lennart Borgman (gmail)
2007-09-22 21:40         ` Drew Adams
2007-09-22 21:51       ` Dan Nicolaescu
2007-09-22 22:16         ` Drew Adams [this message]
2007-09-23  0:37           ` bind commands that change buffer contents to `undefined' whenread-only? Drew Adams
2007-09-23  1:20             ` bind commands that change buffer contents to `undefined'whenread-only? Drew Adams
2007-09-23  1:49               ` Stefan Monnier
2007-09-23  2:18                 ` bind commands that change buffer contents to `undefined' when read-only? Drew Adams
2007-09-23 18:16                   ` Stefan Monnier
2007-09-23 20:42                     ` Drew Adams
2007-09-24  1:25                       ` Stefan Monnier
2007-09-24  2:02                         ` Drew Adams
2007-09-24 15:24                       ` Davis Herring
2007-09-24 16:12                         ` Drew Adams
2007-09-24 17:38                           ` Davis Herring
2007-09-24 21:49                             ` Drew Adams
2007-09-24 18:14                           ` Stefan Monnier
2007-09-25 10:44                             ` Richard Stallman
2007-09-25 18:00                               ` bind commands that change buffer contents to `undefined' whenread-only? Drew Adams
2007-09-24 18:19                     ` bind commands that change buffer contents to `undefined' when read-only? Richard Stallman
2007-09-25 14:15                       ` Stefan Monnier
2007-09-22 22:44         ` TAB for non-editing modes Drew Adams
2007-09-23 14:48           ` Bastien
2007-09-23 23:59           ` Juri Linkov
2007-09-23 15:05       ` Richard Stallman
2007-09-23 16:43         ` Drew Adams
2007-09-24  0:11           ` Johan Bockgård
2007-09-24  0:33             ` Drew Adams
2007-09-24  0:46               ` Johan Bockgård
2007-09-23 15:04     ` Richard Stallman
2007-09-24  0:56       ` Dan Nicolaescu
2007-09-24 18:20         ` Richard Stallman

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=BNELLINCGFJLDJIKDGACAEPHCCAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /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).