unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* key-translation-map and combinations
@ 2014-05-24 22:13 Vesa Paatero
  2014-05-25 19:33 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Vesa Paatero @ 2014-05-24 22:13 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

What I'm trying to do is map the usual C-s search to C-f and the usual 
C-xC-s saving to C-s.
Now, you can do this:

(define-key key-translation-map "\C-f" "\C-s")
(define-key key-translation-map "\C-s" "\C-x\C-s")

but then you'll notice that longer sequences like C-xC-f will also be 
affected and change to e.g. C-xC-s. This can be avoided by defining the 
longer sequences back to themselves like this:

(define-key key-translation-map "\C-x\C-f" "\C-x\C-f")
(define-key key-translation-map "\C-x\C-s" "\C-x\C-s")

but that is no perfect solution since there is no known number of those 
longer sequences as new modes can establish them.

My question: Has anyone found a way to make translation mappings like 
these so that a key is only translated when it begins a key sequence?

Thanks for any help,
Vesa



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: key-translation-map and combinations
  2014-05-24 22:13 key-translation-map and combinations Vesa Paatero
@ 2014-05-25 19:33 ` Stefan Monnier
  2014-05-29 13:10   ` Vesa Paatero
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2014-05-25 19:33 UTC (permalink / raw)
  To: help-gnu-emacs

> My question: Has anyone found a way to make translation mappings like these
> so that a key is only translated when it begins a key sequence?

Yes: don't use key-translation-map.  Instead, change global-map.

(define-key global-map [?\C-f] (lookup-key global-map [?\C-s]))
(define-key global-map [?\C-s] (lookup-key global-map [?\C-x ?\C-s]))


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: key-translation-map and combinations
  2014-05-25 19:33 ` Stefan Monnier
@ 2014-05-29 13:10   ` Vesa Paatero
  2014-05-29 14:44     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Vesa Paatero @ 2014-05-29 13:10 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: Vesa Paatero


2014-05-25  22:33, Stefan Monnier wrote:
>> My question: Has anyone found a way to make translation mappings like these
>> so that a key is only translated when it begins a key sequence?
> Yes: don't use key-translation-map.  Instead, change global-map.
>
> (define-key global-map [?\C-f] (lookup-key global-map [?\C-s]))
> (define-key global-map [?\C-s] (lookup-key global-map [?\C-x ?\C-s]))

Thanks for that hint. Alas, I found a subtle difference there. Try the 
following:  Use

(define-key global-map [?\C-f] (lookup-key global-map [?\C-s]))

to set C-f and then open some local directory (Emacs showing "Dired by 
name"). There, type Control-f and some search key that can be found 
repeatedly in your directory. Then press Control-f repeatedly.  My 
observation is that repeated search by Control-f doesn't work like it 
does when you use Control-s directly. However, if you use remap C-f using

(define-key key-translation-map "\C-f" "\C-s")

then repeated searching works with Control-f. This observation was made 
on Emacs 23.3.1. Can you repeat this in your version of Emacs? Any ideas 
for explanation?


Vesa







^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: key-translation-map and combinations
  2014-05-29 13:10   ` Vesa Paatero
@ 2014-05-29 14:44     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-05-29 14:44 UTC (permalink / raw)
  To: help-gnu-emacs

> name"). There, type Control-f and some search key that can be found
> repeatedly in your directory. Then press Control-f repeatedly.
> My observation is that repeated search by Control-f doesn't work like it
> does when you use Control-s directly. However, if you use remap C-f using

That's because the isearch-mode-map has a binding for C-s to do "repeat"
but doesn't have such a binding for C-f.

You can try

(define-key isearch-mode-map [?\C-f] (lookup-key isearch-mode-map [?\C-s]))


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-05-29 14:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-24 22:13 key-translation-map and combinations Vesa Paatero
2014-05-25 19:33 ` Stefan Monnier
2014-05-29 13:10   ` Vesa Paatero
2014-05-29 14:44     ` Stefan Monnier

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