Function: cider-xref--scan-buffer

cider-xref--scan-buffer is a byte-compiled function defined in cider-xref-source.el.

Signature

(cider-xref--scan-buffer REGEXP FILE &optional EXCLUDE)

Documentation

Collect references matching REGEXP in the current buffer as xref match items.

FILE is the absolute path the locations should point at. Matches inside strings and comments are skipped, using the buffer's syntax table. EXCLUDE, when given, is a (BEG . END) range whose matches are skipped too - used to ignore the namespace form's own require declarations.

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20260822.1520/cider-xref-source.el
            "\\(?:$\\|[^" cider-xref--symbol-chars "]\\)"))) ; right boundary

(defun cider-xref--scan-buffer (regexp file &optional exclude)
  "Collect references matching REGEXP in the current buffer as xref match items.
FILE is the absolute path the locations should point at.  Matches inside strings
and comments are skipped, using the buffer's syntax table.  EXCLUDE, when given,
is a (BEG . END) range whose matches are skipped too - used to ignore the
namespace form's own require declarations."
  (let ((line 1)
        (counted (point-min))   ; position whose line number is `line'
        matches)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward regexp nil t)
        (let ((beg (match-beginning 1))
              (end (match-end 1)))
          (goto-char end)
          (unless (or (ppss-comment-or-string-start (syntax-ppss beg)) ; skip strings and comments
                      (and exclude (>= beg (car exclude)) (< beg (cdr exclude))))
            ;; Advance the line counter incrementally so the whole scan stays
            ;; linear instead of calling `line-number-at-pos' per match.
            (setq line (+ line (save-excursion
                                 (goto-char counted)
                                 (let ((n 0))
                                   (while (search-forward "\n" beg t)
                                     (setq n (1+ n)))
                                   n)))
                  counted beg)
            (save-excursion
              (goto-char beg)
              (let* ((bol (line-beginning-position))
                     (col (- beg bol))
                     (summary (buffer-substring-no-properties
                               bol (line-end-position))))
                (push (xref-make-match (string-trim summary)
                                       (xref-make-file-location file line col)
                                       (- end beg))
                      matches)))))))
    (nreverse matches)))