Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. (require 'treepy)
  2. (require 'parseclj)
  3.  
  4. (defun let-binding-point* (root s-value s-position)
  5. "Return position for let binding in `ROOT' for `S-VALUE' at `S-POSITION'."
  6. (let ((current-zipper (treepy-zipper (lambda (n) (assoc-default :children n))
  7. (lambda (n) (assoc-default :children n))
  8. (lambda (n children) (cons (cons :children children) n))
  9. root)))
  10. (while (and (not (treepy-end-p current-zipper))
  11. (not (= s-position
  12. (assoc-default :position (treepy-node current-zipper)))))
  13. (setq current-zipper (treepy-next current-zipper)))
  14. (catch 'binding-position
  15. (when (treepy-end-p current-zipper)
  16. (throw 'binding-position nil))
  17. (while (and current-zipper
  18. (not (treepy-end-p current-zipper)))
  19. (let ((leftmost-form (treepy-leftmost current-zipper)))
  20. (when (equal 'let (assoc-default :value (treepy-node leftmost-form)))
  21. (when-let ((p (->> leftmost-form
  22. (treepy-right)
  23. (treepy-node)
  24. (assoc-default :children)
  25. (seq-filter (lambda (v)
  26. (equal (assoc-default :value v)
  27. s-value)))
  28. (car)
  29. (assoc-default :position))))
  30. (throw 'binding-position p)))
  31. (setq current-zipper (treepy-up current-zipper)))))))
  32.  
  33. (defun let-binding-point ()
  34. "Jump to neared enclosing let binding for (`symbol-at-point')."
  35. (interactive)
  36. (if-let ((s-value (symbol-at-point))
  37. (s-position (car (bounds-of-thing-at-point 'symbol))))
  38. (if-let ((b-position (save-excursion
  39. (beginning-of-defun)
  40. (let-binding-point* (parseclj-parse-clojure :read-one t)
  41. s-value
  42. s-position))))
  43. (goto-char b-position)
  44. (message "Couldn't find local binding for %s" s-value))
  45. (message "No symbol at point")))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement