Skip to content

Commit

Permalink
Remove clj-refactor hacks
Browse files Browse the repository at this point in the history
Of course, we're still using my fork until [1] and [2] are merged.

[1]: clojure-emacs/clj-refactor.el#392
[2]: clojure-emacs/clj-refactor.el#385
  • Loading branch information
raxod502 committed Oct 22, 2017
1 parent 5527905 commit 240a316
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 72 deletions.
66 changes: 0 additions & 66 deletions radian-emacs/radian-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,6 @@ should be the regular Clojure REPL started by the server process filter."
:defer-install t
:init

;; By default, clj-refactor enables the refactor-nrepl middleware in
;; an *autoload*, meaning that it's already happened as soon as
;; clj-refactor has loaded. But refactor-nrepl doesn't work outside
;; a Clojure project, and signals a warning in that case. So we need
;; to *selectively* inject refactor-nrepl, which means we need to
;; disable it right away so we can do it buffer-locally later. See
;; [1] for discussion of the problem.
;;
;; [1]: https://github.com/clojure-emacs/refactor-nrepl/issues/177
(setq cljr-inject-dependencies-at-jack-in nil)

(with-eval-after-load 'clojure-mode
;; Enable clj-refactor in Clojure buffers. This is adapted from the
;; clj-refactor README [1].
Expand All @@ -369,63 +358,8 @@ the `clj-refactor' keybindings need to be installed."

(add-hook 'clojure-mode-hook #'radian-clj-refactor-enable))

(with-eval-after-load 'cider
;; Because we disabled injection of the clj-refactor middleware
;; earlier, we have to do it buffer-locally now (but only if we're
;; in a project).

(defun radian-advice-cljr-inject-dependencies (&rest args)
"Re-enable injection of `clj-refactor' middleware if inside a project.
This is a `:before' advice for `cider-jack-in'."
(when (and (use-package-install-deferred-package
'clj-refactor :after)
(require 'clj-refactor)
(radian-cljr-project-dir))
;; We need to set this in order for
;; `cljr--inject-jack-in-dependencies' to have an effect. But
;; we want it to remain nil globally, so that in the case that
;; we are outside a project, the dependencies are not
;; injected.
(setq-local cljr-inject-dependencies-at-jack-in t)

;; But we only want the dependencies to be injected in the
;; current buffer.
(make-local-variable 'cider-jack-in-lein-plugins)
(make-local-variable 'cider-jack-in-nrepl-middlewares)

;; Do it.
(cljr--inject-jack-in-dependencies)))

(advice-add #'cider-jack-in :before
#'radian-advice-cljr-inject-dependencies))

:config

;; Recently `cljr--project-dir' was changed to return an empty
;; string instead of nil when there is no containing project. Let's
;; fix it, so that we can have a proper predicate to determine when
;; refactor-nrepl should be injected.
(defun radian-cljr-project-dir ()
"Like `cljr--project-dir', but return nil instead of empty string."
(let ((project-dir (cljr--project-dir)))
(unless (string-empty-p project-dir)
project-dir)))

;; We also need to tell clj-refactor not to check that
;; refactor-nrepl is installed properly when we are not in a
;; project.

(defalias 'radian-advice-cljr-suppress-middleware-check
#'radian-cljr-project-dir
"Suppress a spurious warning from `clj-refactor'.
This is a `:before-while' advice for `cljr--init-middleware'. The
warning in question is printed in the REPL and tells you that the
middleware is not injected, even though it shouldn't be injected
when you're outside a project.")

(advice-add #'cljr--init-middleware :before-while
#'radian-advice-cljr-suppress-middleware-check)

;; Make clj-refactor show its messages right away, instead of
;; waiting for you to do another command.

Expand Down
12 changes: 6 additions & 6 deletions versions.el
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
("avy" . "228ed97d07d51e369eb6ad27bf408c5b3218a23b")
("buffer-move" . "cb517ecf8409b5fdcda472d7190c6021f0c49751")
("cider" . "b4a3d2431ddf8562c39d8ba1386c8bdaaa542b63")
("clj-refactor.el" . "05479fe33d0950dd5c6b6eb1f5139f2e6b0bba30")
("clj-refactor.el" . "b85533e82588754553459feb0f0561ad4b3b7d7f")
("clojure-mode" . "35f5d71b196b1a4b147a56a82b723d0383cb7282")
("company-anaconda" . "b268a00821c79d7e4c5da0d7035356afb389b3a7")
("company-auctex" . "d3727c9f5bb13c52b4a345bc8f895d3dbd9178b3")
Expand All @@ -24,7 +24,7 @@
("dockerfile-mode" . "3c6bc90360a2df53caad1721ee4c8285e2e22369")
("editorconfig-emacs" . "1543835ce00412c3cd34a61497af5f68ead250a6")
("edn.el" . "be9e32d1b49e35247b263b0243df7cfdc8d413ab")
("el-patch" . "f598a7537710f929c6f7592d8c543768361ba0de")
("el-patch" . "32f7a12c2eaacd60d48ed5e5482121154a507fb8")
("emacs-async" . "d6222c2959caaca5c4980038756097da8a51e505")
("emacs-hcl-mode" . "0f2c5ec7e7bcf77c8548e8cac8721ea935ca1b5e")
("emacs-memoize" . "636defefa9168f90bce6fc27431352ac7d01a890")
Expand All @@ -37,7 +37,7 @@
("f.el" . "fabdbd4a4a8caf8684f0fa656f457a03c5dfa4de")
("filladapt" . "d47c42f8b2e1ce325be71a1d320af867a6288402")
("flx" . "ae0981b253b17b52dec666e2f739f889e7952291")
("flycheck" . "8680ba305e9839aee1e21c0bc5b0cb8a1ac37e70")
("flycheck" . "d4db2dd1ad884bb8c0dd22c755a19eed34d72007")
("flycheck-irony" . "34940ae5ab8f4c721d9c1118ebfc3496d7e67a84")
("font-lock-plus" . "238649549c531c84ad627a095a6eef489f52d109")
("geiser" . "f5ae5488a6d94fcd74d573049b58f8c2e7ff7012")
Expand All @@ -58,7 +58,7 @@
("jump.el" . "95a9559bd301ff86fa3b72b15126dc4851ce4a69")
("magit" . "cafb3425e39e067f2b39a47971b7d1f1ac4ff80f")
("markdown-mode" . "0f88075c9091b4120fac96aaf091ec647d2ea555")
("melpa" . "27145423eb4e68e006ef96868a35b99d119a3099")
("melpa" . "d9180fbedf95f9b1f5810bbf4929dfee513f89e3")
("multiple-cursors.el" . "18f992bff596609091afca128b51a7d2e919ac40")
("no-littering" . "8b689a1e16d4825d0221f4a41756b63bbc361c82")
("org" . "602a1a21fccd65b0fa5dc9543a9865b6537a75b9")
Expand All @@ -80,9 +80,9 @@
("smartparens" . "218e8177a331c37ee681ad97cea8978f0532b2d4")
("smex" . "55aaebe3d793c2c990b39a302eb26c184281c42c")
("spinner" . "0637791f005f747532b4439439a81c3415961377")
("straight.el" . "6a75521e115c09cec16db91ebc80a23402bedc87")
("straight.el" . "1723e1cf5543ea7699126162b1e2bb8d4f05713d")
("swift-mode" . "e91e924c225b7bfb7aa6e4a84b5d379c6268014a")
("swiper" . "0a1d361b926291874124f8c63a653d83ead64a36")
("swiper" . "f7470feef4880a735495c5013465efffd049270d")
("sx.el" . "8f1e3346286cfa5a5299ef192cc5aca3f37a7745")
("tern" . "3f8a2bc7c2e9a4ac55e8c6f6c60c0634cbe71326")
("tide" . "1a1a378060a989589cb6129fa22cfbf3eeb5eab8")
Expand Down

0 comments on commit 240a316

Please sign in to comment.