emacs-devel
[Top][All Lists]
Advanced

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

Re: Variable-width font indentation


From: Eli Zaretskii
Subject: Re: Variable-width font indentation
Date: Thu, 08 Mar 2018 15:21:55 +0200

> From: Clément Pit-Claudel <address@hidden>
> Date: Wed, 7 Mar 2018 17:13:09 -0500
> 
> This version is a bit faster, and it uses 'display (space …) instead of ghost 
> strings:
> 
> (defun ~/variable-pitch-indent ()
>   (interactive)
>   (save-excursion
>     (let ((spine [])
>           (prev-bol nil)
>           (prev-eol nil))
>       (goto-char (point-min))
>       (while (not (eobp))
>         (let ((bol (point)))
>           (back-to-indentation)
>           (unless (eolp)
>             (let* ((indentation-amount (current-column))
>                    (trunc-spine-to (min (length spine) indentation-amount)))
>               (setq spine (seq-subseq spine 0 trunc-spine-to))
>               ;; Extend spine based on previous line
>               (when (and prev-bol (< (length spine) indentation-amount))
>                 (let ((beg (+ prev-bol (length spine)))
>                       (end (min prev-eol (+ prev-bol indentation-amount))))
>                   (setq spine (vconcat spine (~/measure-px-widths beg end)))))
>               (setq prev-bol bol prev-eol (point-at-eol))))
>           (dotimes (idx (min (length spine) (- (point) bol)))
>             (let ((w (aref spine idx)))
>               (put-text-property (+ bol idx) (+ bol idx 1)
>                                  'display `(space :width (,w)))))
>           (forward-line 1))))))

It seems you forgot to post ~/measure-px-widths.



reply via email to

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