Last active
January 2, 2016 08:59
-
-
Save quasi/8280332 to your computer and use it in GitHub Desktop.
For js2-mode, to go to function definition and back. I sorely missed the M-. and M-, from SLIME.
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
;;; Find JS function definition in your current buffer (and go back). | |
(defvar *quasi-js-current-pos* nil) | |
(defun quasi-js-function-search () | |
"Search for JS function definations. In a rather dumb way, but works, albeit only for current buffer. | |
Works recurcively too :)" | |
(interactive) | |
(let ((text (thing-at-point 'word))) | |
(push (point) *quasi-js-current-pos*) | |
(goto-char (point-min)) | |
(if (search-forward (concat "function " text) nil t) | |
(recenter) | |
(progn | |
(goto-char (pop *quasi-js-current-pos*)) | |
(message "Could not find definition for %s" text))))) | |
(defun quasi-js-function-go-back () | |
"Go back to where you initiated search from" | |
(interactive) | |
(if *quasi-js-current-pos* | |
(goto-char (pop *quasi-js-current-pos*)) | |
(message "Nowhere to jump!"))) | |
;; Add hooks to js2-mode. It will cobbler the default tag-search bindings. Beware. | |
(add-hook 'js2-mode-hook | |
(lambda () | |
(local-set-key (kbd "M-.") #'quasi-js-function-search) | |
(local-set-key (kbd "M-,") #'quasi-js-function-go-back))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment