Last active
January 1, 2019 21:27
-
-
Save saikyun/95c074961580ba39a328482d563a22e3 to your computer and use it in GitHub Desktop.
Monroe jump to def for Arcadia
This file contains 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 'monroe) | |
(add-hook 'clojure-mode-hook 'clojure-enable-monroe) | |
(defvar *monroe-project-path* nil) | |
(defun monroe-new-session-handler (process) | |
"Returns callback that is called when new connection is established." | |
(lambda (response) | |
(monroe-dbind-response response (id new-session) | |
(when new-session | |
(message "Connected.") | |
(setq monroe-session new-session) | |
(remhash id monroe-requests) | |
(sit-for 0.1) ;; Don't ask me, didn't work without it | |
(run-hooks 'monroe-connected-hook))))) | |
(defun monroe-set-project-path () | |
"Sets *monroe-project-path* to the path of the project | |
the nREPL server monroe connected to was started in." | |
(interactive) | |
(monroe-send-eval-string | |
(format "%s" `(.. (clojure.clr.io/as-file \".\") FullName)) | |
(lambda (response) | |
(monroe-dbind-response response (id value status) | |
(when (member "done" status) | |
(remhash id monroe-requests)) | |
(when value | |
(setq *monroe-project-path* (read value))))))) | |
(add-hook 'monroe-connected-hook 'monroe-set-project-path) | |
(defun monroe-eval-jump (ns var) | |
"Internal function to actually ask for var location via nrepl protocol." | |
(monroe-send-eval-string | |
(format "%s" `((juxt :file :line) | |
(meta ,(if ns `(ns-resolve ',(intern ns) ',(intern var)) | |
`(resolve ',(intern var)))))) | |
(lambda (response) | |
(monroe-dbind-response response (id value status) | |
(when (member "done" status) | |
(remhash id monroe-requests)) | |
(when value | |
(destructuring-bind (file line) | |
(append (car (read-from-string value)) nil) | |
(monroe-jump-find-file (funcall monroe-translate-path-function file)) | |
(when line | |
(goto-char (point-min)) | |
(forward-line (1- line))))))))) | |
(defun monroe-jump-find-file (file) | |
"Internal function to find a file on the disk or inside a jar." | |
(if (string-match "^clojure\\|^arcadia" file) | |
(progn (find-file (concat *monroe-project-path* "/Assets/Arcadia/Source/" file)) | |
(setq buffer-display-table (make-display-table)) | |
(aset buffer-display-table ?\^M [])) | |
(find-file file))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment