[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Variable-width font indentation
From: |
Clément Pit-Claudel |
Subject: |
Re: Variable-width font indentation |
Date: |
Wed, 7 Mar 2018 17:13:09 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 |
On 2018-03-05 20:40, Clément Pit-Claudel wrote:
> On 2018-03-05 20:30, Paul Eggert wrote:
>> On 03/05/2018 05:06 PM, Clément Pit-Claudel wrote:
>>> In variable-pitch mode, each new indentation level has a
>>> slightly-different width, instead of a regular progression of 4
>>> spaces (in Python) and 2 spaces (in Elisp) at each level.
>>
>> That's fine. Although it's only a small thing, to me it's even a
>> small plus, as having every indent level be the same number of pixels
>> unnaturally focuses the reader on a distracting regularity that is
>> not intrinsic to the code.
>
> I've been playing with this a bit more; until now, I'd mostly stopped at my
> previous objection.
>
> The following code gives a preview of what the algorithm that we've been
> discussing produces: [...]
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))))))
… but it doesn't work with tabs.
- Re: Variable-width font indentation, (continued)
- Re: Variable-width font indentation, Daniel Colascione, 2018/03/06
- Re: Variable-width font indentation, Clément Pit-Claudel, 2018/03/06
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/06
- Re: Variable-width font indentation, Clément Pit-Claudel, 2018/03/06
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/06
- Re: Variable-width font indentation, Clément Pit-Claudel, 2018/03/07
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/07
- Re: Variable-width font indentation, Clément Pit-Claudel, 2018/03/09
- Re: Variable-width font indentation,
Clément Pit-Claudel <=
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/08
- Re: Variable-width font indentation, Clément Pit-Claudel, 2018/03/08
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/06
- Re: Variable-width font indentation, Daniel Colascione, 2018/03/06
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/06
- Re: Variable-width font indentation, dancol, 2018/03/06
- Re: Variable-width font indentation, Eli Zaretskii, 2018/03/06
- Re: Variable-width font indentation, Daniel Colascione, 2018/03/06
- Re: Variable-width font indentation, Sam Steingold, 2018/03/06
- Re: Variable-width font indentation, Ricardo Wurmus, 2018/03/06