Function: dtrt-indent--analyze-histogram-try-offset
dtrt-indent--analyze-histogram-try-offset is a natively compiled
function defined in dtrt-indent.el.
Signature
(dtrt-indent--analyze-histogram-try-offset TRY-OFFSET HISTOGRAM TOTAL-LINES)
Documentation
Return match information for the given offset.
TRY-OFFSET is the offset to try, HISTOGRAM is the previously calculated indentation histogram, TOTAL-LINES is the total number of lines for which the histogram was calculated.
Returns a list in the format (TRY-OFFSET, PERCENTAGE, MATCHING-INDENTATIONS, REJECT-REASON) where TRY-OFFSET is the offset that was passed in as the first argument, PERCENTAGE is the percentage of lines (0..1) with indentation levels that are a multiple of TRY-OFFSET, MATCHING-INDENTATIONS is the number of distinct indentation levels found that are a multiple of TRY-OFFSET, and REJECT-REASON, if non-nil, is a string explaining why TRY-OFFSET should be rejected.
Source Code
;; Defined in /nix/store/xl774j723v677bsfsybzln3vi6w0fpm3-emacs-packages-deps/share/emacs/site-lisp/elpa/dtrt-indent-20260709.2011/dtrt-indent.el
(defun dtrt-indent--analyze-histogram-try-offset (try-offset
histogram
total-lines)
"Return match information for the given offset.
TRY-OFFSET is the offset to try, HISTOGRAM is the previously
calculated indentation histogram, TOTAL-LINES is the total number
of lines for which the histogram was calculated.
Returns a list in the format (TRY-OFFSET, PERCENTAGE,
MATCHING-INDENTATIONS, REJECT-REASON) where TRY-OFFSET is the
offset that was passed in as the first argument, PERCENTAGE is
the percentage of lines (0..1) with indentation levels that are a
multiple of TRY-OFFSET, MATCHING-INDENTATIONS is the number of
distinct indentation levels found that are a multiple of
TRY-OFFSET, and REJECT-REASON, if non-nil, is a string explaining
why TRY-OFFSET should be rejected."
(let ((total-matching-lines 0)
(matching-indentations 0))
(dolist (histogram-entry histogram)
(when (eq 0 (mod (nth 0 histogram-entry) try-offset))
(setq total-matching-lines (+ total-matching-lines
(nth 1 histogram-entry)))
(setq matching-indentations (1+ matching-indentations))))
(list try-offset
(/ (float total-matching-lines) total-lines)
matching-indentations
(cond
((< matching-indentations
dtrt-indent-min-matching-indentations)
(format "\
rejected: too few distinct matching offsets (%d required)"
dtrt-indent-min-matching-indentations))
(t
nil)))))