all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp question:keyboard-translate with hyper fail?
@ 2011-03-11 11:00 Xah Lee
  2011-03-11 12:01 ` Deniz Dogan
       [not found] ` <mailman.6.1299844900.14178.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Xah Lee @ 2011-03-11 11:00 UTC (permalink / raw)
  To: help-gnu-emacs

when i try to do this:

(keyboard-translate ?\H-3 ?•) ; set Hyper+3 to type unicode bullet
char

i got this error

Debugger entered--Lisp error: (wrong-type-argument characterp
16777332)
  keyboard-translate(16777332 8226)
  eval((keyboard-translate 16777332 8226))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)

anyone know why? using Ctrl works fine, e.g.

(keyboard-translate ?\C-3 ?•)

i double checked and the syntax for hyper ?\H- seems correct.

 Xah


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-11 11:00 elisp question:keyboard-translate with hyper fail? Xah Lee
@ 2011-03-11 12:01 ` Deniz Dogan
       [not found] ` <mailman.6.1299844900.14178.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Deniz Dogan @ 2011-03-11 12:01 UTC (permalink / raw)
  To: Xah Lee; +Cc: help-gnu-emacs

2011/3/11 Xah Lee <xahlee@gmail.com>:
> when i try to do this:
>
> (keyboard-translate ?\H-3 ?•) ; set Hyper+3 to type unicode bullet
> char
>
> i got this error
>
> Debugger entered--Lisp error: (wrong-type-argument characterp
> 16777332)
>  keyboard-translate(16777332 8226)
>  eval((keyboard-translate 16777332 8226))
>  eval-last-sexp-1(nil)
>  eval-last-sexp(nil)
>  call-interactively(eval-last-sexp nil nil)
>
> anyone know why? using Ctrl works fine, e.g.
>
> (keyboard-translate ?\C-3 ?•)
>
> i double checked and the syntax for hyper ?\H- seems correct.
>

(keyboard-translate ?\C-3 ?•) does not work for me.

Debugger entered--Lisp error: (wrong-type-argument characterp 67108915)
  keyboard-translate(67108915 8226)
  eval((keyboard-translate 67108915 8226))
  eval-last-sexp-1(nil)
  eval-last-sexp(nil)
  call-interactively(eval-last-sexp nil nil)

`keyboard-translate' only works with characters and neither C-3 nor
H-3 make up characters as far as I know.

-- 
Deniz Dogan



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

* Re: elisp question:keyboard-translate with hyper fail?
       [not found] ` <mailman.6.1299844900.14178.help-gnu-emacs@gnu.org>
@ 2011-03-11 22:11   ` Xah Lee
  2011-03-12  0:26     ` Tim X
  2011-03-12  2:54     ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Xah Lee @ 2011-03-11 22:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 11, 4:01 am, Deniz Dogan <deniz.a.m.do...@gmail.com> wrote:
> > i double checked and the syntax for hyper ?\H- seems correct.
>
> (keyboard-translate ?\C-3 ?•) does not work for me.
>
> Debugger entered--Lisp error: (wrong-type-argument characterp 67108915)
>   keyboard-translate(67108915 8226)
>   eval((keyboard-translate 67108915 8226))
>   eval-last-sexp-1(nil)
>   eval-last-sexp(nil)
>   call-interactively(eval-last-sexp nil nil)
>
> `keyboard-translate' only works with characters and neither C-3 nor
> H-3 make up characters as far as I know.

that's strange.

i have the following and they work.

;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
(keyboard-translate ?\C-t ?\C-x)
(keyboard-translate ?\C-x ?\C-t)

the ?\C-3 doesn't work (my mistake), but this works
(keyboard-translate ?\C-t ?•)

so maybe with a letter char it works, however, the following still
doesn't work
(keyboard-translate ?\H-t ?•)

 Xah


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-11 22:11   ` Xah Lee
@ 2011-03-12  0:26     ` Tim X
  2011-03-12  2:54     ` Stefan Monnier
  1 sibling, 0 replies; 17+ messages in thread
From: Tim X @ 2011-03-12  0:26 UTC (permalink / raw)
  To: help-gnu-emacs

