Skip to content

Introduce inf-clojure-reload #132

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#125](https://github.com/clojure-emacs/inf-clojure/pull/125): Avoid throwing an error for frequent operations like completion.
* [#130](https://github.com/clojure-emacs/inf-clojure/pull/130): Support loading directory locals in our buffers.
* [#129](https://github.com/clojure-emacs/inf-clojure/pull/129): Improve the completion bounds detection (now with keywords).
* [#132](https://github.com/clojure-emacs/inf-clojure/pull/132): Introduce inf-clojure-reload.

### Bugs Fixed

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Clojure(Script) development:
* ElDoc
* Apropos
* Macroexpansion
* Require `:reload`/`:reload-all`
* Support connecting to socket REPLs
* Support for Lumo
* Support for Planck
Expand Down
66 changes: 66 additions & 0 deletions inf-clojure.el
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
(define-key map "\C-c\C-c" #'inf-clojure-eval-defun) ; SLIME/CIDER style
(define-key map "\C-c\C-b" #'inf-clojure-eval-buffer)
(define-key map "\C-c\C-r" #'inf-clojure-eval-region)
(define-key map "\C-c\M-r" #'inf-clojure-reload)
(define-key map "\C-c\C-n" #'inf-clojure-eval-form-and-next)
(define-key map "\C-c\C-z" #'inf-clojure-switch-to-repl)
(define-key map "\C-c\C-i" #'inf-clojure-show-ns-vars)
Expand All @@ -152,6 +153,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
["Eval buffer" inf-clojure-eval-buffer t]
"--"
["Load file..." inf-clojure-load-file t]
["Reload file... " inf-clojure-reload t]
"--"
["Switch to REPL" inf-clojure-switch-to-repl t]
["Set REPL ns" inf-clojure-set-ns t]
Expand Down Expand Up @@ -372,6 +374,48 @@ If you are using REPL types, it will pickup the most appropriate
(`planck inf-clojure-load-form-planck)
(_ inf-clojure-load-form)))

(defcustom inf-clojure-reload-form "(require '\"%s\" :reload)"
"Format-string for building a Clojure expression to reload a file.
Reload forces loading of all the identified libs even if they are
already loaded.
This format string should use `%s' to substitute a namespace and
should result in a Clojure form that will be sent to the inferior
Clojure to load that file."
:type 'string
:safe #'stringp
:package-version '(inf-clojure . "2.2.0"))

;; :reload forces loading of all the identified libs even if they are
;; already loaded
;; :reload-all implies :reload and also forces loading of all libs that the
;; identified libs directly or indirectly load via require or use

(defun inf-clojure-reload-form (proc)
"Return the form to query the Inf-Clojure PROC for reloading a namespace.
If you are using REPL types, it will pickup the most appropriate
`inf-clojure-reload-form` variant."
(inf-clojure--set-repl-type proc)
inf-clojure-reload-form)

(defcustom inf-clojure-reload-all-form "(require '\"%s\" :reload-all)"
"Format-string for building a Clojure expression to :reload-all a file.
Reload-all implies :reload and also forces loading of all libs
that the identified libs directly or indirectly load via require
or use.
This format string should use `%s' to substitute a namespace and
should result in a Clojure form that will be sent to the inferior
Clojure to load that file."
:type 'string
:safe #'stringp
:package-version '(inf-clojure . "2.2.0"))

(defun inf-clojure-reload-all-form (proc)
"Return the form to query the Inf-Clojure PROC for :reload-all of a namespace.
If you are using REPL types, it will pickup the most appropriate
`inf-clojure-reload-all-form` variant."
(inf-clojure--set-repl-type proc)
inf-clojure-reload-all-form)

(defcustom inf-clojure-prompt "^[^=> \n]+=> *"
"Regexp to recognize prompts in the Inferior Clojure mode."
:type 'regexp)
Expand Down Expand Up @@ -702,6 +746,28 @@ is present it will be used instead of the current file."
(when switch-to-repl
(inf-clojure-switch-to-repl t))))

(defun inf-clojure-reload (arg)
"Send a query to the inferior Clojure for reloading the namespace.
See variable `inf-clojure-reload-form' and
`inf-clojure-reload-all-form'.

The prefix argument ARG can change the behavior of the command:

- C-u M-x `inf-clojure-reload': prompts for a namespace name.
- M-- M-x `inf-clojure-reload': executes (require ... :reload-all).
- M-- C-u M-x `inf-clojure-reload': reloads all AND prompts."
(interactive "P")
(let* ((proc (inf-clojure-proc))
(invertp (or (equal arg "-") (equal arg '(-4))))
(promptp (or (equal arg '(4)) (equal arg '(-4))))
(ns (if promptp
(car (inf-clojure-symprompt "Namespace" (clojure-find-ns)))
(clojure-find-ns)))
(form (if (not invertp)
(inf-clojure-reload-form proc)
(inf-clojure-reload-all-form proc))))
(inf-clojure--send-string proc (format form ns))))

(defun inf-clojure-connected-p ()
"Return t if inferior Clojure is currently connected, nil otherwise."
(not (null inf-clojure-buffer)))
Expand Down