emacs-devel
[Top][All Lists]
Advanced

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

Re: on helm substantial differences


From: Juri Linkov
Subject: Re: on helm substantial differences
Date: Wed, 25 Nov 2020 21:16:10 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> To align the second column, 'completion--insert-strings'
>> inserts " \t" with `(display (space :align-to ,column)).
>>
>> So when completions use \t to separate a character from its name,
>> then the two-column layout schematically looks like this:
>>
>> character1 \t name1   \t with :align-to   character2 \t name2
>>
>> And tab-width doesn't align properly \t between character2 and name2.
>
> I don't think I understand why.  Maybe the value of :align-to needs
> tuning?  If not, what is the problem here?

Tuning means adding :align-to to all '\t'?  E.g.:

character1 (\t :align-to) name1 (\t :align-to) character2 (\t :align-to) name2

But the caller doesn't know the value for the third :align-to.
So instead of this, the caller should calculate :width, e.g.:

character1 (\t :width) name1 (\t :align-to) character2 (\t :width) name2

>> It seems font-get-glyphs can't be used because on wide characters it
>> returns nil:
>>
>> (font-get-glyphs (font-at (point)) 0 1 "𒐫")
>> => [nil]
>
> Is this with point on that wide character?

Got it.  When point is on the character, everything works fine, and this code:

(let ((max-width 0))
    (dotimes (c #x1FFFF)
      (insert c)
      (let* ((font (font-at (1- (point))))
             (glyphs (when font (font-get-glyphs
                                 font 0 1
                                 (string c)))))
        (when (and glyphs (aref glyphs 0))
          (setq max-width (max max-width (aref (aref glyphs 0) 4)))))
      (delete-char -1))
    (ceiling max-width (frame-char-width)))

correctly returns 8, i.e. tab-width for the widest character.

The problem is that this code requires to be run in the selected buffer.
When enclosed in 'with-temp-buffer', it raises an error:

Debugger entered--Lisp error: (error "Specified window is not displaying the 
current buffer")
  font-at(1)

This is a pretty bad limitation.  Maybe better to pre-calculate widths
of all characters and generate a mapping from char to its width.
This will also improve performance - the above code takes 15 seconds.



reply via email to

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