Good point, thanks for the suggestion.
I changed the lock-step update to use `pop' and renamed the locals to
`remaining-triplets', `remaining-specs', and `remaining-widths'. I also
extracted the width update to `org-columns--update-column-width', so the
main loop now only expresses the parallel traversal over rows, specs,
and widths.
This reads better to me than the previous version. I am not sure there
is much more to simplify here without changing the shape of the code
more substantially. Do you think this addresses your concern, or would
you still prefer a different structure?
The updated code is below:
(defun org-columns--update-column-width (spec cell widths)
"Update WIDTHS according to SPEC and CELL.
WIDTHS is the current tail of the column widths list. CELL is a
list (SPEC VALUE DISPLAYED-VALUE), as returned by
`org-columns--collect-values'."
(unless (wholenump (org-columns--spec-width spec))
(setcar widths
(max (car widths)
(string-width (nth 2 cell))))))
(defun org-columns--set-widths (rows)
".."
(setq org-columns-current-maxwidths
(let ((widths (mapcar (lambda (spec)
(pcase spec
(`(,_ ,_ ,(and width (pred wholenump)) . ,_)
width)
(`(,_ ,title . ,_) (string-width title))))
org-columns-current-fmt-compiled)))
(dolist (row rows)
(let ((remaining-triplets (cdr row))
(remaining-specs org-columns-current-fmt-compiled)
(remaining-widths widths))
(while (and remaining-triplets remaining-specs remaining-widths)
(org-columns--update-column-width
(car remaining-specs) (car remaining-triplets)
remaining-widths)
(pop remaining-triplets)
(pop remaining-specs)
(pop remaining-widths))))
(apply #'vector widths))))
Best,
--
Slawomir Grochowski