Created
September 11, 2023 15:55
-
-
Save knu/963532a92433333705fd114b60741c30 to your computer and use it in GitHub Desktop.
Get eval-defun to find a non-toplevel defun/defvar nearest to the point
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; (require 'smartparens) | |
(defun eval-defun:inner-def (orig-func &rest args) | |
(cl-letf* | |
(((symbol-function #'beginning-of-defun) | |
(lambda (&optional arg) | |
(let (pos) | |
(save-match-data | |
(cl-loop | |
do | |
(setq pos (point)) | |
(if (and (not (looking-at "(")) | |
(looking-back ")\\(\\s-\\|\n\\)*" (- (point) 16))) | |
(sp-backward-sexp) | |
(sp-backward-up-sexp)) | |
until (or | |
(looking-at-p "(\\(defun\\|defvar\\)\\(\\s-\\|$\\)") | |
(= pos (point)))))))) | |
((symbol-function #'end-of-defun) | |
(lambda (&optional arg) | |
(let (pos) | |
(beginning-of-defun) | |
(sp-forward-sexp))))) | |
(apply orig-func args))) | |
(advice-add #'eval-defun :around #'eval-defun:inner-def) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment