emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/inf-clojure be3e2e7 195/313: Introduce inf-clojure-reload


From: ELPA Syncer
Subject: [nongnu] elpa/inf-clojure be3e2e7 195/313: Introduce inf-clojure-reload
Date: Wed, 11 Aug 2021 10:00:15 -0400 (EDT)

branch: elpa/inf-clojure
commit be3e2e7c5ec9302cf1a7d5e39defc2ecc78bd9de
Author: Andrea Richiardi <a.richiardi.work@gmail.com>
Commit: Bozhidar Batsov <bozhidar.batsov@gmail.com>

    Introduce inf-clojure-reload
    
    It will evaluate (require 'ns :reload) or (require 'ns :reload-all) at the
    REPL, depending on the arguments passed in.  This works only from source
    buffers at the moment (like all the other namespace commands).
---
 CHANGELOG.md   |  1 +
 README.md      |  1 +
 inf-clojure.el | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87b78fe..31e1fa2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
 
diff --git a/README.md b/README.md
index 16f78b1..23fa630 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/inf-clojure.el b/inf-clojure.el
index 382f223..385b149 100644
--- a/inf-clojure.el
+++ b/inf-clojure.el
@@ -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)
@@ -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]
@@ -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)
@@ -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)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]