[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: :align-to space spec and line wrap
From: |
Eli Zaretskii |
Subject: |
Re: :align-to space spec and line wrap |
Date: |
Tue, 25 Apr 2023 10:22:49 +0300 |
> From: Qiantan Hong <qthong@stanford.edu>
> Date: Mon, 24 Apr 2023 19:23:48 +0000
>
> I use the :align-to space spec to right align texts, like this:
>
> (defun k-insert-fill-right (string)
> ;; More correct than `k-fill-right' in some cases, respect current
> ;; buffer settings (e.g. invisibility spec)
> (let ((from (point)))
> (insert " " string)
> (save-restriction
> (narrow-to-region (1+ from) (point))
> (let ((width (car (buffer-text-pixel-size))))
> (widen)
> (put-text-property from (1+ from)
> 'display
> `(space :align-to (- right-fringe (,width))))))
> nil))
>
> It works when there is no line wrap. However, when there is line wrap,
> the space width shrink to zero rather than fill to (- right-fringe
> (,width)) position on the new line. Seem that the width calculation
> does not take line wrap into account. Is this intended?
The :align-to display spec counts columns, and column number doesn't
get reset to zero when the line is continued on the next screen line.
The column numbers on the continuation lines keep counting from the
last column displayed on the previous screen line.
So you are in effect trying to align to a column whose number is
smaller than the column where the text is displayed, and thus the
space width indeed comes out as zero, because you are already past the
target column.
> Is the behavior that align to the right position on the new line
> possible to implement?
You need to dynamically calculate the value of the column for
continuation lines.