>>108277328
>>108284933
>Checking something related to autocompletion of let/let* scoped variables in emacs.
It's not as comprehensive as your solution but I imagined using backward-up-list and form-at-point to recursively match each enclosing let until a base case is reached
(defun collect-lets ()
(pcase (up-list-form)
('() '())
(`(let ,vars . ,body) (append vars (collect-lets)))
(_ (collect-lets))))
(defun up-list-form ()
(let ((last (point)))
(condition-case nil
(goto-char (scan-lists last -1 1))
(error nil))
(if (= (point) last)
'()
(form-at-point))))
For example with this sexp
(defun f (w)
(let ((x 1))
(let ((y 2)
(z 3))
(+ w x y z))))
collect-lets gives one of these lists for autocomplete
((y 2) (z 3) (x 1))
((x 1))