Function: csv--jit-merge-columns
csv--jit-merge-columns is a natively compiled function defined in
csv-mode.el.
Signature
(csv--jit-merge-columns COLUMN-WIDTHS)
Source Code
;; Defined in /nix/store/3gmjnyw9n226b7k7jamikx980vf8267p-emacs-packages-deps/share/emacs/site-lisp/elpa/csv-mode-1.27/csv-mode.el
(defun csv--jit-merge-columns (column-widths)
;; FIXME: The incremental update (delayed by jit-lock-context-time) of column
;; width is a bit jarring at times. It's OK while scrolling or when
;; extending a column, but not right when enabling the csv-align-mode or
;; when shortening the longest field (or deleting the line containing it),
;; because in that case we have *several* cascaded updates, e.g.:
;; - Remove the line with the longest field of column N.
;; - Edit some line: this line is updated as if its field was the widest,
;; hence its subsequent fields are too much to the left.
;; - The rest is updated starting from the first few lines (according
;; to jit-lock-chunk-size).
;; - After the first few lines, come the next set of few lines,
;; which may cause the previous few lines to need refresh again.
;; - etc.. until arriving again at the edited line which is re-aligned
;; again.
;; - etc.. until the end of the windows, potentially causing yet more
;; refreshes as we discover yet-wider fields for this column.
(let ((old-columns csv--jit-columns)
(changed nil))
(while (and old-columns column-widths)
(when (or (> (caar column-widths) (caar old-columns))
;; Apparently modification-hooks aren't run when the
;; whole text containing the overlay is deleted (e.g.
;; the whole line), so detect this case here.
;; It's a bit too late, but better than never.
(null (overlay-buffer (cdar old-columns))))
(setq changed t) ;; Return non-nil if some existing column changed.
(pcase-let ((`(,width ,beg ,end) (car column-widths)))
(setf (caar old-columns) width)
(move-overlay (cdar old-columns) beg end)))
(setq old-columns (cdr old-columns))
(setq column-widths (cdr column-widths)))
(when column-widths
;; New columns appeared.
(setq csv--jit-columns
(nconc csv--jit-columns
(mapcar (lambda (x)
(pcase-let*
((`(,width ,beg ,end) x)
(ol (make-overlay beg end)))
(overlay-put ol 'csv-width t)
(overlay-put ol 'evaporate t)
(overlay-put ol 'modification-hooks
(list #'csv--jit-width-change))
(cons width ol)))
column-widths))))
changed))