I'm running Mac OS X and GNU Emacs 22.3.1. I use a swedish keyboard. I am unable to type braces {
}
, [
]
in emacs. When trying to type braces I get parenthesis. Since I'm quite new to Mac and emacs I need a little help on configuring emacs to get this right.

- 121,568
- 97
- 310
- 388

- 563
- 1
- 6
- 8
-
What you call "square braces" are usually refered to as "brackets". Not that it matters, but its a bit shorter to type. – Jonathan Allen Jul 31 '10 at 06:43
-
4Watch out: "brackets" is a regional one. In the US it means square brackets, in the UK, it means round brackets / parenthesis. – Douglas Jul 31 '10 at 14:03
-
1Unfortunately not one of the answers solved a similar issue on my german keyboard. I don't get any brackets or curly braces at all. – eriq Jul 10 '14 at 13:02
-
@sanityinc solved it for me on my French keyboard... however I am not satisfied at all, since to make a "[" I have to press three keys (alt shift 5) ! – nha Jun 29 '15 at 10:19
9 Answers
(setq mac-option-modifier nil
mac-command-modifier 'meta
x-select-enable-clipboard t)
This is what I use for my swedish keyboard. It even works with svorak A5, if you use it :)

- 3,657
- 28
- 30
-
I tryed putting this into bouth my ~/.emacs file and my ~/.emacs.d/init.el file but i can't get it to work. – muxare Sep 03 '11 at 14:20
-
-
srsly tho, try `emacs -Q` and then paste the above into `*scratch*`, eval with M-x eval-buffer and see if it works. It could be your other settings that screws something up. – monotux Sep 05 '11 at 22:37
-
I just tryed "emacs -Q and then paste the above into *scratch*, eval with M-x eval-buffer". But the curly bracets dont work. – muxare Nov 26 '11 at 14:34
-
1I'm guessing that the above code isn't evaluated properly. Try adding it to your `*scratch*`-buffer, evaluate it and see if it works. If it does work, try removing all your emacs settings (moving `.emacs.d` somewhere) and start again. – monotux Mar 10 '14 at 09:02
-
This is fantastic, but I now have an issue after relaoding emacs. Can't type letter "c" anymore. The uppercase "C" works but not lowercase. Anything I can do? – leontalbot Jul 20 '15 at 19:28
-
I just opened a question for my issue : https://stackoverflow.com/questions/31524961/emacs-lower-case-letter-c-doesnt-type-anymore – leontalbot Jul 20 '15 at 19:41
-
C-a = is not a standard shortcut. I don't know what you've done in your config but it's most likely unrelated to the above. – monotux Oct 09 '15 at 09:42
-
@monotux I will just leave it in the scratch as it seems to be working correctly this way, and I never close emacs. Thx – Pelican May 05 '21 at 07:45
-
@Pelican you can paste them into your ~/.emacs.d/init.el instead, then they are evaluated every time you start Emacs. – monotux May 06 '21 at 09:28
-
@monotux i never « start » eMacs ... I live in there , all jokes aside yes I will do that, thank you – Pelican May 06 '21 at 09:29
You could also try:
(setq mac-option-key-is-meta t)
(setq mac-right-option-modifier nil)

- 349
- 3
- 3
-
1
-
3Yes! The setq mac-right-option-modifier nil is what totally saved me! Now I can have my left alt as meta and my right alt as curly brackets source. Thank you! – stackdaemon May 21 '16 at 21:03
-
1
-
1
I'm assuming that you're using a graphical emacs, and not just using the OS X bundled version from within Terminal.
To ensure that Emacs responds to keystrokes in the same way as other OS X apps, try the following:
(setq default-input-method "MacOSX")
And in particular, if you want to use the Option key to enter extended characters not on your keyboard (e.g. "Option-c c" => "ç"), use these settings:
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'none)
(Put these commands in your ~/.emacs or ~/.emacs.d/init.el emacs startup file, and restart Emacs, or just "M-x eval-buffer" while editing the file.)

- 15,002
- 2
- 49
- 43
(setq default-input-method "MacOSX")
(setq mac-command-modifier 'meta
mac-option-modifier nil
mac-allow-anti-aliasing t
mac-command-key-is-meta t)
Try this. You will be able to use the Alt key as a AltGR and for all the old M-x functions you will have to use your command key.

- 74
- 1
- 1
Bind the relevant keyboard shortcuts to anonymous functions that insert those characters, for example add these lines to ~/.emacs
for European Portuguese:
(global-set-key "\M-(" (lambda () (interactive) (insert "{")))
(global-set-key "\M-)" (lambda () (interactive) (insert "}")))
(global-set-key "\M-8" (lambda () (interactive) (insert "[")))
(global-set-key "\M-9" (lambda () (interactive) (insert "]")))
Then save ~/.emacs
with C-x C-s
and reload it with M-x load-file
and type ~/.emacs
.
One downside is that this does not work in the mini-buffer, and typing "Alt-9" will insert text in the buffer and not the mini-buffer.
Comparison with other solutions: This solution maintains compatibility with other shortcuts using M-
. The solutions by @monotux, @sanityinc, and Abdul Bijur V A do work, but they do not maintain that compatibility, e.g. Cmd-Q
no longer quits the program and M-x
no longer calls the mini-buffer to execute commands.
The solution by @patrikha doesn't suit touch-typing, which requires the same modifier commands on the right and the left side of the keyboard (Command, Alt/Option, Shift, and Control). For example, with this solution doing M-x
requires the left thumb on the left Alt
key and the left index finger on the S
key, instead of the right thumb on the right Alt
key. You could (setq mac-left-option-modifier nil)
, but that might require a change in habits for letters on the right side of the keyboard.
Notes: If you use AquaMacs, the wiki has a work-around in the section "Inputting {}[] etc. on non-English keyboards, or other keys with the Option modifier".
I also add this line to the end of ./emacs
to show the matching of brackets and braces: (show-paren-mode)
.

- 5,025
- 4
- 29
- 64
Using Aquamacs:
From the main menu, go to Options - Option, command, meta keys and select "option for composed characters".
The braces and the brackets work as with the standard Mac keyboard.

- 11
- 1
I had the same issue with a french keyboard. It looks like an Aquamacs issue (Carbon Emacs does not replace { with ()).
The change in emacs above work fine and I could type brackets but I could not use standard shortcuts anymore (Ctrl+C/Ctrl+V for instance).
Aquamacs provides a workaround. Menu Bar > Options > Option, Command, Meta keys > select ...Meta & French
It worked fine for me. However it may not work for swedish, no swedish keyboard option.

- 71
- 4
You don't need to remember those programming like things: Here is the answer. Go to Keyboard preferences, and check the "Show keyboard and character viewer in menu bar". After that, check on the menu bar near the battery meter for the icon and start double clicking any character you want.