emacs-devel
[Top][All Lists]
Advanced

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

RE: TAB for non-editing modes


From: Drew Adams
Subject: RE: TAB for non-editing modes
Date: Sat, 22 Sep 2007 12:01:08 -0700

>   >     TAB does not do anything for pcvs, dired, log-view and maybe
others
>   >     It would be nice if TAB would do something for these modes too.
>   >
>   > It seems harmless to add that functionality in modes that are
>   > read-only and have distinguishable links.  I don't see that this
>   > is very useful in Dired, though.
>
> Why not? I'd rather have TAB run dired-next-line instead of throwing
> an error "Buffer is read-only" as it does now.

That is truly a waste of a key binding, IMO. `n' does that already. I have
nothing against giving `TAB' a useful binding in Dired, but there is no
sense duplicating `n' for that.

If no truly useful Dired binding for `TAB' can be found now, then let's
leave it alone - something will come up eventually. The problem with binding
it now to something that is not particularly useful is that that binding can
become cast in stone, a sacred cow that is later defended against replacing
with a truly useful binding.

If we don't bind `TAB' in Dired to something useful now, we might consider
unbinding it there, more precisely, binding it to `undefined'. It is silly
for `TAB' to invoke `indent-for-tab-command' in Dired.


Generalizing this (note: a topic change) -

Similarly for other bindings that invoke commands that modify the buffer -
why not bind them to `undefined'? 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 via email to

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