I have been writing a document with a not monospaced font, because it is not code but only text. This is a document written in reStructuredText, with the file ending .rst and when it is opened in emacs, it enters the correct mode and shows reST as mode in the bar at the bottom.

Earlier, I was looking how to always display current row and column of the cursor, in order to know, how long the underlining characters of a heading in reST have to be, when using a not monospaced font. Everything worked find, but then I realized, that there is an error in the document. Some heading was not recognized properly.

The reason is, that emacs shows a wrong column count of the cursor when there is a ü in that line. Since I entered as many underlining characters as emacs told me the number of the column was when being at the last position in the heading text line, I entered one underlining characters too many.

I want emacs to only count äöü and ÄÖÜ and potentially ß as one column, which it also looks like, so that I can have the correct number of underlining characters for a heading and do not need to check for German umlaute in a heading before entering the correct number of underlining characters.

The specific example in my case is:

Schlussfolgerungen bezüglich Code-Editoren

(note that with not monospaced font, this will not be as nicely aligned)

  • When I place the cursor at the end of the text line, the column count shows: 43
  • When I place the cursor at the end of the underlining characters line, the column count shows: 42

How can I fix this?

I already tried adding a preferred encoding to my ~/.emacs file:

(prefer-coding-system 'utf-8)

and a coding line in the first row of my file .. # -*- coding: utf-8 -*-. Note the two dots ... They are necessary, because the file will be automatically processed and I do not want any "coding: bla" to show up in the end result, so maybe that this line does not help at all.

Edit 1

The output of C-u C-x =:

             position: 106656 of 143714 (74%), column: 22
            character: ü (displayed as ü) (codepoint 252, #o374, #xfc)
    preferred charset: chinese-gbk (GBK Chinese simplified.)
code point in charset: 0xA8B9
               script: latin
               syntax: w    which means: word
             category: .:Base, L:Left-to-right (strong), c:Chinese, j:Japanese, l:Latin
             to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME"
          buffer code: #xC3 #xBC
            file code: #xC3 #xBC (encoded by coding system utf-8-unix)
              display: by this font (glyph code)
    xft:-DAMA-Ubuntu-light-normal-normal-*-16-*-*-*-*-0-iso10646-1 (#xD7)

Character code properties: customize what to show
  general-category: Ll (Letter, Lowercase)
  decomposition: (117 776) ('u' '̈')

There are text properties here:
  face                 (rst-level-3)
  font-lock-multiline  t
  fontified            t

It says preferred charset: chinese-gbk (GBK Chinese simplified.) there, that might be because of one environment variable I had to set, to be able to write Chinese characters in emacs using fcitx. I start emacs with the following command inside a launcher of XFCE desktop environment:

/bin/bash -c "XMODIFIERS=@im=fcitx LC_CTYPE=\"zh_CN.UTF-8\" emacs %F"

I only need this for writing Chinese in emacs, not because of any other preferences, so if there is an alternative for this, I am open to hearing it. So far this is the only workaround I found. That this is the cause is only a guess though.

Edit 2

When I start emacs with:

emacs -Q &

The count is 42 for both lines. So I guess it is my config then? Here is my ~/.emacs file:

;; deactivate version control integration, so that emacs starts up faster
(setq vc-handled-backends ())
;(setq-default vc-handled-backends nil)
;(eval-after-load "vc" '(remove-hook 'find-file-hooks 'vc-find-file-hook))

;; Installation of el-get
(add-to-list 'load-path "~/.emacs.d/el-get/el-get")
    (unless (require 'el-get nil 'noerror)
            (url-retrieve-synchronously "https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
            (goto-char (point-max))
(add-to-list 'el-get-recipe-path "~/.emacs.d/el-get-user/recipes")
(el-get 'sync)

;; other stuff
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
     ["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"])
 '(column-number-mode t)
 '(custom-enabled-themes (quote (suscolors)))
       ("b9b1a8d2ec1d5c17700e1a09256f33c2520b26f49980ed9e217e444c381279a9" default)))
 '(lisp-body-indent 2)
 '(lisp-indent-offset 2)
 '(neo-show-hidden-files t)
 '(neo-theme (quote ascii))
 '(python-shell-buffer-name "Python Console")
 '(send-mail-function (quote smtpmail-send-it))
 '(show-paren-mode t)
 '(size-indication-mode t)
 '(smtpmail-smtp-server "smtp.gmail.com")
 '(smtpmail-smtp-service 25)
 '(tool-bar-mode nil)
 '(word-wrap t))

 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(cursor ((t (:background "gold" :foreground "#151718"))))
 '(mode-line ((t (:background "black" :foreground "#4499FF"))))
 '(neo-dir-link-face ((t (:foreground "deep sky blue" :slant normal :weight bold :height 120 :family "Fantasque Sans Mono"))))
 '(neo-file-link-face ((t (:foreground "White" :weight normal :height 120 :family "Fantasque Sans Mono"))))
 '(neo-root-dir-face ((t (:foreground "lightblue" :weight bold))))
 '(show-paren-match ((t (:background "#000000" :foreground "spring green" :underline nil :weight ultra-bold))))
 '(show-paren-mismatch ((t (:foreground "red" :weight bold)))))

(require 'package) ;; You might already have this line
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize) ;; You might already have this line

; SAVE SESSIONS - save sessions to restore buffers on next startup
(desktop-save-mode 1)
;; remember cursor position in file
(require 'saveplace)
(setq-default save-place t)

; load theme on startup
(add-hook 'emacs-startup-hook (load-theme 'suscolors))
(set-face-attribute 'region nil :foreground "#FF00FF" :background "#000")

;; ===== FONT SETTINGS =====
(set-default-font "Inconsolata LGC-10:weight=normal:antialias=1")

;; functions for having buffer specific fonts

;; Use variable width font faces in current buffer
(defun my-buffer-face-mode-variable ()
  "Set font to a variable width (proportional) fonts in current buffer"
  (setq buffer-face-mode-face '(:family "Ubuntu Light" :height 120 :weight light)) ;;light thin regular book

;; Use monospaced font faces in current buffer
(defun my-buffer-face-mode-fixed ()
  "Sets a fixed width (monospace) font in current buffer"
  (setq buffer-face-mode-face '(:family "Inconsolata LGC" :height 100 :weight normal))

;; Set default font faces for Info and ERC modes
(add-hook 'rst-mode-hook 'my-buffer-face-mode-variable)

;; ===== turn on highlighting current line =====
(global-hl-line-mode 1)
(set-face-background 'hl-line "#303030")
(set-face-foreground 'highlight nil) ;; To keep syntax highlighting in the current line

;; highlight matching parenthesis
(show-paren-mode 1)
(setq-default show-paren-delay 0) ;; 0 delay
(setq-default show-paren-style 'parenthesis) ;;'parenthesis is another possible value, only highlighting the brackets

(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default tab-stop-list (number-sequence 4 200 4))

(defvaralias 'c-indent-level 'tab-width)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'sgml-indent-level 'tab-width)
(defvaralias 'sgml-basic-offset 'tab-width)

(add-hook 'racket-mode-hook
          (function (lambda ()
                      (setq indent-tabs-mode nil
                            tab-width 2))))
(add-hook 'pythonracket-mode-hook
          (function (lambda ()
                      (setq indent-tabs-mode nil
                            tab-width 4)
                      (setq-default python-indent 4))))
;; word wrap
;; for reStructuredText mode
(add-hook 'rst-mode-hook
  (function (lambda ()
          (setq word-wrap t))))
(add-hook 'org-mode-hook
  (function (lambda ()
          (global-set-key (kbd "C-c t") 'toggle-truncate-lines))))

;; make return key also do indent, globally
(electric-indent-mode 1)

(setq-default mouse-wheel-scroll-amount '(5 ((shift) . 5))) ;; two lines at a time    
(setq-default mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq-default mouse-wheel-follow-mouse 't) ;; scroll window under mouse    
(setq-default scroll-step 5) ;; keyboard scroll one line at a time
(scroll-bar-mode -1)

;; case-insensitive minibuffer completion
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)

(require 'multiple-cursors)

(require 'linum)
(add-hook 'prog-mode-hook 'linum-on)
;; set fontsize
(eval-after-load "linum"
  '(set-face-attribute 'linum nil :height 80))

(delete-selection-mode 1)

(defun duplicate-line()
  (move-beginning-of-line 1)

(defun my-indent-region (N)
  (interactive "p")
  (if (use-region-p)
      (progn (indent-rigidly (region-beginning) (region-end) (* N 4))
         (setq deactivate-mark nil))
    (self-insert-command N)))

(defun my-unindent-region (N)
  (interactive "p")
  (if (use-region-p)
      (progn (indent-rigidly (region-beginning) (region-end) (* N -4))
         (setq deactivate-mark nil))
    (self-insert-command N)))

;; This function toggles the case of the selected text.
(defun toggle-case ()
  (when (region-active-p)
      ((i 0)
       (return-string "")
       (input (buffer-substring-no-properties (region-beginning) (region-end))))
      (while (< i (- (region-end) (region-beginning)))
      ((current-char (substring input i (+ i 1))))
        (string= (substring input i (+ i 1)) (downcase (substring input i (+ i 1))))
        (setq return-string
          (concat return-string (upcase (substring input i (+ i 1)))))
        (setq return-string
          (concat return-string (downcase (substring input i (+ i 1)))))))
    (setq i (+ i 1)))

    (delete-region (region-beginning) (region-end))
    (insert return-string))))

;; set options for completion
(setq hippie-expand-try-functions-list
    ;; try-complete-file-name-partially
    ;; try-complete-file-name
    ;; try-expand-list
    ;; try-expand-line


(setq-default doc-view-pdfdraw-program "mudraw")
(setq-default doc-view-continuous t)

(require 'ispell)
(add-to-list 'ispell-local-dictionary-alist '("deutsch-hunspell"
                                          ("-d" "de_DE"); Dictionary file name

(add-to-list 'ispell-local-dictionary-alist '("english-hunspell"
                                          ("-d" "en_US")

(setq ispell-program-name "hunspell"          ; Use hunspell to correct mistakes
      ispell-dictionary   "deutsch-hunspell") ; Default dictionary to use

(defun switch-dictionary-de-en ()
  "Switch german and english dictionaries."
  (let* ((dict ispell-current-dictionary)
     (new (if (string= dict "deutsch-hunspell") "english-hunspell"
    (ispell-change-dictionary new)
    (message "Switched dictionary from %s to %s" dict new)))

(prefer-coding-system 'utf-8)

(dolist (key '("\C-g"))
  (global-unset-key key))

(define-key global-map (kbd "RET") 'newline-and-indent)
(define-key global-map (kbd "<C-return>") 'newline)
(global-set-key (kbd "<C-mouse-5>") (lambda () (interactive) (text-scale-decrease 1)))
(global-set-key (kbd "<C-mouse-4>") (lambda () (interactive) (text-scale-increase 1)))
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C-n") 'set-mark-command)
(global-set-key (kbd "C-d") 'duplicate-line)
(global-set-key (kbd "C->") 'my-indent-region)
(global-set-key (kbd "C-<") 'my-unindent-region)
(global-set-key (kbd "<C-tab>") 'hippie-expand)
(global-set-key (kbd "<f8>") 'neotree-toggle)
(global-set-key (kbd "C-~") 'toggle-case)
(global-set-key (kbd "C-d") 'kill-whole-line)
(global-set-key (kbd "M-<left>") 'backward-sexp)
(global-set-key (kbd "M-<right>") 'forward-sexp)
;; moving between windows
(global-set-key (kbd "s-<left>") 'windmove-left)
(global-set-key (kbd "s-<right>") 'windmove-right)
(global-set-key (kbd "s-<up>") 'windmove-up)
(global-set-key (kbd "s-<down>") 'windmove-down)
;; rebinding combination for zap-to-char to the installed zop-to-char
(global-set-key [remap zap-to-char] 'zop-up-to-char)
(global-set-key (kbd "C-g l") 'goto-last-change)
;; spelling change dictionary
(global-set-key (kbd "C-c d") 'switch-dictionary-de-en)
(global-set-key (kbd "C-c S-h") 'highlight-regexp)
(global-set-key (kbd "C-c h") 'highlight-phrase)
(global-set-key (kbd "C-c u") 'unhighlight-regexp)

This is probably a bit much. There are comments at least describing what the purpose of things is. I am not an elisp expert, so it is rather a collection of a lot of copied stuff from here or there as fixes for getting emacs customized.

Edit 3

The environment variables do not seem to be the cause. I just tried running:

XMODIFIERS=@im=fcitx LC_CTYPE=\"zh_CN.UTF-8\" emacs -Q &

And that did not show the described issue of wrong count of columns. So I guess it really is something in my ~/.emacs file, except if the -Q option somehow makes emacs ignore these environment variables. The C-u C-x = on ü in this case results in:

         position: 214 of 276 (77%), column: 22
        character: ü (displayed as ü) (codepoint 252, #o374, #xfc)
    preferred charset: unicode-bmp (Unicode Basic Multilingual Plane (U+0000..U+FFFF))
code point in charset: 0xFC
           script: latin
           syntax: w    which means: word
         category: .:Base, L:Left-to-right (strong), c:Chinese, j:Japanese, l:Latin
         to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME"
      buffer code: #xC3 #xBC
        file code: #xC3 #xBC (encoded by coding system utf-8-unix)
          display: by this font (glyph code)
    xft:-PfEd-DejaVu Sans Mono-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1 (#xBE)

Character code properties: customize what to show
  general-category: Ll (Letter, Lowercase)
  decomposition: (117 776) ('u' '̈')

There are text properties here:
  fontified            t

Which shows a more appropriate preferred encoding. That might be the difference.

Edit 4

Apparently the counting issue only appears with lower case ü, not with the other Umlaute.

Edit 5

As suggested in one of the answers, I tried running emacs with the following command

XMODIFIERS=@im=fcitx LC_CTYPE="zh_CN.UTF-8" emacs -q

Running it like this, the issue persists. I read in the --help of emacs, that this tells emacsnot to load the ~/.emacs and default.el file. I am using a ~/.emacs file.

Edit 6

I regenerated locales as described in this post and set the locale to en_US.utf-8 using:

export LC_ALL="en_US.utf-8"

After that I closed the terminal in which I did that. Then when starting emacs using either -q or -Q, the issue is gone. So I went about trying to comment out more and more of my .emacs file and starting emacs again by:

/bin/bash -c "XMODIFIERS=@im=fcitx LC_CTYPE=\"zh_CN.UTF-8\" emacs"

However, even when the complete .emacs file is commented out, the issue persists. So I went ahead and started emacs without any parameters:


And the issue is gone. So a bad premonition came up in my head: "Great, do I now have to choose between being able to write Chinese and having the correct column count?" So I tried again a slightly different start, still with everything commented out in the .emacs file:

XMODIFIERS=@im=fcitx emacs

The issue is gone. But I cannot use my input method fcitx anymore :(

So I guess I'll simply have to remember this when I want to write some Chinese or create a second launcher for that purpose.

  • Works for me, according to C-x =, I get column 42 on both lines. What does C-u C-x = say with point on ü?
    – npostavs
    Feb 19, 2017 at 17:20
  • @npostavs Updated : ) Feb 19, 2017 at 17:29
  • I can reproduce this with emacs -Q and then M-x set-language-environment Chinese-GBK RET
    – npostavs
    Feb 20, 2017 at 13:58

2 Answers 2


Q: How can I fix this?

A1: Now that you know that the environment variable makes the difference, see if you can get the intended effect without it. Searching the net for "LANG vs. LC_CTYPE", this question pops up: https://stackoverflow.com/questions/30479607/explain-the-effects-of-export-lang-lc-ctype-lc-all, which explains:

LC_CTYPE This variable determines the locale category for character handling functions, such as tolower(), toupper() and isalpha(). This environment variable determines the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters), the classification of characters (for example, alpha, digit, graph) and the behaviour of character classes. Additional semantics of this variable, if any, are implementation-dependent.

I understand that you want the LC_CTYPE setting for editing of chinese text. Now, a single Emacs instance can hold texts in multiple languages, at the same time - the issue is triggered with german text, after all. However, as documented in Info node "Language Environments", the environment applies to the entire instance, which may not be what you need. Maybe it is possible to use a buffer-specific approach for some aspects. Leave the environment in its default state (de_DE.utf-8, for example), and see if Emacs provides a way to specify chinese character input and handling in a buffer-local fashion. In particular, see set-input-method.


Judging by your use of fctix and XMODIFIERS, your OS is Linux or BSD based and your window system is X11.

Up to now I had not bothered to look up "fctix". I did now, and I see that it is not a concrete input method, but an input method framework. I assume that a concrete input method needs to be chosen to make it actually do any work.

Over the years, I have tried multiple times to understand how "input methods" work on the technical level, and this time is not much different. In particular, the layering is not clear to me. What happens where?

Since you mentioned fonts, I assume that you are using Emacs as a GUI program. As such, I assume that Emacs receives a stream of events that describe what happened on the "physical" input device, e.g. keycodes, and that Emacs translates this event stream into a stream of code points on its own, using its own input method framework. Since different buffers may need different input methods, it seems to me that any input processing outside of Emacs might interfere with Emacs' own input processing.

Side note: I also assume that when Emacs runs as a terminal program, Emacs receives something that is more like a stream of characters, not a stream of event descriptors. Depending on the value of LC_CTYPE and related variables, this character stream may already have been through an "input method" processor at the terminal level, so that no further "input method" processing is required of the application.

(To be continued)


A2: Not a direct answer, rather a strategy to find one. Since I can't comment, I can only provide this as a formal answer. To fix it, you need to first identify what causes your issue (you know that much of course). Use "divide and conquer" to do that. You have already used -Q to determine that the issue is related to some config file code. Have you tried -q? If the issue persists with this option, the cause is in the site files.

(By site files I mean those whose execution -Q suppresses that -q doesn't. Quoting from Emacs -> M-x info -> Emacs -> Entering Emacs -> Emacs Invocation -> Initial Options:

 Do not load ‘site-start.el’ (*note Init File::).  The ‘-Q’ option
 does this too, but other options like ‘-q’ do not.

 Do not include the ‘site-lisp’ directories in ‘load-path’ (*note
 Init File::).  The ‘-Q’ option does this too.

Whether such files exist so that this actually makes a difference depends on your installation. It may be that your distribution includes such files, or that your sysadmin has created such files. )

Otherwise, it's in your user's config file(s). In that case, successively bisect your init file. Divide it roughly in half, preferring to keep related entries together, delete one half, start a second emacs instance (avoiding Emacs-Server), see if the issue persists. If the issue persists, the trigger is in the remaining half, so continue by bisecting it. If the issue is gone, the removed half must have triggered the issue, so re-add it and continue by bisecting that. Continue until you have a minimal set of config entries that triggers the issue.

PS: I share your pain. Pervasive correct handling of non-ASCII characters is still a way off. :-) I applaud everyone who improves this situation, including people who precisely report bugs.

  • Thanks for the debugging input! The issue persists with XMODIFIERS=@im=fcitx LC_CTYPE="zh_CN.UTF-8" emacs -q, so it should be "site files" - I am not completely new to emacs, but probably also not very experienced. I don't know what site files means. Can you explain what they are and what I can do about it? Is it simply everything except my .emacs file? I'll update my OP. Feb 19, 2017 at 21:02
  • I regenerated locales following the instructions in this post: askubuntu.com/a/359932 and setting the locale to LC_ALL="en_US.utf-8" and now the issue is gone when calling with -q and when calling with -Q, so I'll test my config in .emacs next. Feb 19, 2017 at 21:17
  • 2
    I added a section explaining what I mean by "site files", and suggested to look for buffer-local alternatives to LC_CTYPE. Feb 20, 2017 at 9:13
  • The set-input-method thing is nice to have, but unfortunately, it seems to lack the context or phrase analytical skill or functionality of fcitx, which extremely well narrows down which Chinese characters you want, depending on the previous Pinyin syllables you typed. It comes across as some bare bones input method, because of this. I'd much prefer a real input method, specifically fcitx to work, since I am familiar with it, it is modern, does phrase analysis and it is in active development, afaik. I'll check for other methods Emacs provides. Feb 20, 2017 at 20:59
  • Might have been I judged too quickly about that input method thing … It seems to learn combinations of characters I typed before. Will try it some more : ) Feb 20, 2017 at 21:02

It seems there was something inherently wrong with setting LC_CTYPE=\"zh_CN.UTF-8\" in the command to run emacs, which caused this issue. I now created another launcher for emacs, which starts it without this environment variable set. So I have two launchers now:

For enabling Chinese input via fcitx:

/bin/bash -c "XMODIFIERS=@im=fcitx LC_CTYPE=\"zh_CN.UTF-8\" emacs"

and for my daily default usage:

/bin/bash -c "XMODIFIERS=@im=fcitx emacs"

Gave the one for Chinese input a nice icon, and am satisfied for now. Well, if someone can provide a better workaround or even fix, that will be still appreciated ;)

I have a guess what the issue behind the scenes might be. In Chinese Pinyin, the phonetic script, the character ü exists, while the other ones äöÜÄÖß do not exist. So maybe when I set the LC_CTYPE environment variable, it recognizes the difference between characters belonging to Chinese or its phonetic script and everything else. Since Chinese characters are counted as two columns wide (since they are wider or need more space to be readable), it might also count that ü as a special character and thus it becomes a +2 character.

This is the only difference between the Umlaute, which has anything to do with Chinese at least.

  • It seems you could use C-x C-m l to switch between language environments, not really a good solution, but probably better than having multiple launchers
    – npostavs
    Feb 21, 2017 at 13:26

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.