unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* custom keyboard layout? howto redefine keys?
@ 2009-04-09 23:40 nic.d.m.1
  2009-04-10  9:25 ` B. T. Raven
  0 siblings, 1 reply; 6+ messages in thread
From: nic.d.m.1 @ 2009-04-09 23:40 UTC (permalink / raw)
  To: help-gnu-emacs

Is there a way to customize the keyboard layout within emacs? For
example if I want "the key on my keyboard labeled 'a'  behave like
that labeled 'b' I think the code for my .emacs file should be
something like this:

(global-set-key ["Key labeled 'a' on my keyboard"]  'ucs-insert 0062)

I am new to emacs and don't know what the correct syntax for "Key
labeled 'a' on my keyboard' could be.

So I tried to make f5 instead behave like b:

(global-set-key [f5]  'ucs-insert 0062)

Then I get an error message: "Wrong type argument: commandp, (ucs-
insert 62)" if I restart emacs and press f5.

(For example (global-set-key [f1]  'ucs-insert) works, but then it
asks which UTF-8 character I want to insert, that's not what I want)

Any ideas?

thanks
nic


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

* Re: custom keyboard layout? howto redefine keys?
  2009-04-09 23:40 custom keyboard layout? howto redefine keys? nic.d.m.1
@ 2009-04-10  9:25 ` B. T. Raven
  2009-04-10 10:18   ` nic.d.m.1
  0 siblings, 1 reply; 6+ messages in thread
From: B. T. Raven @ 2009-04-10  9:25 UTC (permalink / raw)
  To: help-gnu-emacs

nic.d.m.1@googlemail.com wrote:
> Is there a way to customize the keyboard layout within emacs? For
> example if I want "the key on my keyboard labeled 'a'  behave like
> that labeled 'b' I think the code for my .emacs file should be
> something like this:
> 
> (global-set-key ["Key labeled 'a' on my keyboard"]  'ucs-insert 0062)
> 
> I am new to emacs and don't know what the correct syntax for "Key
> labeled 'a' on my keyboard' could be.
> 
> So I tried to make f5 instead behave like b:
> 
> (global-set-key [f5]  'ucs-insert 0062)
> 
> Then I get an error message: "Wrong type argument: commandp, (ucs-
> insert 62)" if I restart emacs and press f5.
> 
> (For example (global-set-key [f1]  'ucs-insert) works, but then it
> asks which UTF-8 character I want to insert, that's not what I want)
> 
> Any ideas?

(global-set-key [f5] (lambda () (interactive) (ucs-insert "62")))

ucs-insert seems to want a string;

for your original question you could also do this:

(global-set-key "a" "b")

but you will immediately regret it, since now you won't be able to type 
the letter a, for example to assign it to another key. At least I 
couldn't figure out how to undo the damage and I had to re-start Emacs.

> 
> thanks
> nic


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

* Re: custom keyboard layout? howto redefine keys?
  2009-04-10  9:25 ` B. T. Raven
@ 2009-04-10 10:18   ` nic.d.m.1
  2009-04-10 15:56     ` rustom
                       ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: nic.d.m.1 @ 2009-04-10 10:18 UTC (permalink / raw)
  To: help-gnu-emacs

Thank you very much! I "mixed" your solutions and it worked:

(global-set-key "b" (lambda () (interactive) (ucs-insert "61")))
(global-set-key "a" (lambda () (interactive) (ucs-insert "62")))

Any idea *why* this works? I don't understand it. What is the meaning
of  "interactive" here?

By the way: Is there a possibility to reload the .emacs file without
restarting emacs?

I tried: M-x load-file .emacs but it doesn't work.

