Function: dtrt-indent--calc-histogram

dtrt-indent--calc-histogram is a natively compiled function defined in dtrt-indent.el.

Signature

(dtrt-indent--calc-histogram LANGUAGE)

Documentation

Calculate an indendation histogram.

The histogram is calculated for the current buffer using LANGUAGE to determine which lines to exclude from the histogram.

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--calc-histogram (language)
  "Calculate an indendation histogram.

The histogram is calculated for the current buffer using LANGUAGE
to determine which lines to exclude from the histogram."
  (let ((histogram (make-hash-table))
        (hard-tab-line-count 0)
        (soft-tab-line-count 0)
        (line-count 0))

    (dtrt-indent--for-each-indentation
     language
     (lambda (histogram-and-count)
       (setq line-count (1+ line-count))
       (when (and (> (current-column) 0)
                  (not (looking-at "$"))
                  (or (not dtrt-indent-ignore-single-chars-flag)
                      (save-excursion
                        (forward-char)
                        (not (looking-at "[ \t]*$")))))
         (puthash (current-column)
                  (1+ (gethash (current-column)
                               (car histogram-and-count) 0))
                  (car histogram-and-count))
         (beginning-of-line)
         (if (looking-at "[\t]+")
             (setq hard-tab-line-count (1+ hard-tab-line-count))
           (setq soft-tab-line-count (1+ soft-tab-line-count)))
         (setcdr histogram-and-count (1+ (cdr histogram-and-count))))
       (< line-count dtrt-indent-max-lines))
     (cons histogram 0))
    (let ((histogram-list '()) (total-lines 0))
      (maphash (lambda (key value)
                 (setq histogram-list (append histogram-list
                                              (list (list key value))))
                 (setq total-lines (+ total-lines value)))
               histogram)
      (list histogram-list
            total-lines
            hard-tab-line-count
            soft-tab-line-count))))