Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ebbde4e

Browse filesBrowse files
committed
Introduce inf-clojure-reload
It will evaluate (require 'ns :reload) or (require 'ns :reload-all) at the REPL, depending on the arguments passed in.
1 parent 630471b commit ebbde4e
Copy full SHA for ebbde4e

File tree

1 file changed

+73
-0
lines changed
Filter options

1 file changed

+73
-0
lines changed

‎inf-clojure.el

Copy file name to clipboardExpand all lines: inf-clojure.el
+73Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
131131
(define-key map "\C-c\C-c" #'inf-clojure-eval-defun) ; SLIME/CIDER style
132132
(define-key map "\C-c\C-b" #'inf-clojure-eval-buffer)
133133
(define-key map "\C-c\C-r" #'inf-clojure-eval-region)
134+
(define-key map "\C-c\C-r" #'inf-clojure-reload)
134135
(define-key map "\C-c\C-n" #'inf-clojure-eval-form-and-next)
135136
(define-key map "\C-c\C-z" #'inf-clojure-switch-to-repl)
136137
(define-key map "\C-c\C-i" #'inf-clojure-show-ns-vars)
@@ -152,6 +153,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
152153
["Eval buffer" inf-clojure-eval-buffer t]
153154
"--"
154155
["Load file..." inf-clojure-load-file t]
156+
["Reload file... " inf-clojure-reload t]
155157
"--"
156158
["Switch to REPL" inf-clojure-switch-to-repl t]
157159
["Set REPL ns" inf-clojure-set-ns t]
@@ -372,6 +374,48 @@ If you are using REPL types, it will pickup the most appropriate
372374
(`planck inf-clojure-load-form-planck)
373375
(_ inf-clojure-load-form)))
374376

377+
(defcustom inf-clojure-reload-form "(require '\"%s\" :reload)"
378+
"Format-string for building a Clojure expression to reload a file.
379+
Reload forces loading of all the identified libs even if they are
380+
already loaded.
381+
This format string should use `%s' to substitute a namespace and
382+
should result in a Clojure form that will be sent to the inferior
383+
Clojure to load that file."
384+
:type 'string
385+
:safe #'stringp
386+
:package-version '(inf-clojure . "2.2.0"))
387+
388+
;; :reload forces loading of all the identified libs even if they are
389+
;; already loaded
390+
;; :reload-all implies :reload and also forces loading of all libs that the
391+
;; identified libs directly or indirectly load via require or use
392+
393+
(defun inf-clojure-reload-form (proc)
394+
"Return the form to query the Inf-Clojure PROC for reloading a namespace.
395+
If you are using REPL types, it will pickup the most appropriate
396+
`inf-clojure-reload-form` variant."
397+
(inf-clojure--set-repl-type proc)
398+
inf-clojure-reload-form)
399+
400+
(defcustom inf-clojure-reload-all-form "(require '\"%s\" :reload-all)"
401+
"Format-string for building a Clojure expression to :reload-all a file.
402+
Reload-all implies :reload and also forces loading of all libs
403+
that the identified libs directly or indirectly load via require
404+
or use.
405+
This format string should use `%s' to substitute a namespace and
406+
should result in a Clojure form that will be sent to the inferior
407+
Clojure to load that file."
408+
:type 'string
409+
:safe #'stringp
410+
:package-version '(inf-clojure . "2.2.0"))
411+
412+
(defun inf-clojure-reload-all-form (proc)
413+
"Return the form to query the Inf-Clojure PROC for :reload-all of a namespace.
414+
If you are using REPL types, it will pickup the most appropriate
415+
`inf-clojure-reload-all-form` variant."
416+
(inf-clojure--set-repl-type proc)
417+
inf-clojure-reload-all-form)
418+
375419
(defcustom inf-clojure-prompt "^[^=> \n]+=> *"
376420
"Regexp to recognize prompts in the Inferior Clojure mode."
377421
:type 'regexp)
@@ -702,6 +746,35 @@ is present it will be used instead of the current file."
702746
(when switch-to-repl
703747
(inf-clojure-switch-to-repl t))))
704748

749+
(defcustom inf-clojure-reload-default t
750+
"Controls whether `inf-clojure-reload' should reload or reload-all by default."
751+
:type '(choice (const :tag "Reload" t)
752+
(const :tag "Reload All" nil))
753+
:safe #'booleanp
754+
:package-version '(inf-clojure . "2.2.0"))
755+
756+
(defun inf-clojure-reload (arg)
757+
"Send a query to the inferior Clojure for reloading the namespace.
758+
See variable `inf-clojure-reload-form' and
759+
`inf-clojure-reload-all-form'.
760+
761+
The prefix argument ARG can change the behavior of the command:
762+
763+
- C-u M-x `inf-clojure-reload': prompts for a namespace name.
764+
- M-- M-x `inf-clojure-reload': inverts the default reload command
765+
- M-- C-u M-x `inf-clojure-reload': inverts default AND prompts for a namespace name."
766+
(interactive "P")
767+
(let* ((proc (inf-clojure-proc))
768+
(invert? (or (equal current-prefix-arg "-") (equal current-prefix-arg '(-4))))
769+
(prompt? (or (equal current-prefix-arg '(4)) (equal current-prefix-arg '(-4))))
770+
(ns (if prompt?
771+
(car (inf-clojure-symprompt "Namespace" (clojure-find-ns)))
772+
(clojure-find-ns)))
773+
(form (if (and inf-clojure-reload-default (not invert?))
774+
(inf-clojure-reload-form proc)
775+
(inf-clojure-reload-all-form proc))))
776+
(inf-clojure--send-string proc (format form ns))))
777+
705778
(defun inf-clojure-connected-p ()
706779
"Return t if inferior Clojure is currently connected, nil otherwise."
707780
(not (null inf-clojure-buffer)))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.