macos 无法在 emacs 中输入大括号和方括号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3376863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:05:56  来源:igfitidea点击:

Unable to type braces and square braces in emacs

macosemacskeyboardkeyboard-layout

提问by Niclas ?strand

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.

我正在运行 Mac OS X 和 GNU Emacs 22.3.1。我使用瑞典语键盘。我无法输入括号{}[]在Emacs。尝试键入大括号时,我得到括号。由于我对 Mac 和 emacs 还很陌生,因此我需要一些帮助来配置 emacs 才能做到这一点。

回答by monotux

(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 :)

这是我用于我的瑞典语键盘的。如果您使用它,它甚至可以与 svorak A5 一起使用 :)

回答by patrikha

You could also try:

你也可以试试:

(setq mac-option-key-is-meta t)
(setq mac-right-option-modifier nil)

回答by sanityinc

I'm assuming that you're using a graphical emacs, and not just using the OS X bundled version from within Terminal.

我假设您使用的是图形 emacs,而不仅仅是在终端中使用 OS X 捆绑版本。

To ensure that Emacs responds to keystrokes in the same way as other OS X apps, try the following:

要确保 Emacs 以与其他 OS X 应用程序相同的方式响应击键,请尝试以下操作:

(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:

特别是,如果您想使用 Option 键输入不在键盘上的扩展字符(例如“Option-c c”=>“?”),请使用以下设置:

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

(将这些命令放在您的 ~/.emacs 或 ~/.emacs.d/init.el emacs 启动文件中,然后重新启动 Emacs,或者在编辑文件时仅使用“Mx eval-buffer”。)

回答by Abdul Bijur V A

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

试试这个。您将能够将 Alt 键用作 AltGR,对于所有旧的 Mx 功能,您必须使用命令键。

回答by miguelmorin

Bind the relevant keyboard shortcuts to anonymous functions that insert those characters, for example add these lines to ~/.emacsfor European Portuguese:

将相关的键盘快捷键绑定到插入这些字符的匿名函数,例如将这些行添加到~/.emacs欧洲葡萄牙语:

(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 ~/.emacswith C-x C-sand reload it with M-x load-fileand type ~/.emacs.

然后保存~/.emacsC-x C-s与重新加载M-x load-file和类型~/.emacs

One downside is that this does notwork in the mini-buffer, and typing "Alt-9" will insert text in the buffer and not the mini-buffer.

一个缺点是,这并没有工作在小缓冲区,然后键入“ALT-9”将插入在缓冲区文本,而不是小缓冲区。

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-Qno longer quits the program and M-xno longer calls the mini-buffer to execute commands.

与其他解决方案的比较:此解决方案保持与其他使用M-. @monotux、@sanityinc 和 Abdul Bijur VA 的解决方案确实有效,但它们没有保持这种兼容性,例如Cmd-Q不再退出程序并且M-x不再调用迷你缓冲区来执行命令。

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-xrequires the left thumb on the left Altkey and the left index finger on the Skey, instead of the rightthumb on the right Altkey. 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.

@patrikha 的解决方案不适合触摸输入,它需要在键盘的右侧和左侧使用相同的修饰符命令(Command、Alt/Option、Shift 和 Control)。例如,这个解决方案M-x需要左手拇指放在左键上,左手Alt食指放在S键上,而不是右手拇指放在右手Alt键上。您可以(setq mac-left-option-modifier nil),但这可能需要改变键盘右侧字母的习惯。

Notes: If you use AquaMacs, the wikihas a work-around in the section "Inputting {}[] etc. on non-English keyboards, or other keys with the Option modifier".

注意:如果您使用 AquaMacs,维基在“在非英语键盘或其他带有 Option 修饰符的键上输入 {}[] 等”部分有一个变通方法。

I also add this line to the end of ./emacsto show the matching of brackets and braces: (show-paren-mode).

我还将这一行添加到的末尾./emacs以显示括号和大括号的匹配:(show-paren-mode)

回答by Francesco

Using Aquamacs:

使用 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.

大括号和括号与标准 Mac 键盘一样工作。

回答by cfalguiere

I had the same issue with a french keyboard. It looks like an Aquamacs issue (Carbon Emacs does not replace { with ()).

我在使用法语键盘时遇到了同样的问题。看起来像是 Aquamacs 问题(Carbon Emacs 没有将 { 替换为 ())。

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

上面 emacs 中的更改工作正常,我可以输入括号,但我不能再使用标准快捷方式(例如 Ctrl+C/Ctrl+V)。

Aquamacs provides a workaround. Menu Bar > Options > Option, Command, Meta keys > select ...Meta & French

Aquamacs 提供了一种解决方法。菜单栏 > 选项 > 选项、命令、元键 > 选择 ...元和法语

It worked fine for me. However it may not work for swedish, no swedish keyboard option.

它对我来说很好。但是它可能不适用于瑞典语,没有瑞典语键盘选项。

回答by user151019

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

我会尝试基于 Cocoa 的 emacs,即版本 23。对于 mac 集成的 emacs,我会尝试Aquamacs

回答by Julo Ratumo

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.

你不需要记住那些编程之类的东西:这就是答案。转到键盘首选项,然后选中“在菜单栏中显示键盘和字符查看器”。之后,检查电池表附近的菜单栏上的图标并开始双击您想要的任何字符。