How to type letters with accents and diacritics in Emacs
I’ve heard a lot of good things about Emacs and Org-mode package as the approach to write and organize plain-text notes. I recently found a doom-emacs project and I decided to give it a try. Unfortunately, in the default configuration, I was unable to type polish characters. Here are two solutions, how to fix it.
Problem
The option key in macOS is used to input non-ASCII characters, e.g., polish letters like “ąęść”. However, in emacs, this key is used as a <Meta>
modifier. Thankfully, emacs is highly configurable, so it’s not a problem to change its behavior, including <Meta>
key binding.
Preparation
You need to locate your configuration file. I use the doom-emacs configuration framework, so my configuration file is placed in ~/.doom.d/config.el
.
After each change, you should sync your local configuration with the emacs configuration using the following command. I assume that you store your emacs configuration in the default directory. Otherwise, you have to locate the doom binary in your setup.
~/.emacs.d/bin/doom sync
But first, let’s go to your configuration. You can go to the list of your configuration files directly from doom-emacs by typing sequentially SPC f P
(case is important). Then, select the config.el file and press RET
.
Go to the bottom of the configuration file by pressing the g
key once.
Solution 1: Use command key as <Meta> modifier
Since you need option key to behave in a standard way, you need to assign <Meta>
modifier to another key. The emacs wiki proposes using command key as <Meta>
modifier.
Put this snippet in your configuration file and sync it with emacs-doom.
(setq mac-option-key-is-meta nil)
(setq mac-command-key-is-meta t)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier nil)
In this case, you’ll lose another modifier called <Super>. If you want to keep both <Meta> and <Super> modifiers bounded, you can use the second solution.
Solution 2: Use only left option key as <Meta> modifier
I use the right option key to write accents. It means that I can still use the left option key as the <Meta>
modifier. Emacs allows you to change the behavior of different keys, so you can turn off a binding of right option key.
(setq mac-right-option-modifier 'none)
Now, you can use left option as <Meta>
and right option to write accents.
Have fun with Emacs but remember to get your things done!