branch: externals/org
commit fc0248d4e8d0777433f260b60e861980bd61a66a
Author: Slawomir Grochowski <[email protected]>
Commit: Slawomir Grochowski <[email protected]>

    ; org-colview: Extract column width update
    
    * lisp/org-colview.el (org-columns--update-column-width): New
    function.
    (org-columns--set-widths): Use it and rename local variables.
    
    Refactoring: Extract Function.
    
    No behavior change.
---
 lisp/org-colview.el | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 0956f34d2d..2378aa85dd 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -335,6 +335,16 @@ displayed without leading stars."
 
 ;;;; Column widths
 
+(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)
   "Compute the maximum column widths from the format and ROWS.
 This function sets `org-columns-current-maxwidths' as a vector of
@@ -360,15 +370,16 @@ where:
                                  (`(,_ ,title . ,_) (string-width title))))
                              org-columns-current-fmt-compiled)))
          (dolist (row rows)
-           (let ((triplets (cdr row))
-                 (specs org-columns-current-fmt-compiled)
-                 (w widths))
-             (while (and triplets specs w)
-               (unless (wholenump (org-columns--spec-width (car specs)))
-                 (setcar w (max (car w) (string-width (nth 2 (car 
triplets))))))
-               (setq triplets (cdr triplets))
-               (setq specs (cdr specs))
-               (setq w (cdr w)))))
+           (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))))
 
 ;;;; Overlay rendering

Reply via email to