branch: elpa/inf-clojure commit c590c65d8f7b702f642b97548aa28ac91fb2e857 Author: dan sutton <d...@dpsutton.com> Commit: Bozhidar Batsov <bozhidar.bat...@gmail.com>
Remove projects from inf-clojure except to serve as project root No inferring of build commands. Just a simple api: - `m-x inf-clojure` and select or type a clojure startup command - `m-x inf-clojure-connect` and enter host and port These days clojure commands are incredibly simple and tooling gets in the way. Inf clojure just interacts with a repl process so you can follow tutorials and just type what the tutorial types in. Seems just as simple to define your own project functions as to develop a good override api and defcustoms. Update todo with removing CIDER hooks --- inf-clojure.el | 138 +++++++++++++++++---------------------------------------- todo.org | 14 ++++-- 2 files changed, 51 insertions(+), 101 deletions(-) diff --git a/inf-clojure.el b/inf-clojure.el index 1545e14..9149212 100644 --- a/inf-clojure.el +++ b/inf-clojure.el @@ -408,45 +408,6 @@ If this is `nil`, the project will be automatically detected." :safe #'stringp :package-version '(inf-clojure . "2.1.0")) -(defcustom inf-clojure-lein-cmd "lein repl" - "The command used to start a Clojure REPL for Leiningen projects. - -Alternatively you can specify a TCP connection cons pair, instead -of command, consisting of a host and port -number (e.g. (\"localhost\" . 5555)). That's useful if you're -often connecting to a remote REPL process." - :type '(choice (string) - (cons string integer)) - :risky #'stringp - :safe #'inf-clojure--endpoint-p - :package-version '(inf-clojure . "2.0.0")) - -(defcustom inf-clojure-boot-cmd "boot repl -C" - "The command used to start a Clojure REPL for Boot projects. - -Alternatively you can specify a TCP connection cons pair, instead -of command, consisting of a host and port -number (e.g. (\"localhost\" . 5555)). That's useful if you're -often connecting to a remote REPL process." - :type '(choice (string) - (cons string integer)) - :risky #'stringp - :safe #'inf-clojure--endpoint-p - :package-version '(inf-clojure . "2.0.0")) - -(defcustom inf-clojure-tools-deps-cmd "clojure" - "The command used to start a Clojure REPL for tools.deps projects. - -Alternatively you can specify a TCP connection cons pair, instead -of command, consisting of a host and port -number (e.g. (\"localhost\" . 5555)). That's useful if you're -often connecting to a remote REPL process." - :type '(choice (string) - (cons string integer)) - :risky #'stringp - :safe #'inf-clojure--endpoint-p - :package-version '(inf-clojure . "2.1.0")) - (defcustom inf-clojure-generic-cmd "lein repl" "The command used to start a Clojure REPL outside Lein/Boot projects. @@ -688,7 +649,7 @@ to continue it." (t str))) (defvar inf-clojure-project-root-files - '("project.clj" "build.boot" "deps.edn") + '("project.clj" "build.boot" "deps.edn" "shadow-cljs.edn") "A list of files that can be considered project markers.") (defun inf-clojure-project-root () @@ -702,29 +663,52 @@ Fallback to `default-directory.' if not within a project." inf-clojure-project-root-files))) default-directory)) -(defun inf-clojure-project-type () - "Determine the type, either leiningen or boot of the current project." - (or inf-clojure-project-type - (let ((default-directory (inf-clojure-project-root))) - (cond ((file-exists-p "project.clj") "lein") - ((file-exists-p "build.boot") "boot") - ((file-exists-p "deps.edn") "tools.deps") - (t "generic"))))) - -(defun inf-clojure-cmd (project-type) - "Determine the command `inf-clojure' needs to invoke for the PROJECT-TYPE." - (pcase project-type - ("lein" inf-clojure-lein-cmd) - ("boot" inf-clojure-boot-cmd) - ("tools.deps" inf-clojure-tools-deps-cmd) - (_ inf-clojure-generic-cmd))) - (defun inf-clojure-clear-repl-buffer () "Clear the REPL buffer." (interactive) (let ((comint-buffer-maximum-size 0)) (comint-truncate-buffer))) +(defun inf-clojure-switch-to-repl (eob-p) + "Switch to the inferior Clojure process buffer. +With prefix argument EOB-P, positions cursor at end of buffer." + (interactive "P") + (if (get-buffer-process inf-clojure-buffer) + (let ((pop-up-frames + ;; Be willing to use another frame + ;; that already has the window in it. + (or pop-up-frames + (get-buffer-window inf-clojure-buffer t)))) + (pop-to-buffer inf-clojure-buffer)) + (call-interactively #'inf-clojure)) + (when eob-p + (push-mark) + (goto-char (point-max)))) + +(defun inf-clojure-quit (&optional buffer) + "Kill the REPL buffer and its underlying process. + +You can pass the target BUFFER as an optional parameter +to suppress the usage of the target buffer discovery logic." + (interactive) + (let ((target-buffer (or buffer (inf-clojure-select-target-repl)))) + (when (get-buffer-process target-buffer) + (delete-process target-buffer)) + (kill-buffer target-buffer))) + +(defun inf-clojure-restart (&optional buffer) + "Restart the REPL buffer and its underlying process. + +You can pass the target BUFFER as an optional parameter +to suppress the usage of the target buffer discovery logic." + (interactive) + (let* ((target-buffer (or buffer (inf-clojure-select-target-repl))) + (target-buffer-name (buffer-name target-buffer))) + ;; TODO: Try to recycle the old buffer instead of killing and recreating it + (inf-clojure-quit target-buffer) + (call-interactively #'inf-clojure) + (rename-buffer target-buffer-name))) + ;;;###autoload (defun inf-clojure (cmd) "Run an inferior Clojure process, input and output via buffer `*inf-clojure*'. @@ -821,22 +805,6 @@ Prefix argument AND-GO means switch to the Clojure buffer afterwards." (inf-clojure-eval-last-sexp) (forward-sexp)) -(defun inf-clojure-switch-to-repl (eob-p) - "Switch to the inferior Clojure process buffer. -With prefix argument EOB-P, positions cursor at end of buffer." - (interactive "P") - (if (get-buffer-process inf-clojure-buffer) - (let ((pop-up-frames - ;; Be willing to use another frame - ;; that already has the window in it. - (or pop-up-frames - (get-buffer-window inf-clojure-buffer t)))) - (pop-to-buffer inf-clojure-buffer)) - (inf-clojure (inf-clojure-cmd (inf-clojure-project-type)))) - (when eob-p - (push-mark) - (goto-char (point-max)))) - (defun inf-clojure-insert-and-eval (form) "Insert FORM into process and evaluate. Indent FORM. FORM is expected to have been trimmed." @@ -1411,30 +1379,6 @@ Useful for commands that can invoked outside of an ‘inf-clojure’ buffer (t (get-buffer (completing-read "Select target inf-clojure buffer: " (mapcar #'buffer-name repl-buffers)))))))) -(defun inf-clojure-quit (&optional buffer) - "Kill the REPL buffer and its underlying process. - -You can pass the target BUFFER as an optional parameter -to suppress the usage of the target buffer discovery logic." - (interactive) - (let ((target-buffer (or buffer (inf-clojure-select-target-repl)))) - (when (get-buffer-process target-buffer) - (delete-process target-buffer)) - (kill-buffer target-buffer))) - -(defun inf-clojure-restart (&optional buffer) - "Restart the REPL buffer and its underlying process. - -You can pass the target BUFFER as an optional parameter -to suppress the usage of the target buffer discovery logic." - (interactive) - (let* ((target-buffer (or buffer (inf-clojure-select-target-repl))) - (target-buffer-name (buffer-name target-buffer))) - ;; TODO: Try to recycle the old buffer instead of killing and recreating it - (inf-clojure-quit target-buffer) - (inf-clojure (inf-clojure-cmd (inf-clojure-project-type))) - (rename-buffer target-buffer-name))) - (defun inf-clojure--response-match-p (form match-p proc) "Send FORM and apply MATCH-P on the result of sending it to PROC. Note that this function will add a \n to the end of the string diff --git a/todo.org b/todo.org index 6b3e922..e42524f 100644 --- a/todo.org +++ b/todo.org @@ -50,9 +50,15 @@ The source primitive is quite nice but we most likely need a way to navigate to ** TODO PREPL Be nice to implement this now that we have parseedn in elisp to understand edn. * Nice-to-haves - -** TODO Better handling of cyclic dependencies -In inf-clojure.el I load the implementation specific files for lumo, planck, etc _after_ defining the register function. I would much prefer a way to do this without being so fragile. - ** TODO Put repl type in modeline Rather than just ~*inf-clojure*~ we could put the repl type. Make it easy to follow and makes it easy to see when it gets it wrong. + +** TODO How do CIDER and inf-clojure play nice on the same emacs? +inf-clojure and CIDER are fighting over the keymappings. I've been doing a bit of a kludge to remove CIDER's tentacles from my clojure files for developing: +#+BEGIN_SRC emacs-lisp + (seq-doseq (buffer (buffer-list)) + (with-current-buffer buffer + (cider-mode -1)) + (remove-hook 'clojure-mode-hook #'cider-mode)) +#+END_SRC +Seems a bit heavy handed but its working for me so far.