Xah Lee <xahlee@gmail.com> writes:

> On Mar 11, 4:01 am, Deniz Dogan <deniz.a.m.do...@gmail.com> wrote:
>> > i double checked and the syntax for hyper ?\H- seems correct.
>>
>> (keyboard-translate ?\C-3 ?•) does not work for me.
>>
>> Debugger entered--Lisp error: (wrong-type-argument characterp 67108915)
>>   keyboard-translate(67108915 8226)
>>   eval((keyboard-translate 67108915 8226))
>>   eval-last-sexp-1(nil)
>>   eval-last-sexp(nil)
>>   call-interactively(eval-last-sexp nil nil)
>>
>> `keyboard-translate' only works with characters and neither C-3 nor
>> H-3 make up characters as far as I know.
>
> that's strange.
>
> i have the following and they work.
>
> ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
> (keyboard-translate ?\C-t ?\C-x)
> (keyboard-translate ?\C-x ?\C-t)
>
> the ?\C-3 doesn't work (my mistake), but this works
> (keyboard-translate ?\C-t ?•)
>
> so maybe with a letter char it works, however, the following still
> doesn't work
> (keyboard-translate ?\H-t ?•)
>
>  Xah

Are you sure your keyboard is actually generating the keycode you think
it is? I remember on some (unix) based systems, I had to used xmodmap in
order to get the hyper key working.

-- 
tcross (at) rapttech dot com dot au


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-11 22:11   ` Xah Lee
  2011-03-12  0:26     ` Tim X
@ 2011-03-12  2:54     ` Stefan Monnier
  2011-03-12  4:51       ` Le Wang
  2011-03-12  7:07       ` Xah Lee
  1 sibling, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2011-03-12  2:54 UTC (permalink / raw)
  To: help-gnu-emacs

> ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
> (keyboard-translate ?\C-t ?\C-x)
> (keyboard-translate ?\C-x ?\C-t)

There are 32 Ctrl+letter combinations which are characters, and the
above two are among them.  These are exceptional special cases due
to history.  My general recommendation is to not use keyboard-translate
but key-translation-map or function-key-map, which work on arbitrary
key sequences rather only on single-char events.


        Stefan



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  2:54     ` Stefan Monnier
@ 2011-03-12  4:51       ` Le Wang
  2011-03-12 21:16         ` Stefan Monnier
  2011-03-12  7:07       ` Xah Lee
  1 sibling, 1 reply; 17+ messages in thread
From: Le Wang @ 2011-03-12  4:51 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1141 bytes --]

On Sat, Mar 12, 2011 at 10:54 AM, Stefan Monnier
<monnier@iro.umontreal.ca>wrote:

> > ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
> > (keyboard-translate ?\C-t ?\C-x)
> > (keyboard-translate ?\C-x ?\C-t)
>
> There are 32 Ctrl+letter combinations which are characters, and the
> above two are among them.  These are exceptional special cases due
> to history.  My general recommendation is to not use keyboard-translate
> but key-translation-map or function-key-map, which work on arbitrary
> key sequences rather only on single-char events.
>

I got these exact keyboard-translate lines from Xah's blog.  They don't work
reliably on Windows.  Sometimes after switching back to Emacs from another
program, and my first input to Emacs is C-j, C-j still registers instead of
C-x.

How would I use key-translation-map to do the swap?

(define-key key-translation-map [(control x)] [(control j)])
(define-key key-translation-map [(control j)] [(control x)])

C-j seems regixter as C-x.  But C-x acting like a prefix key, waiting for
the next input.


>
>        Stefan
>
>


-- 
Le

