From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Pixel padding with variable pitch font Date: Mon, 07 Jun 2021 16:35:07 +0300 Message-ID: <831r9dhk6s.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17005"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Anand Tamariya Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Jun 08 02:04:16 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lqPE7-0004Da-Vg for ged-emacs-devel@m.gmane-mx.org; Tue, 08 Jun 2021 02:04:15 +0200 Original-Received: from localhost ([::1]:35860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqPE7-0006Fy-1b for ged-emacs-devel@m.gmane-mx.org; Mon, 07 Jun 2021 20:04:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqPDG-0004bD-Dq for emacs-devel@gnu.org; Mon, 07 Jun 2021 20:03:22 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:39388) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqPDF-00009v-UA; Mon, 07 Jun 2021 20:03:21 -0400 Original-Received: from 84.94.185.95.cable.012.net.il ([84.94.185.95]:1843 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqFPO-0003vs-US; Mon, 07 Jun 2021 09:35:15 -0400 In-Reply-To: (message from Anand Tamariya on Mon, 7 Jun 2021 18:49:01 +0530) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:270539 Archived-At: > From: Anand Tamariya > 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)))) > )))) This assumes that, e.g., #x2001 takes the same horizontal space as the SPC character (or the same as a column)? That's only so in fixed-pitch fonts; in variable-pitch fonts the SPC could be much more narrow, and columns are all but meaningless. Caveat emptor!