@@ -135,6 +135,7 @@ mode. Default is whitespace followed by 0 or 1 single-letter colon-keyword
135
135
(define-key map " \C -c\C -r" #'inf-clojure-eval-region )
136
136
(define-key map " \C -c\M -r" #'inf-clojure-reload )
137
137
(define-key map " \C -c\C -n" #'inf-clojure-eval-form-and-next )
138
+ (define-key map (kbd " C-c C-j" ) #'inf-clojure-insert-defun )
138
139
(define-key map " \C -c\C -z" #'inf-clojure-switch-to-repl )
139
140
(define-key map " \C -c\C -i" #'inf-clojure-show-ns-vars )
140
141
(define-key map (kbd " C-c C-S-a" ) #'inf-clojure-apropos )
@@ -682,15 +683,25 @@ Prefix argument AND-GO means switch to the Clojure buffer afterwards."
682
683
" Send the string CODE to the inferior Clojure process to be executed."
683
684
(inf-clojure--send-string (inf-clojure-proc) code))
684
685
686
+ (defun inf-clojure--defun-at-point (&optional bounds )
687
+ " Return text or range of defun at point.
688
+ If BOUNDS is truthy return a dotted pair of beginning and end of
689
+ current defun else return the string.."
690
+ (save-excursion
691
+ (end-of-defun )
692
+ (let ((end (point ))
693
+ (case-fold-search t )
694
+ (func (if bounds #'cons #'buffer-substring-no-properties )))
695
+ (beginning-of-defun )
696
+ (funcall func (point ) end))))
697
+
685
698
(defun inf-clojure-eval-defun (&optional and-go )
686
699
" Send the current defun to the inferior Clojure process.
687
700
Prefix argument AND-GO means switch to the Clojure buffer afterwards."
688
701
(interactive " P" )
689
702
(save-excursion
690
- (end-of-defun )
691
- (let ((end (point )) (case-fold-search t ))
692
- (beginning-of-defun )
693
- (inf-clojure-eval-region (point ) end and-go))))
703
+ (let ((bounds (inf-clojure--defun-at-point t )))
704
+ (inf-clojure-eval-region (car bounds) (cdr bounds) and-go))))
694
705
695
706
(defun inf-clojure-eval-buffer (&optional and-go )
696
707
" Send the current buffer to the inferior Clojure process.
@@ -731,6 +742,24 @@ With prefix argument EOB-P, positions cursor at end of buffer."
731
742
(push-mark )
732
743
(goto-char (point-max ))))
733
744
745
+ (defun inf-clojure-insert-and-eval (form )
746
+ " Insert FORM into process and evaluate.
747
+ Indent FORM. FORM is expected to have been trimmed."
748
+ (let ((clojure-process (inf-clojure-proc)))
749
+ (with-current-buffer (process-buffer clojure-process)
750
+ (comint-goto-process-mark )
751
+ (let ((beginning (point )))
752
+ (insert (format " %s " form))
753
+ (let ((end (point )))
754
+ (goto-char beginning)
755
+ (indent-sexp end)))
756
+ (comint-send-input t ))))
757
+
758
+ (defun inf-clojure-insert-defun ()
759
+ " Send current defun to process."
760
+ (interactive )
761
+ (inf-clojure-insert-and-eval (string-trim (inf-clojure--defun-at-point))))
762
+
734
763
735
764
; ;; Now that inf-clojure-eval-/defun/region takes an optional prefix arg,
736
765
; ;; these commands are redundant. But they are kept around for the user
0 commit comments