Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require 'treepy)
- (require 'parseclj)
- (defun let-binding-point* (root s-value s-position)
- "Return position for let binding in `ROOT' for `S-VALUE' at `S-POSITION'."
- (let ((current-zipper (treepy-zipper (lambda (n) (assoc-default :children n))
- (lambda (n) (assoc-default :children n))
- (lambda (n children) (cons (cons :children children) n))
- root)))
- (while (and (not (treepy-end-p current-zipper))
- (not (= s-position
- (assoc-default :position (treepy-node current-zipper)))))
- (setq current-zipper (treepy-next current-zipper)))
- (catch 'binding-position
- (when (treepy-end-p current-zipper)
- (throw 'binding-position nil))
- (while (and current-zipper
- (not (treepy-end-p current-zipper)))
- (let ((leftmost-form (treepy-leftmost current-zipper)))
- (when (equal 'let (assoc-default :value (treepy-node leftmost-form)))
- (when-let ((p (->> leftmost-form
- (treepy-right)
- (treepy-node)
- (assoc-default :children)
- (seq-filter (lambda (v)
- (equal (assoc-default :value v)
- s-value)))
- (car)
- (assoc-default :position))))
- (throw 'binding-position p)))
- (setq current-zipper (treepy-up current-zipper)))))))
- (defun let-binding-point ()
- "Jump to neared enclosing let binding for (`symbol-at-point')."
- (interactive)
- (if-let ((s-value (symbol-at-point))
- (s-position (car (bounds-of-thing-at-point 'symbol))))
- (if-let ((b-position (save-excursion
- (beginning-of-defun)
- (let-binding-point* (parseclj-parse-clojure :read-one t)
- s-value
- s-position))))
- (goto-char b-position)
- (message "Couldn't find local binding for %s" s-value))
- (message "No symbol at point")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement