Skip to content

Instantly share code, notes, and snippets.

@saikyun
Created December 28, 2018 09:44
Show Gist options
  • Save saikyun/79750e99f0b504167fe59c58b1138772 to your computer and use it in GitHub Desktop.
Save saikyun/79750e99f0b504167fe59c58b1138772 to your computer and use it in GitHub Desktop.
Get source of function in arcadia + emacs.
(defun inf-clojure-eval-in-ns (nsn command)
(interactive "sNamespace to go to: \nsCommand: ")
(inf-clojure--process-response
(concat "(do (if-not (find-ns '" nsn ") (try (require '" nsn " :reload) (catch Exception e (ns " nsn " )))) (in-ns '" nsn ")" command ")")
(inf-clojure-proc)))
(defun inf-clojure-eval-in-ns-of-current-file (command)
(interactive "sCommand: ")
(if-let ((ns (clojure-find-ns)))
(inf-clojure-eval-in-ns ns command)
(inf-clojure--process-response command (inf-clojure-proc))))
(defun inf-clojure-source-of-function (fun)
"Gets the source for a function."
(interactive "sSource of clojure function: ")
(let ((res (inf-clojure-eval-in-ns-of-current-file
(concat "(do (require '[clojure.repl :as temp-clojure-repl-ns]) (temp-clojure-repl-ns/source "
fun
"))"))))
(switch-to-buffer-other-window "*inf-clojure-source*")
(erase-buffer)
(clojure-mode)
(insert res)
(goto-char 0)
(while (re-search-forward "
" nil t)
(replace-match ""))))
(defun inf-clojure-source-of-function-at-point ()
(interactive)
(let* ((pos (point))
(beg (progn (re-search-backward "[[:space:]]\\|\n\\|(")
(forward-char)
(match-end 0)))
(end (progn (re-search-forward "[[:space:]]\\|\n\\|)")
(backward-char)
(match-beginning 0)))
(identifier (buffer-substring beg end))
(parsed-id (car (read-from-string identifier))))
(inf-clojure-source-of-function identifier)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment