4

Emacs is telling me that a certain character only takes up 1 column, even though it clearly takes up two? Is there a way I can fix this?

incorrect char width

The reason is that I'm doing some calculations in order to "right-align" part of my mode-line. I do this by getting the window-total-width and subtracting from it the (string-width left-part), then appropriately padding based on this. This works great until I show a multi-column character like this. I purposefully made my math involve the amount of columns the string takes, but as shown above, this shows up incorrectly.

  • 1
    Thanks for addressing this issue which bugging me for a long time! – seagle0128 Apr 16 at 18:19
  • Please report this as a bug. – Stefan Apr 16 at 21:49
1

syohex helped me out and pointed me to some code that adjusts the character widths of certain character codes. I adapted it to fit what I'm doing:

  (defun blaenk/set-char-widths (alist)
    (while (char-table-parent char-width-table)
      (setq char-width-table (char-table-parent char-width-table)))
    (dolist (pair alist)
      (let ((width (car pair))
            (chars (cdr pair))
            (table (make-char-table nil)))
        (dolist (char chars)
          (set-char-table-range table char width))
        (optimize-char-table table)
        (set-char-table-parent table char-width-table)
        (setq char-width-table table))))


  ;; argument is an alist of width and list of RANGEs,
  ;; which is the same as the RANGE that set-char-table-range accepts
  (blaenk/set-char-widths
   `((2 . (,(string-to-char (fontawesome "cloud"))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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