The problem: When I type a non-ascii character, the character is not wrote and instead a weird key combination is performed, depending on which character I have typed, as if it didn't support utf-8. This strange behavior is true whether I:

  • input non-ascii characters directly from my keyboard (such as the french letter ç)
  • create them with XCompose (such as )
  • input them using a different keyboard layout (I tried a chinese keyboard)

However, this only occurs when I use emacsclient in a terminal. If I start a fresh new emacs program, no problem. If I use emacsclient with GUI, no problem.

Restarting the emacs server doesn't change anything.

Besides that, emacsclient has no problem in reading or showing non-ascii characters (eg. I can open files that contain utf-8 characters and edit them).

What I tried: I tried setting keyboard-coding-system to utf-8 from within an emacsclient session, and it works until I leave it. If I close the session, and open it again, it quits working, even though the server hasn't stopped.

I tried saving it into emacs' configuration via customize, but it doesn't work: each time I close and re-open emacsclient, it comes back to utf-8-unix, saying that it has been changed outside customize (even though in init.el the value is set to utf-8).

I tried the same thing with emacs, and the same thing happens: I can change temporally the value, but when I restart it comes back to the original value. However, I am positively sure I don't overwrite keyboard-coding-system in my configuration. To rule that out, I started emacs with -q (which tells emacs not to read any configuration file, just start as-is), but it still had the value utf-8-unix saying CHANGED outside Customize.

To recap: changing keyboard-coding-system temporarily solves the issue for emacsclient, but I can't make it definitive. And, I have no problem neither in emacs nor in emacsclient GUI with the default value for keyboard-coding-system.

This is especially problematic since my keyboard is full of non-ascii keys and each time I press them by mistake emacs runs commands (depending on which key I have pressed) which is very annoying.


Technical details: I have the same problem on several Linux distros, including a Debian which has emacs 26.1 and NixOS which has the latest stable emacs.


EDIT 1: A comment asked what locale returned in the terminal in which I start emacsclient.

$ locale
  • What does locale in the terminal window where you start emacsclient report?
    – NickD
    May 1, 2021 at 15:30
  • 1
    @NickD since the output didn't really fit in a comment I edited the question to add the output. Btw, I tampered with the locales (as you can see) to get some non-us standard units.
    – jthulhu
    May 1, 2021 at 20:01

1 Answer 1


Does this fix the problem?

(defun my-terminal-keyboard-coding-system (&optional frame)
  "Force the terminal `keyboard-coding-system' to be `utf-8'.

Prevents terminal frames using a coding system based on the locale.
See info node `(emacs) Terminal Coding'."
  (with-selected-frame (or frame (selected-frame))
    (unless window-system
      (set-keyboard-coding-system 'utf-8))))

;; Run now, for non-daemon Emacs...
;; ...and later, for new frames / emacsclient
(add-hook 'after-make-frame-functions 'my-terminal-keyboard-coding-system)

Any time you need to customize terminal-local settings you need to check/set them for every frame that is created, because each given frame can potentially be different to any other (e.g. you can ssh to the server host from multiple different machines each with different terminals and locales, and run an emacsclient to the same single server from each terminal).

  • No, this doesn't solve the issue. On the contrary, this makes emacsclient instantly crash when launched. By contrast, emacs and the server run without problems.
    – jthulhu
    May 2, 2021 at 8:07
  • If you evaluate that same (set-keyboard-coding-system 'utf-8) interactively, does Emacs signal an error? I can reproduce the issue, but only by specifying a coding system that isn't valid to use. See the code of set-keyboard-coding-system for details. It may or may not be better to directly (setq keyboard-coding-system 'utf-8)
    – phils
    May 2, 2021 at 9:04
  • If I run M-x set-keyboard-coding-system ENT utf-8 ENT, it works. If I eval (set-keyboard-coding-system 'utf-8), it works and returns utf-8-unix. By 'it works' I mean it doesn't throw an error.
    – jthulhu
    May 2, 2021 at 9:41
  • And you're doing that from a terminal frame, yes?
    – phils
    May 2, 2021 at 10:13
  • Given that you're ultimately using utf-8-unix, does the code work if you're specifying that directly instead of just the base utf-8 ?
    – phils
    May 2, 2021 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.