Unable to type braces and square braces in emacs
Asked Answered
M

9

47

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.

Masque answered 31/7, 2010 at 4:55 Comment(4)
What you call "square braces" are usually refered to as "brackets". Not that it matters, but its a bit shorter to type.Lustre
Watch out: "brackets" is a regional one. In the US it means square brackets, in the UK, it means round brackets / parenthesis.Fichtean
Unfortunately not one of the answers solved a similar issue on my german keyboard. I don't get any brackets or curly braces at all.Trevelyan
@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) !Kennie
S
66
(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 :)

Starlastarlene answered 31/7, 2010 at 13:58 Comment(11)
I tryed putting this into bouth my ~/.emacs file and my ~/.emacs.d/init.el file but i can't get it to work.Demodulator
Are you sure you're on a mac? ;)Starlastarlene
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.Starlastarlene
I just tryed "emacs -Q and then paste the above into scratch, eval with M-x eval-buffer". But the curly bracets dont work.Demodulator
I'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.Starlastarlene
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?Heathenism
I just opened a question for my issue : #31525461Heathenism
<kbd>C-a =</kbd> 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.Starlastarlene
@Starlastarlene I will just leave it in the scratch as it seems to be working correctly this way, and I never close emacs. ThxRevile
@Revile you can paste them into your ~/.emacs.d/init.el instead, then they are evaluated every time you start Emacs.Starlastarlene
@Starlastarlene i never « start » eMacs ... I live in there 😅, all jokes aside yes I will do that, thank youRevile
B
32

You could also try:

(setq mac-option-key-is-meta t)
(setq mac-right-option-modifier nil)
Buehrer answered 29/10, 2012 at 14:48 Comment(4)
why didn't I discovered that earlier? :DLelandleler
Yes! 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!Drawing
Works for me, too. Actually, didn't need the first line.Priester
I didn't need the first line either.Sequestration
S
10

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

Schober answered 1/8, 2010 at 13:22 Comment(0)
C
5
(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.

Compressibility answered 23/4, 2011 at 18:49 Comment(0)
B
5

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

Bidget answered 18/4, 2018 at 14:19 Comment(0)
C
1

I would try a Cocoa based emacs ie version 23. For a mac integrated emacs I would try Aquamacs

Cithara answered 31/7, 2010 at 6:40 Comment(0)
A
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.

Ashcroft answered 2/3, 2012 at 19:27 Comment(0)
D
1

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.

Dilisio answered 2/6, 2013 at 7:27 Comment(0)
D
-1

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.

Dahlia answered 10/5, 2013 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.