emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pixel padding with variable pitch font


From: Anand Tamariya
Subject: Pixel padding with variable pitch font
Date: Mon, 7 Jun 2021 18:49:01 +0530

If you need to pad space with variable pitch font, and you are unable to use ':align-to display' option for any reason, you can use the following code. This uses unicode spacing characters to insert required amount of space.

Screenshot: https://lifeofpenguin.blogspot.com/2021/06/gnu-emacs.html

(defun company--insert-space (width w)
  "Insert unicode space characters to fit the WIDTH."
  (let ((num 0))
    (dolist (spc '((#x2001 .  1) (#x2000 . 0.5) (#x2004 . 0.33) (#x2005 . 0.25) (#x2006 . 0.16) (#x200A . 0.125)))
      (setq num (floor (/ width w (cdr spc))))
      (if (memq (car spc) '(#x2001 #x2000 #x2004 #x2005))
          ;; Allow finer spaces towards the end for better accuracy
          (setq num (1- num)))
      (when (> num 0)
        (dotimes (i num)
          (insert (car spc)))
        (setq width (- width (* num w (cdr spc))))
        ))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]