Last active
January 1, 2016 21:39
-
-
Save knjname/8204631 to your computer and use it in GitHub Desktop.
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
| (defun parent-directory (dir) | |
| (unless (equal "/" dir) | |
| (file-name-directory (directory-file-name dir)))) | |
| (defun find-nearest-file (dir-path filename) | |
| (let ((file (concat dir-path filename)) | |
| (parent (parent-directory (expand-file-name dir-path)))) | |
| (if (file-exists-p file) | |
| file | |
| (when parent | |
| (find-nearest-file parent filename))))) | |
| (defun current-buffer-project-clj () | |
| (find-nearest-file (file-name-directory (buffer-file-name)) "project.clj")) | |
| (defmacro with-clj-buffer (filepath &rest body) | |
| `(with-temp-buffer | |
| (insert-file-contents ,filepath) | |
| ,@body)) | |
| (defmacro let-if (varname condition-expr true-part &optional false-part) | |
| `(let | |
| ((,varname ,condition-expr)) | |
| (if ,varname | |
| ,true-part | |
| ,false-part))) | |
| (defun guess-ring-nrepl-port (filepath) | |
| (with-clj-buffer filepath | |
| (beginning-of-buffer) | |
| (if (and | |
| (re-search-forward ":nrepl" nil t) | |
| (re-search-forward ":port" nil t)) | |
| (progn | |
| (forward-word) | |
| (thing-at-point 'word))))) | |
| (defun open-current-clj-project-ring-nrepl () (interactive) | |
| (let-if project-file-path | |
| (current-buffer-project-clj) | |
| (let-if ring-nrepl-port | |
| (guess-ring-nrepl-port project-file-path) | |
| (nrepl "127.0.0.1" ring-nrepl-port) | |
| (error "Port specification is not found.")) | |
| (error "project.clj is not found."))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment