Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to type {, [

16 views
Skip to first unread message

Yuan Cheng

unread,
Jun 9, 2011, 8:22:19 AM6/9/11
to help-gn...@gnu.org
Dear Sir or Madam,

my name is Yuan Cheng and I'm from Germany. Today I started to use emacs, but I've encountered a big problem.
I don't know how I can type { } or [ ]. I am using a german keyboard and to type them I have to use "alt" (on my Mac) which has another usage in emacs.

Best regards,

Yuan Cheng

Pascal J. Bourguignon

unread,
Jun 9, 2011, 5:36:10 PM6/9/11
to
Yuan Cheng <gmz...@gmail.com> writes:

You have several solutions.

The simpliest one, and the one I use personnaly (I come from France
where the AZERTY layout is even more programmer unfriendly), is to
merely use the US keyboard layout. Happily, with Macintosh, it's
trivial to change the keyboard layout. The only problem with this
solution is if you share a computer with other people, they may curse
you because you will forget to change the layout back. On the other
hand, nowadays with MacOSX, each user has his own keyboard layout
preferences so it shouldn't be a big problem.


Now, with emacs on Macintosh, you could tell it to use a different key
than Alt for Meta. For example, it could use quite well, the Command
key instead.

I use this in my ~/.emacs:

(defun mac-vanilla-keys ()
(interactive)
(setf mac-command-modifier 'meta
mac-option-modifier 'alt
one-buffer-one-frame nil))

(mac-vanilla-keys)

On the other hand, this must be disabled when using emacs on the Mac
thru VNC from a machine that has a proper keyboard layout with Alt and
Meta (and no Command). In this situation we have to revert to the
original situation. For this, I use the following command:

(defun mac-vnc-keys ()
(interactive)
(setf mac-command-modifier 'alt
mac-option-modifier 'meta
one-buffer-one-frame nil))

Then, you can use the keyboard-translate function to translate some
useless character into the wanted [] {} characters.
For example, ö and ä are not needed to write programs, so you could map
them to the brackets:

(keyboard-translate ?ö ?[)
(keyboard-translate ?Ö ?{)
(keyboard-translate ?ä ?])
(keyboard-translate ?Ä ?})

This translation is done early in emacs event processing. If you are
also using emacs to write documentation or papers in German, you may
need those letters, so this won't do.


Then what you can do is to bind those keys to commands that will insert
the brackets, only in the programming modes:

(defun inserter (string)
(byte-compile `(lambda () (interactive) (insert ,string))))

(defun german-brackets-meat ()
(interactive)
(local-set-key (kbd "ö") (inserter "["))
(local-set-key (kbd "ä") (inserter "]"))
(local-set-key (kbd "Ö") (inserter "{"))
(local-set-key (kbd "Ä") (inserter "}")))

and then you can add this meat to the programming mode hooks:

(add-hook 'c-mode-hook 'german-brackets-meat)
(add-hook 'java-mode-hook 'german-brackets-meat)
(add-hook 'lisp-mode-hook 'german-brackets-meat)
;; ...

--
__Pascal Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.

Nicolas Forgerit

unread,
Jun 9, 2011, 5:54:11 PM6/9/11
to Yuan Cheng, help-gn...@gnu.org
Hello Mr. Cheng,

good choice! Load your .emacs file (which you can usually find at [1])
with "C-x C-f", paste the code [0] into it, save with "C-x C-s". Then
either restart Emacs or type "M-x eval-buffer" and hit Enter. This
command remaps "Meta" to the "Apple Cmd-Button" and let's you use
"Alt" for the brackets. I think this is the most useful way to go on a
Mac.

Have fun & best regards from Karlsruhe! :-)
Ciao
Nico

[0] Emacs Lisp Code:
;; (begin) ENABLE MAC KBD BINDINGS
(setq mac-option-modifier nil
mac-command-modifier 'meta
x-select-enable-clipboard t)
;; (end of code-snippet)

[1] Filepath on our Harddisk-Drive
~/.emacs


On Thu, Jun 9, 2011 at 2:22 PM, Yuan Cheng <gmz...@gmail.com> wrote:
> Dear Sir or Madam,
>
> my name is Yuan Cheng and I'm from Germany. Today I started to use emacs, but I've encountered a big problem.
> I don't know how I can type { } or [ ]. I am using a german keyboard and to type them I have to use "alt" (on my Mac) which has another usage in emacs.
>

> Best regards,
>
> Yuan Cheng
>

--
Ciao
                                     Nico

Peter Dyballa

unread,
Jun 10, 2011, 3:09:05 AM6/10/11
to Yuan Cheng, help-gn...@gnu.org

Am 09.06.2011 um 14:22 schrieb Yuan Cheng:

> I don't know how I can type { } or [ ]. I am using a german keyboard
> and to type them I have to use "alt" (on my Mac) which has another
> usage in emacs.


Why don't you try to press all keys of your keyboard, adding on each
new run one more modifier (shift, alt, alt-shift, ...)? Or read the
documentation.

--
Greetings

Pete

Increase the size of your bike by at least *five* inches!


Deniz Dogan

unread,
Jun 11, 2011, 2:34:38 AM6/11/11
to help-gn...@gnu.org
On 2011-06-10 09:09, Peter Dyballa wrote:
>
> Am 09.06.2011 um 14:22 schrieb Yuan Cheng:
>
>> I don't know how I can type { } or [ ]. I am using a german keyboard
>> and to type them I have to use "alt" (on my Mac) which has another
>> usage in emacs.
>
>
> Why don't you try to press all keys of your keyboard, adding on each new
> run one more modifier (shift, alt, alt-shift, ...)? Or read the
> documentation.
>

So helpful.

0 new messages