Function: elisp-refs--walk
elisp-refs--walk is a byte-compiled function defined in elisp-refs.el.
Signature
(elisp-refs--walk BUFFER FORM START-POS END-POS SYMBOL MATCH-P &optional PATH)
Documentation
Walk FORM, a nested list, and return a list of sublists (with their positions) where MATCH-P returns t. FORM is traversed depth-first (pre-order traversal, left-to-right).
MATCH-P is called with three arguments:
(SYMBOL CURRENT-FORM PATH).
PATH is the first element of all the enclosing forms of CURRENT-FORM, innermost first, along with the index of the current form.
For example if we are looking at h in (e f (g h)), PATH takes the value ((g . 1) (e . 2)).
START-POS and END-POS should be the position of FORM within BUFFER.
Source Code
;; Defined in ~/.emacs.d/elpa/elisp-refs-20230920.201/elisp-refs.el
(defun elisp-refs--walk (buffer form start-pos end-pos symbol match-p &optional path)
"Walk FORM, a nested list, and return a list of sublists (with
their positions) where MATCH-P returns t. FORM is traversed
depth-first (pre-order traversal, left-to-right).
MATCH-P is called with three arguments:
\(SYMBOL CURRENT-FORM PATH).
PATH is the first element of all the enclosing forms of
CURRENT-FORM, innermost first, along with the index of the
current form.
For example if we are looking at h in (e f (g h)), PATH takes the
value ((g . 1) (e . 2)).
START-POS and END-POS should be the position of FORM within BUFFER."
(cond
((funcall match-p symbol form path)
;; If this form matches, just return it, along with the position.
(list (list form start-pos end-pos)))
;; Otherwise, recurse on the subforms.
((consp form)
(let ((matches nil)
;; Find the positions of the subforms.
(subforms-positions
(if (eq (car-safe form) '\`)
;; Kludge: `elisp-refs--sexp-positions' excludes the ` when
;; calculating positions. So, to find the inner
;; positions when walking from `(...) to (...), we
;; don't need to increment the start position.
(cons nil (elisp-refs--sexp-positions buffer start-pos end-pos))
;; Calculate the positions after the opening paren.
(elisp-refs--sexp-positions buffer (1+ start-pos) end-pos))))
;; For each subform, recurse if it's a list, or a matching symbol.
(--each (-zip-pair form subforms-positions)
(-let [(subform subform-start subform-end) it]
(when (or
(and (consp subform) (elisp-refs--proper-list-p subform))
(and (symbolp subform) (eq subform symbol)))
(-when-let (subform-matches
(elisp-refs--walk
buffer subform
subform-start subform-end
symbol match-p
(cons (cons (car-safe form) it-index) path)))
(push subform-matches matches)))))
;; Concat the results from all the subforms.
(apply #'append (nreverse matches))))))