Function: dtrt-indent--analyze
dtrt-indent--analyze is a natively compiled function defined in
dtrt-indent.el.
Signature
(dtrt-indent--analyze HISTOGRAM-AND-TOTAL-LINES)
Documentation
Analyze the histogram.
HISTOGRAM-AND-TOTAL-LINES is a tuple with the first item being the histogram, the second item being the total number of lines considered in the histogram.
Returns a map with the following entries:
TBD
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-and-total-lines)
"Analyze the histogram.
HISTOGRAM-AND-TOTAL-LINES is a tuple with the first item being
the histogram, the second item being the total number of lines
considered in the histogram.
Returns a map with the following entries:
TBD"
(let* ((analysis
(let ((try-offset dtrt-indent-min-offset)
unsorted-analysis)
(while (<= try-offset dtrt-indent-max-offset)
(setq
unsorted-analysis
(append unsorted-analysis
(list (dtrt-indent--analyze-histogram-try-offset
try-offset
(nth 0 histogram-and-total-lines)
(nth 1 histogram-and-total-lines)))))
(setq try-offset (1+ try-offset)))
(sort unsorted-analysis (lambda (x y) (> (nth 1 x)
(nth 1 y))))))
(analysis-iterator analysis))
(while analysis-iterator
(let ((analysis-entry (car analysis-iterator)))
(dolist (other-analysis-entry (cdr analysis-iterator))
(let ((deviation (abs (- (nth 1 other-analysis-entry)
(nth 1 analysis-entry)))))
(when (and (not (nth 3 analysis-entry))
(eq 0 (mod (car other-analysis-entry)
(car analysis-entry)))
(> dtrt-indent-max-merge-deviation
(* 100.0 deviation)))
(setcdr
(cddr analysis-entry)
(list
(format "\
merged with offset %s (%.2f%% deviation, limit %.2f%%)"
(nth 0 other-analysis-entry)
(* 100.0 deviation)
dtrt-indent-max-merge-deviation)))))))
(setq analysis-iterator (cdr analysis-iterator)))
(let (best-guess)
(dolist (guess analysis)
(cond
((and (null best-guess)
(null (nth 3 guess)))
(setq best-guess guess))))
(let* ((confidence
(if best-guess
(nth 1 best-guess)
0))
(total-lines (nth 1 histogram-and-total-lines))
(enough-relevant-lines
(>= total-lines dtrt-indent-min-relevant-lines))
(hard-tab-percentage (if (> total-lines 0)
(/ (float (nth 2 histogram-and-total-lines))
total-lines)
0))
(soft-tab-percentage (if (> total-lines 0)
(/ (float (nth 3 histogram-and-total-lines))
total-lines)
0))
(change-indent-tabs-mode)
(indent-tabs-mode-setting)
(rejected
(cond
((null best-guess)
"no best guess")
((< (* 100.0 (nth 1 best-guess))
dtrt-indent-min-quality)
(format "best guess below minimum quality (%f < %f)"
(* 100.0 (nth 1 best-guess))
dtrt-indent-min-quality))
((not enough-relevant-lines)
(format "not enough relevant lines (%d required)"
dtrt-indent-min-relevant-lines)))))
(cond
((not enough-relevant-lines))
((or (= 0 hard-tab-percentage)
(>= (/ soft-tab-percentage
hard-tab-percentage)
(+ 1.0 (/ dtrt-indent-min-soft-tab-superiority 100.0))))
(setq change-indent-tabs-mode t)
(setq indent-tabs-mode-setting nil))
((or (= 0 soft-tab-percentage)
(>= (/ hard-tab-percentage
soft-tab-percentage)
(+ 1.0 (/ dtrt-indent-min-hard-tab-superiority 100.0))))
(setq change-indent-tabs-mode t)
(setq indent-tabs-mode-setting t)))
(list (cons :histogram (car histogram-and-total-lines))
(cons :total-lines total-lines)
(cons :analysis analysis)
(cons :best-guess best-guess)
(cons :hard-tab-lines (nth 2 histogram-and-total-lines) )
(cons :hard-tab-percentage hard-tab-percentage)
(cons :soft-tab-lines (nth 3 histogram-and-total-lines) )
(cons :soft-tab-percentage soft-tab-percentage)
(cons :change-indent-tabs-mode change-indent-tabs-mode)
(cons :indent-tabs-mode-setting indent-tabs-mode-setting)
(cons :rejected rejected)
(cons :confidence confidence))))))