@@ -167,6 +167,14 @@ to load that file."
167
167
:type 'regexp
168
168
:group 'inf-clojure )
169
169
170
+ (defcustom inf-clojure-repl-flavor 'clojure
171
+ " Symbol to define your REPL flavor.
172
+ The default flavor is 'clojure, 'lumo is the other supported
173
+ one."
174
+ :type 'symbol
175
+ :options '(clojure lumo)
176
+ :group 'inf-clojure )
177
+
170
178
(defvar inf-clojure-buffer nil
171
179
" The current inf-clojure process buffer.
172
180
@@ -208,6 +216,36 @@ whichever process buffer you want to use.")
208
216
209
217
(put 'inf-clojure-mode 'mode-class 'special )
210
218
219
+ (defun inf-clojure--flavor-lumo-setup ()
220
+ " Setup defcustoms for the Lumo flavor."
221
+ ; ; The defcustoms for the following are already ok:
222
+ ; ; * inf-clojure-set-ns-command
223
+ ; ; * inf-clojure-macroexpand-command
224
+ ; ; * inf-clojure-macroexpand-1-command
225
+ ; ;
226
+ ; ; https://github.com/anmonteiro/lumo/issues/84
227
+ ; ; (setq inf-clojure-var-source-command "(lumo.repl/source %s)")
228
+ ; ; https://github.com/anmonteiro/lumo/issues/87
229
+ ; ; (setq inf-clojure-ns-vars-command "(lumo.repl/dir %s)")
230
+ ; ; https://github.com/anmonteiro/lumo/issues/86
231
+ ; ; (setq inf-clojure-var-apropos-command "(lumo.repl/apropos %s)")
232
+
233
+ ; ; Uncomment after https://github.com/anmonteiro/lumo/pull/88
234
+ ; ; (setq inf-clojure-arglist-command "(lumo.repl/get-arglists \"%s\")")
235
+ (setq inf-clojure-var-doc-command " (lumo.repl/doc %s)" )
236
+ (setq inf-clojure-completion-command " (or (doall (map str (lumo.repl/get-completions \" %s\" )) '())" )
237
+
238
+ (let ((inf-program (inf-clojure--lumo-program)))
239
+ ; ; (message (concat "inf-clojure-program set to: \"" (prin1-to-string inf-program) "\""))
240
+ (setq inf-clojure-program inf-program)))
241
+
242
+ (defun inf-clojure--flavor-setup ()
243
+ " Setup inf-clojure defcustoms depending on the choose flavor."
244
+ (pcase inf-clojure-repl-flavor
245
+ (lumo (progn (message " [inf-clojure] will switch to the Lumo flavor " )
246
+ (inf-clojure--flavor-lumo-setup)))
247
+ (_ (message " [inf-clojure] will default to the Clojure flavor " ))))
248
+
211
249
(define-derived-mode inf-clojure-mode comint-mode " Inferior Clojure"
212
250
" Major mode for interacting with an inferior Clojure process.
213
251
Runs a Clojure interpreter as a subprocess of Emacs, with Clojure I/O through an
@@ -322,6 +360,7 @@ With argument, allows you to edit the command line (default is value
322
360
of `inf-clojure-program' ). Runs the hooks from
323
361
`inf-clojure-mode-hook' (after the `comint-mode-hook' is run).
324
362
\( Type \\ [describe-mode] in the process buffer for a list of commands.)"
363
+ (inf-clojure--flavor-setup)
325
364
(interactive (list (if current-prefix-arg
326
365
(read-string " Run Clojure: " inf-clojure-program)
327
366
inf-clojure-program)))
@@ -770,6 +809,73 @@ Return the number of nested sexp the point was over or after."
770
809
(setq-local eldoc-documentation-function #'inf-clojure-eldoc )
771
810
(apply #'eldoc-add-command inf-clojure-extra-eldoc-commands))
772
811
773
- (provide 'inf-clojure )
812
+ ; ;;; Lumo
813
+ ; ;;; ====
814
+
815
+ ; ; AR - TODO Alternatively you can specify a command string that will be called,
816
+ ; ; which should return a string.
817
+ (defcustom inf-clojure-lumo-classpath-generator " cp"
818
+ " The file used to create the classpath string.
819
+ The classpath string has to be a \" :\" separated list of dir and
820
+ files."
821
+ :type '(choice (string ))
822
+ :group 'lumo )
823
+
824
+ (defcustom inf-clojure-lumo-command " lumo"
825
+ " The command used to launch lumo."
826
+ :type '(choice (string ))
827
+ :group 'lumo )
828
+
829
+ (defcustom inf-clojure-lumo-args " -d"
830
+ " The command arguments used to launch lumo."
831
+ :type '(choice (string ))
832
+ :group 'lumo )
833
+
834
+ (defcustom inf-clojure-lumo-hostname " localhost"
835
+ " The hostname used to launch lumo.
836
+ Note that only if port is specified this will be used."
837
+ :type '(choice (string ))
838
+ :group 'lumo )
839
+
840
+ (defcustom inf-clojure-lumo-port " "
841
+ " The port used to launch lumo.
842
+ Note that if port is specified, inf-clojure will connect to the
843
+ REPL using HTTP socket. No process will be actually started."
844
+ :type '(choice (string )
845
+ (integer))
846
+ :group 'lumo )
847
+
848
+ ; ; AR - not used but left here because it is a possible sanity check
849
+ (defun inf-clojure--lumo-mode-p ()
850
+ " Return true if the lumo is the target REPL."
851
+ (comint-send-string (inf-clojure-proc) " (js/global.hasOwnProperty \" $$LUMO_GLOBALS\" )" ))
852
+
853
+ (defun inf-clojure--empty-string-p (string )
854
+ " Return true if the string is empty or nil. Expects STRING."
855
+ (or (null string)
856
+ (zerop (length string))))
857
+
858
+ (defun inf-clojure--read-classpath (classpath-option )
859
+ " Read the classpath from the input CLASSPATH-OPTION."
860
+ (let ((classpath-file-path (concat (inf-clojure-project-root) classpath-option)))
861
+ (cond
862
+ ((and (file-exists-p classpath-file-path) (file-readable-p classpath-file-path))
863
+ (f-read classpath-file-path))
864
+ ; ; TODO launch a command that returns the classpath string?
865
+ ((message (concat " Option \" " classpath-option " \" was not a (readable) file, the classpath will be empty." ))
866
+ " " ))))
867
+
868
+ (defun inf-clojure--lumo-program ()
869
+ " Return inf-clojure-program for lumo."
870
+ (if (inf-clojure--empty-string-p inf-clojure-lumo-port)
871
+ (concat inf-clojure-lumo-command
872
+ " "
873
+ (when (not (inf-clojure--empty-string-p inf-clojure-lumo-classpath-generator))
874
+ (concat inf-clojure-lumo-args " " ))
875
+ " -c " (inf-clojure--read-classpath inf-clojure-lumo-classpath-generator))
876
+ (cons inf-clojure-lumo-hostname (if (stringp inf-clojure-lumo-port)
877
+ (string-to-number inf-clojure-lumo-port)
878
+ inf-clojure-lumo-port))))
774
879
880
+ (provide 'inf-clojure )
775
881
; ;; inf-clojure.el ends here
0 commit comments