On 10 Apr., 11:25, "B. T. Raven" <ni...@nihilo.net> wrote:
> nic.d....@googlemail.com wrote:
> > Is there a way to customize the keyboard layout within emacs? For
> > example if I want "the key on my keyboard labeled 'a'  behave like
> > that labeled 'b' I think the code for my .emacs file should be
> > something like this:
>
> > (global-set-key ["Key labeled 'a' on my keyboard"]  'ucs-insert0062)
>
> > I am new to emacs and don't know what the correct syntax for "Key
> > labeled 'a' on my keyboard' could be.
>
> > So I tried to make f5instead behave like b:
>
> > (global-set-key [f5]  'ucs-insert0062)
>
> > Then I get an error message: "Wrong type argument: commandp, (ucs-
> > insert62)" if I restart emacs and press f5.
>
> > (For example (global-set-key [f1]  'ucs-insert) works, but then it
> > asks which UTF-8character I want to insert, that's not what I want)
>
> > Any ideas?
>
> (global-set-key [f5] (lambda () (interactive) (ucs-insert "62")))
>
> ucs-insert seems to want a string;
>
> for your original question you could also do this:
>
> (global-set-key "a" "b")
>
> but you will immediately regret it, since now you won't be able to type
> the letter a, for example to assign it to another key. At least I
> couldn't figure out how to undo the damage and I had to re-start Emacs.
>


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

* Re: custom keyboard layout? howto redefine keys?
  2009-04-10 10:18   ` nic.d.m.1
@ 2009-04-10 15:56     ` rustom
  2009-04-10 16:22     ` B. T. Raven
  2009-04-10 16:39     ` harven
  2 siblings, 0 replies; 6+ messages in thread
From: rustom @ 2009-04-10 15:56 UTC (permalink / raw)
  To: help-gnu-emacs

Can someone recommend me where to stat studying about this ucs/utf etc
business.
Every time I tried I was firghtened by the gobbledy-gook!

On Apr 10, 3:18 pm, nic.d....@googlemail.com wrote:
> Thank you very much! I "mixed" your solutions and it worked:
>
> (global-set-key "b" (lambda () (interactive) (ucs-insert "61")))
> (global-set-key "a" (lambda () (interactive) (ucs-insert "62")))


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

* Re: custom keyboard layout? howto redefine keys?
  2009-04-10 10:18   ` nic.d.m.1
  2009-04-10 15:56     ` rustom
@ 2009-04-10 16:22     ` B. T. Raven
  2009-04-10 16:39     ` harven
  2 siblings, 0 replies; 6+ messages in thread
From: B. T. Raven @ 2009-04-10 16:22 UTC (permalink / raw)
  To: help-gnu-emacs

nic.d.m.1@googlemail.com wrote:
> Thank you very much! I "mixed" your solutions and it worked:
> 
> (global-set-key "b" (lambda () (interactive) (ucs-insert "61")))
> (global-set-key "a" (lambda () (interactive) (ucs-insert "62")))

Aren't you worried about having the keyboard work one way in Emacs and 
another in other programs. Here is an explanation of the danger inherent 
in such a strategy:

http://en.wikipedia.org/wiki/Muscle_memory

> 
> Any idea *why* this works? I don't understand it. What is the meaning
> of  "interactive" here?

I think it makes the anonymous lambda function act like a command.

> 
> By the way: Is there a possibility to reload the .emacs file without
> restarting emacs?

Not with it's full initialization functionality, but many things (as in 
your example above) can be set up by pressing C-x C-e with the cursor 
after the last parenthesis of the lisp expression. The expression 
doesn't even have to be in .emacs but if it isn't saved saved there it 
won't be set the next time you start Emacs.


> 
> I tried: M-x load-file .emacs but it doesn't work.
> 
> On 10 Apr., 11:25, "B. T. Raven" <ni...@nihilo.net> wrote:
>> nic.d....@googlemail.com wrote:
>>> Is there a way to customize the keyboard layout within emacs? For
>>> example if I want "the key on my keyboard labeled 'a'  behave like
>>> that labeled 'b' I think the code for my .emacs file should be
>>> something like this:
>>> (global-set-key ["Key labeled 'a' on my keyboard"]  'ucs-insert0062)
>>> I am new to emacs and don't know what the correct syntax for "Key
>>> labeled 'a' on my keyboard' could be.
>>> So I tried to make f5instead behave like b:
>>> (global-set-key [f5]  'ucs-insert0062)
>>> Then I get an error message: "Wrong type argument: commandp, (ucs-
>>> insert62)" if I restart emacs and press f5.
>>> (For example (global-set-key [f1]  'ucs-insert) works, but then it
>>> asks which UTF-8character I want to insert, that's not what I want)
>>> Any ideas?
>> (global-set-key [f5] (lambda () (interactive) (ucs-insert "62")))
>>
>> ucs-insert seems to want a string;
>>
>> for your original question you could also do this:
>>
>> (global-set-key "a" "b")
>>
>> but you will immediately regret it, since now you won't be able to type
>> the letter a, for example to assign it to another key. At least I
>> couldn't figure out how to undo the damage and I had to re-start Emacs.
>>


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

* Re: custom keyboard layout? howto redefine keys?
  2009-04-10 10:18   ` nic.d.m.1
  2009-04-10 15:56     ` rustom
  2009-04-10 16:22     ` B. T. Raven
@ 2009-04-10 16:39     ` harven
  2 siblings, 0 replies; 6+ messages in thread
From: harven @ 2009-04-10 16:39 UTC (permalink / raw)
  To: help-gnu-emacs

nic.d.m.1@googlemail.com writes:

> Thank you very much! I "mixed" your solutions and it worked:
>
> (global-set-key "b" (lambda () (interactive) (ucs-insert "61")))
> (global-set-key "a" (lambda () (interactive) (ucs-insert "62")))
>
> Any idea *why* this works? I don't understand it. What is the meaning
> of  "interactive" here?

you could have used instead:

(defun my-command ()
   (interactive)
   (ucs-insert "61"))

(global-set-key "b" 'my-command)

Interactive means that the function my-command is actually a command,
that is something called interactively using  M-x my-command.
Now you will probably never use that command directly, so there is no
need to give it a name.

Hence the lambda which defines an anonymous function, that is a function
without a name, and the interactive which convert it to a command.
It's a bit paradoxical, but global-set-key wants a command, not
a function, as its argument.

> By the way: Is there a possibility to reload the .emacs file without
> restarting emacs?
>
> I tried: M-x load-file .emacs but it doesn't work.

with current buffer being .emacs, do
M-x eval-buffer


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

end of thread, other threads:[~2009-04-10 16:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-09 23:40 custom keyboard layout? howto redefine keys? nic.d.m.1
2009-04-10  9:25 ` B. T. Raven
2009-04-10 10:18   ` nic.d.m.1
2009-04-10 15:56     ` rustom
2009-04-10 16:22     ` B. T. Raven
2009-04-10 16:39     ` harven

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