[-- Attachment #2: Type: text/html, Size: 1733 bytes --]

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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  2:54     ` Stefan Monnier
  2011-03-12  4:51       ` Le Wang
@ 2011-03-12  7:07       ` Xah Lee
  2011-03-12  7:22         ` Xah Lee
  2011-03-12 11:59         ` Deniz Dogan
  1 sibling, 2 replies; 17+ messages in thread
From: Xah Lee @ 2011-03-12  7:07 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 11, 6:54 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
> > (keyboard-translate ?\C-t ?\C-x)
> > (keyboard-translate ?\C-x ?\C-t)
>
> There are 32 Ctrl+letter combinations which are characters, and the
> above two are among them.  These are exceptional special cases due
> to history.  My general recommendation is to not use keyboard-translate
> but key-translation-map or function-key-map, which work on arbitrary
> key sequences rather only on single-char events.
>
>         Stefan

thanks to all.

perhaps the doc can be improved.

i just read up the elisp doc and it actually gives a C- example.

 -- Function: keyboard-translate from to
     This function modifies `keyboard-translate-table' to translate
     character code FROM into character code TO.  It creates the
     keyboard translate table if necessary.

   Here's an example of using the `keyboard-translate-table' to make
`C-x', `C-c' and `C-v' perform the cut, copy and paste operations:

     (keyboard-translate ?\C-x 'control-x)
     (keyboard-translate ?\C-c 'control-c)
     (keyboard-translate ?\C-v 'control-v)
     (global-set-key [control-x] 'kill-region)
     (global-set-key [control-c] 'kill-ring-save)
     (global-set-key [control-v] 'yank)

also note it uses the syntax 「'control-x」. I don't quite understand
it...

should it be a bug report?

 Xah


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  7:07       ` Xah Lee
@ 2011-03-12  7:22         ` Xah Lee
  2011-03-14 14:17           ` Stefan Monnier
  2011-03-12 11:59         ` Deniz Dogan
  1 sibling, 1 reply; 17+ messages in thread
From: Xah Lee @ 2011-03-12  7:22 UTC (permalink / raw)
  To: help-gnu-emacs

ugh, just tried this and still doesn't work.

(define-key key-translation-map [?\H-8] ?\◇)

am giving up at this point.

in case anyone's interested, i'm trying to make hyper key do unicode
symbols.
Ι have it all working by
(global-set-key (kbd "H-3") (lambda () (interactive) (insert "•"))) ;
bullet

but yesterday i got smart and thought i'll re-write them using
keyboard-translate instead. (just had a major refactoring of
my .emacs.)

possibly i'll file a bug report. Thanks for the helpful answers.

 Xah

On Mar 11, 11:07 pm, Xah Lee <xah...@gmail.com> wrote:
> On Mar 11, 6:54 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>
> > > ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
> > > (keyboard-translate ?\C-t ?\C-x)
> > > (keyboard-translate ?\C-x ?\C-t)
>
> > There are 32 Ctrl+letter combinations which are characters, and the
> > above two are among them.  These are exceptional special cases due
> > to history.  My general recommendation is to not use keyboard-translate
> > but key-translation-map or function-key-map, which work on arbitrary
> > key sequences rather only on single-char events.
>
> >         Stefan
>
> thanks to all.
>
> perhaps the doc can be improved.
>
> i just read up the elisp doc and it actually gives a C- example.
>
>  -- Function: keyboard-translate from to
>      This function modifies `keyboard-translate-table' to translate
>      character code FROM into character code TO.  It creates the
>      keyboard translate table if necessary.
>
>    Here's an example of using the `keyboard-translate-table' to make
> `C-x', `C-c' and `C-v' perform the cut, copy and paste operations:
>
>      (keyboard-translate ?\C-x 'control-x)
>      (keyboard-translate ?\C-c 'control-c)
>      (keyboard-translate ?\C-v 'control-v)
>      (global-set-key [control-x] 'kill-region)
>      (global-set-key [control-c] 'kill-ring-save)
>      (global-set-key [control-v] 'yank)
>
> also note it uses the syntax 「'control-x」. I don't quite understand
> it...
>
> should it be a bug report?
>
>  Xah



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  7:07       ` Xah Lee
  2011-03-12  7:22         ` Xah Lee
@ 2011-03-12 11:59         ` Deniz Dogan
  1 sibling, 0 replies; 17+ messages in thread
From: Deniz Dogan @ 2011-03-12 11:59 UTC (permalink / raw)
  To: Xah Lee; +Cc: help-gnu-emacs

2011/3/12 Xah Lee <xahlee@gmail.com>:
> On Mar 11, 6:54 pm, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>> > ;; Swap “Ctrl+x” and “Ctrl+t”, so it's easier to type on Dvorak layout
>> > (keyboard-translate ?\C-t ?\C-x)
>> > (keyboard-translate ?\C-x ?\C-t)
>>
>> There are 32 Ctrl+letter combinations which are characters, and the
>> above two are among them.  These are exceptional special cases due
>> to history.  My general recommendation is to not use keyboard-translate
>> but key-translation-map or function-key-map, which work on arbitrary
>> key sequences rather only on single-char events.
>>
>>         Stefan
>
> thanks to all.
>
> perhaps the doc can be improved.
>
> i just read up the elisp doc and it actually gives a C- example.
>
>  -- Function: keyboard-translate from to
>     This function modifies `keyboard-translate-table' to translate
>     character code FROM into character code TO.  It creates the
>     keyboard translate table if necessary.
>
>   Here's an example of using the `keyboard-translate-table' to make
> `C-x', `C-c' and `C-v' perform the cut, copy and paste operations:
>
>     (keyboard-translate ?\C-x 'control-x)
>     (keyboard-translate ?\C-c 'control-c)
>     (keyboard-translate ?\C-v 'control-v)
>     (global-set-key [control-x] 'kill-region)
>     (global-set-key [control-c] 'kill-ring-save)
>     (global-set-key [control-v] 'yank)
>
> also note it uses the syntax 「'control-x」. I don't quite understand
> it...
>
> should it be a bug report?
>

The examples with C-x, C-c and C-v are valid. The keys C-a up to C-z
and probably a few others (Stefan said there are 32 of them) are all
characters. C-3 however is not a character.

I don't think it's a bug in the documentation, but maybe it should
clarify this matter?

-- 
Deniz Dogan



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  4:51       ` Le Wang
@ 2011-03-12 21:16         ` Stefan Monnier
  2011-03-13  4:31           ` Le Wang
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2011-03-12 21:16 UTC (permalink / raw)
  To: Le Wang; +Cc: help-gnu-emacs

> I got these exact keyboard-translate lines from Xah's blog.  They don't work
> reliably on Windows.  Sometimes after switching back to Emacs from another
> program, and my first input to Emacs is C-j, C-j still registers instead of
> C-x.

Sounds like a bug (even sounds like one that's already been reported but
that we're having trouble tracking down).  But I can't find it in the
bug database, so maybe it's something different.  So please M-x
report-emacs-bug an include as much info as possible to help us
reproduce the bug.

> How would I use key-translation-map to do the swap?

> (define-key key-translation-map [(control x)] [(control j)])
> (define-key key-translation-map [(control j)] [(control x)])

Yes.

> C-j seems regixter as C-x.  But C-x acting like a prefix key, waiting for
> the next input.

I think that's because of function-key-map's remapping of C-x @ S <key>
to S-<key>.  If you add (define-key function-key-map [?\C-x] nil), it
might work (it does for me).


        Stefan



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12 21:16         ` Stefan Monnier
@ 2011-03-13  4:31           ` Le Wang
  0 siblings, 0 replies; 17+ messages in thread
From: Le Wang @ 2011-03-13  4:31 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1475 bytes --]

On Sun, Mar 13, 2011 at 5:16 AM, Stefan Monnier <monnier@iro.umontreal.ca>wrote:

> > I got these exact keyboard-translate lines from Xah's blog.  They don't
> work
> > reliably on Windows.  Sometimes after switching back to Emacs from
> another
> > program, and my first input to Emacs is C-j, C-j still registers instead
> of
> > C-x.
>
> Sounds like a bug (even sounds like one that's already been reported but
> that we're having trouble tracking down).  But I can't find it in the
> bug database, so maybe it's something different.  So please M-x
> report-emacs-bug an include as much info as possible to help us
> reproduce the bug.
>

I filed http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8237


> > How would I use key-translation-map to do the swap?
>
> > (define-key key-translation-map [(control x)] [(control j)])
> > (define-key key-translation-map [(control j)] [(control x)])
>
> Yes.
>
> > C-j seems regixter as C-x.  But C-x acting like a prefix key, waiting for
> > the next input.
>
> I think that's because of function-key-map's remapping of C-x @ S <key>
> to S-<key>.  If you add (define-key function-key-map [?\C-x] nil), it
> might work (it does for me).
>

These 3 lines seem to do the swapping I want.

(define-key key-translation-map [(control x)] [(control j)])
(define-key key-translation-map [(control j)] [(control x)])
(define-key function-key-map [(control x)] nil)

Hopefully this will work reliably.

Thanks!


>
>        Stefan
>



-- 
Le

[-- Attachment #2: Type: text/html, Size: 2437 bytes --]

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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-12  7:22         ` Xah Lee
@ 2011-03-14 14:17           ` Stefan Monnier
  2011-03-14 20:32             ` Xah Lee
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2011-03-14 14:17 UTC (permalink / raw)
  To: help-gnu-emacs

> ugh, just tried this and still doesn't work.
> (define-key key-translation-map [?\H-8] ?\◇)

key-translation-map maps key sequences to key sequences, so try

  (define-key key-translation-map [?\H-8] [?\◇])

> Ι have it all working by
> (global-set-key (kbd "H-3") (lambda () (interactive) (insert "•"))) ;
> bullet

You can also do

  (global-set-key (kbd "H-3") "•")


        Stefan


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-14 14:17           ` Stefan Monnier
@ 2011-03-14 20:32             ` Xah Lee
  2011-03-18 13:56               ` Xah Lee
  0 siblings, 1 reply; 17+ messages in thread
From: Xah Lee @ 2011-03-14 20:32 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 14, 7:17 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
> > ugh, just tried this and still doesn't work.
> > (define-key key-translation-map [?\H-8] ?\◇)
>
> key-translation-map maps key sequences to key sequences, so try
>
>   (define-key key-translation-map [?\H-8] [?\◇])

Thanks! That worked.

 Xah

> > Ι have it all working by
> > (global-set-key (kbd "H-3") (lambda () (interactive) (insert "•"))) ;
> > bullet
>
> You can also do
>
>   (global-set-key (kbd "H-3") "•")
>
>         Stefan



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-14 20:32             ` Xah Lee
@ 2011-03-18 13:56               ` Xah Lee
  2011-03-19 16:09                 ` rusi
  0 siblings, 1 reply; 17+ messages in thread
From: Xah Lee @ 2011-03-18 13:56 UTC (permalink / raw)
  To: help-gnu-emacs


just wrote up a little blog on why i wanted to use key-translation in
this thread. Might be interesting.

〈Emacs: Remapping Keys Using key-translation-map〉
http://xahlee.org/emacs/emacs_key-translation-map.html

────────────────────
Emacs: Remapping Keys Using key-translation-map

Xah Lee, 2011-03-17

This page shows you how to remap keys to input unicode symbols using
the elisp function “key-translation-map”, and discuss some related
issues.

Recently i wrote a article on How to Create a APL or Math Symbols
Keyboard Layout. In the article, i described several ways to remap
keys on keyboard to input symbols for Mac, Windows, Linux. Some are OS-
wide thru OS's user-configurable mechanisms. Some are using key-macro
software for that OS. And there's emacs for just within emacs. I've
used them all in the past 2 decades, but in the past few years, i find
the most practical and flexible way is just emacs. Because: ① 99% of
my typing are done in emacs. So, i don't really need them to be OS-
wide. ② Each method of remapping keys all have their own limitations
(e.g. on Mac and Windows, there's no way to remap some key
combinations.), but within emacs it has the most support on remapping
keys that has less restrictions than using OS's methods.

Here's interesting thing i discovered recently.

────────────────────
Using “global-set-key” or “key-translation-map” to Insert Unicode Char

If you want to define a key combo for typing a unicode char such as
math symbol λ, you can do it using “global-set-key” or “key-
translation-map”.

Example of using “global-set-key”:

(global-set-key (kbd "H-3") (lambda () (interactive) (insert "λ"))) ;
【Hyper+3】 insert λ char
(global-set-key (kbd "H-3") "λ") ; 【Hyper+3】 insert λ char. This is a
builtin macro for above.

(In this example we use Hyper key, but Ctrl or Meta works too. You can
make the Win key or the Menu key act as Hyper. To set up, see: Emacs:
How to define Hyper & Super Keys.)

Example of using “key-translation-map”:

(define-key key-translation-map (kbd "H-3") (kbd "λ")) ; 【Hyper+3】
insert λ char

There are some advantage and disadvantages in either way.

────────────────────
Problem with “global-set-key”

If you use “global-set-key”, then when you do interactive search 【Ctrl
+s】, then when you type 【Hyper+3】, it'll exit the search. So this
means, if you use unicode heavily in your files, then you lose the
ability to isearch them. (you can work-around by typing it in the
buffer first, put cursor on it, start isearch, 【C-w】 to select the
char. Then when done, delete that symbol you inserted for this
purpose.)

Using “key-translation-map” doesn't have this problem.

────────────────────
Problem with “key-translation-map”

The problem with “key-translation-map” is this: Suppose you don't type
the backtick (`) char often, and you press 【C-x o】 “delete-other-
windows” ~50 times more often. So, to increase the efficiency of key
use on keyboard, you remap backtick to do “delete-other-windows” and
set 【Hyper+`】 for inputting the backtick. The elisp code looks like
this:

(global-set-key (kbd "`") 'someCommand) ; set ` to someCommand
(define-key key-translation-map (kbd "H-`") (kbd "`")) ; insert
backtick char by 【Hyper+`】

The problem is, when you type 【Hyper+`】, it'll actually call the
command bound to backtick.

So, this means, the “key-translation-map” is great for symbol input
but is not good if you want to use it as a way to remap buttons.

Note: there's the function “keyboard-translate”. However, it is
designed to translate character only. So, key combination isn't a
character and you can't use it for Hyper combination. Using (define-
key key-translation-map …) is more versatile. (Due to historical
reasons, “keyboard-translate” does work for some Ctrl combination key.
(thanks to Stefan Monnier and Deniz Dogan for this tip. (Source
groups.google.com)))

────────────────────
Who Need to Use Unicode That Often?

Well, i do, a lot, all over, in my writings, as well in coding.

For example, bullet (•), “curly quote”, dash (—), angle bracket for
〈article title〉 and 《book title》 (See: Intro to Chinese Punctuation
with Computer Language Syntax Perspectives.), and i use 【lenticular
bracket】 to mark key combinations, 「corner bracket」 to mark computer
code, and i use FULLWIDTH AMPERSAND (&) for avoid html entity
complexity (See: HTML Entities, Ampersand, Unicode, Semantics.) , and
lots others.

Using proper symbols decreases ambiguity at syntax level. For example,
the asterisk (*) can mean lots of things. But a dedicated bullet “•”
carries a precise semantics.

For coding, some languages heavily use math symbols (e.g. APL,
Mathematica). For functional languages such as Haskell, Scheme Lisp,
you can setup for example “λ” to mean “lambda”, “≠” to mean “!=”, “⊕”
for user-defined operators, etc. You can also use symbols for variable
names in emacs lisp, Javascript, Java (e.g. “α”). See:

    * Unicode Support in Ruby, Perl, Python, javascript, Java, Emacs
Lisp, Mathematica
    * Problems of Symbol Congestion in Computer Languages (ASCII Jam;
Unicode; Fortress)
    * How Mathematica does Unicode?
    * Unicode Popularity On Web

 Xah


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-18 13:56               ` Xah Lee
@ 2011-03-19 16:09                 ` rusi
  2011-03-20  0:31                   ` Xah Lee
  0 siblings, 1 reply; 17+ messages in thread
From: rusi @ 2011-03-19 16:09 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 18, 6:56 pm, Xah Lee <xah...@gmail.com> wrote:
> just wrote up a little blog on why i wanted to use key-translation in
> this thread. Might be interesting.
>
> 〈Emacs: Remapping Keys Using key-translation-map〉http://xahlee.org/emacs/emacs_key-translation-map.html
>
> ────────────────────
> Emacs: Remapping Keys Using key-translation-map
>
> Xah Lee, 2011-03-17
>
> This page shows you how to remap keys to input unicode symbols using
> the elisp function “key-translation-map”, and discuss some related
> issues.
>
> Recently i wrote a article on How to Create a APL or Math Symbols
> Keyboard Layout. In the article, i described several ways to remap
> keys on keyboard to input symbols for Mac, Windows, Linux. Some are OS-
> wide thru OS's user-configurable mechanisms. Some are using key-macro
> software for that OS. And there's emacs for just within emacs. I've
> used them all in the past 2 decades, but in the past few years, i find
> the most practical and flexible way is just emacs. Because: ① 99% of
> my typing are done in emacs. So, i don't really need them to be OS-
> wide. ② Each method of remapping keys all have their own limitations
> (e.g. on Mac and Windows, there's no way to remap some key
> combinations.), but within emacs it has the most support on remapping
> keys that has less restrictions than using OS's methods.
>
> Here's interesting thing i discovered recently.
>
> ────────────────────
> Using “global-set-key” or “key-translation-map” to Insert Unicode Char
>
> If you want to define a key combo for typing a unicode char such as
> math symbol λ, you can do it using “global-set-key” or “key-
> translation-map”.
>
> Example of using “global-set-key”:
>
> (global-set-key (kbd "H-3") (lambda () (interactive) (insert "λ"))) ;
> 【Hyper+3】 insert λ char
> (global-set-key (kbd "H-3") "λ") ; 【Hyper+3】 insert λ char. This is a
> builtin macro for above.
>
> (In this example we use Hyper key, but Ctrl or Meta works too. You can
> make the Win key or the Menu key act as Hyper. To set up, see: Emacs:
> How to define Hyper & Super Keys.)
>
> Example of using “key-translation-map”:
>
> (define-key key-translation-map (kbd "H-3") (kbd "λ")) ; 【Hyper+3】
> insert λ char
>
> There are some advantage and disadvantages in either way.
>
> ────────────────────
> Problem with “global-set-key”
>
> If you use “global-set-key”, then when you do interactive search 【Ctrl
> +s】, then when you type 【Hyper+3】, it'll exit the search. So this
> means, if you use unicode heavily in your files, then you lose the
> ability to isearch them. (you can work-around by typing it in the
> buffer first, put cursor on it, start isearch, 【C-w】 to select the
> char. Then when done, delete that symbol you inserted for this
> purpose.)
>
> Using “key-translation-map” doesn't have this problem.
>
> ────────────────────
> Problem with “key-translation-map”
>
> The problem with “key-translation-map” is this: Suppose you don't type
> the backtick (`) char often, and you press 【C-x o】 “delete-other-
> windows” ~50 times more often. So, to increase the efficiency of key
> use on keyboard, you remap backtick to do “delete-other-windows” and
> set 【Hyper+`】 for inputting the backtick. The elisp code looks like
> this:
>
> (global-set-key (kbd "`") 'someCommand) ; set ` to someCommand
> (define-key key-translation-map (kbd "H-`") (kbd "`")) ; insert
> backtick char by 【Hyper+`】
>
> The problem is, when you type 【Hyper+`】, it'll actually call the
> command bound to backtick.
>
> So, this means, the “key-translation-map” is great for symbol input
> but is not good if you want to use it as a way to remap buttons.
>
> Note: there's the function “keyboard-translate”. However, it is
> designed to translate character only. So, key combination isn't a
> character and you can't use it for Hyper combination. Using (define-
> key key-translation-map …) is more versatile. (Due to historical
> reasons, “keyboard-translate” does work for some Ctrl combination key.
> (thanks to Stefan Monnier and Deniz Dogan for this tip. (Source
> groups.google.com)))
>
> ────────────────────
> Who Need to Use Unicode That Often?
>
> Well, i do, a lot, all over, in my writings, as well in coding.
>
> For example, bullet (•), “curly quote”, dash (—), angle bracket for
> 〈article title〉 and 《book title》 (See: Intro to Chinese Punctuation
> with Computer Language Syntax Perspectives.), and i use 【lenticular
> bracket】 to mark key combinations, 「corner bracket」 to mark computer
> code, and i use FULLWIDTH AMPERSAND (&) for avoid html entity
> complexity (See: HTML Entities, Ampersand, Unicode, Semantics.) , and
> lots others.

Xah your unicode has not worked out -- at least in this post :-)
[Though you probably cant see that I cant see (most of) your
characters]

>
> Using proper symbols decreases ambiguity at syntax level. For example,
> the asterisk (*) can mean lots of things. But a dedicated bullet “•”
> carries a precise semantics.
>
> For coding, some languages heavily use math symbols (e.g. APL,
> Mathematica). For functional languages such as Haskell, Scheme Lisp,
> you can setup for example “λ” to mean “lambda”, “≠” to mean “!=”, “⊕”
> for user-defined operators, etc. You can also use symbols for variable
> names in emacs lisp, Javascript, Java (e.g. “α”). See:
>
>     * Unicode Support in Ruby, Perl, Python, javascript, Java, Emacs
> Lisp, Mathematica
>     * Problems of Symbol Congestion in Computer Languages (ASCII Jam;
> Unicode; Fortress)
>     * How Mathematica does Unicode?
>     * Unicode Popularity On Web
>
>  Xah



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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-19 16:09                 ` rusi
@ 2011-03-20  0:31                   ` Xah Lee
  2011-03-20  2:51                     ` rusi
  0 siblings, 1 reply; 17+ messages in thread
From: Xah Lee @ 2011-03-20  0:31 UTC (permalink / raw)
  To: help-gnu-emacs

α λ — “ ” • … ≠ ⊕ ① ② ─ 〈 〉 《 》 「 」 【 】 &

> Xah your unicode has not worked out -- at least in this post :-)
> [Though you probably cant see that I cant see (most of) your
> characters]

do a screenshot. I'd love to see it.

if you use Google Chrome, and view in google groups here
http://groups.google.com/group/gnu.emacs.help/msg/0e5cb199a07c1235

i think all char will show.

as you know... you'll need the font, and the app will need to support
unicode, and the news server didn't screw up the encoding...

i have on my site a blog of a selection of fonts i found to be best
for unicode. For linux, that's DejaVu.

 Xah


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

* Re: elisp question:keyboard-translate with hyper fail?
  2011-03-20  0:31                   ` Xah Lee
@ 2011-03-20  2:51                     ` rusi
  0 siblings, 0 replies; 17+ messages in thread
From: rusi @ 2011-03-20  2:51 UTC (permalink / raw)
  To: help-gnu-emacs

On Mar 20, 5:31 am, Xah Lee <xah...@gmail.com> wrote:
> α λ — “ ” • … ≠ ⊕ ① ② ─ 〈 〉 《 》 「 」 【 】 &
>
> > Xah your unicode has not worked out -- at least in this post :-)
> > [Though you probably cant see that I cant see (most of) your
> > characters]
>
> do a screenshot. I'd love to see it.

Seems ok now -- must have been a transient problem with googlegroups)
These【 】were showing as unicode boxes IIRC


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

end of thread, other threads:[~2011-03-20  2:51 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-11 11:00 elisp question:keyboard-translate with hyper fail? Xah Lee
2011-03-11 12:01 ` Deniz Dogan
     [not found] ` <mailman.6.1299844900.14178.help-gnu-emacs@gnu.org>
2011-03-11 22:11   ` Xah Lee
2011-03-12  0:26     ` Tim X
2011-03-12  2:54     ` Stefan Monnier
2011-03-12  4:51       ` Le Wang
2011-03-12 21:16         ` Stefan Monnier
2011-03-13  4:31           ` Le Wang
2011-03-12  7:07       ` Xah Lee
2011-03-12  7:22         ` Xah Lee
2011-03-14 14:17           ` Stefan Monnier
2011-03-14 20:32             ` Xah Lee
2011-03-18 13:56               ` Xah Lee
2011-03-19 16:09                 ` rusi
2011-03-20  0:31                   ` Xah Lee
2011-03-20  2:51                     ` rusi
2011-03-12 11:59         ` Deniz Dogan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.