I like using the arrow keys to move around so I can free up Ctrl-F
Ctrl-B Ctrl-N and Ctrl-P and rebind them for some commands that I use
often.
For instance, I have
(global-set-key "\C-n" 'other-window)
in my .emacs
This works great until I invoke another major mode.
Like in dired, the dired mode map has C-n bound to dired-next-line.
C-n runs the command dired-next-line
which is an interactive compiled Lisp function in `dired'.
(dired-next-line ARG)
Is there a way to define a key as special using global-set-key (or
otherwise) so that no other modes can override my .emacs setting?
Thanks.
-- fungsin
Down that road lies madness.
> This works great until I invoke another major mode.
See? :-)
> Like in dired, the dired mode map has C-n bound to dired-next-line.
>
> C-n runs the command dired-next-line
> which is an interactive compiled Lisp function in `dired'.
> (dired-next-line ARG)
>
>
> Is there a way to define a key as special using global-set-key (or
> otherwise) so that no other modes can override my .emacs setting?
Hmmm, maybe you could bind `C-n' etc. to some other character not likely
to be bound to a command (e.g. an ISO-8859/Unicode C1 control character
or a Unicode private use character) via keyboard-translate, then bind
the key sequence (vector) of that unused character to `other-window'.
--
Kevin
The simple answer is no (afaik).
If you want to override mode specific keys you need to do it in a mode
hook using local-set-key.
Some people recommend this syntax (define-key X-key-map 'fcn) where X
is the mode name rather than local-set-key. Both have their advantages
& dissadvantages.
Either way, modes often override the global key because, for example
moving to the next line in this particular buffer involves doing other
things besides moving point. There is no guarantee that the mode
writer put that functionality on the arrow key (for example) and so
that functionality may need to be moved by you before you override the
mode's key definition. Meaning you may need to do something like this
(local-set-key [down] (lookup-key (current-local-map) [?\C-n]))
before you do this
(local-set-key [?\C-n] 'my-custom-fcn)
I've wanted to do this but can't figure out how. Perhaps it's not
possible? I want to use keyboard-translate on named events such as
<down> <apps> <end> etc.
Can this be done?
If so, I must be using the wrong syntax. Could you give an example?
keyboard-translate only works on characters, not arbitrary events.
Maybe you can use function-key-map or key-translation-map to map such
events (more precisely, a sequence) to a different event sequence.
--
Kevin
(defvar my-map (make-sparse-keymap)
"My keymap.")
(defvar my-map-alist `((t . ,my-map))
"My keymap alist.")
(add-to-ordered-list 'emulation-mode-map-alists 'my-map-alist 100)
(define-key my-map [(control n)] 'other-window)
I tried this and it works great so far. Why is it not recommended?