我正在使用git的nrepl.el(0.1.6预览,通过el-get配方),我想要clojure缓冲区evals:Cx Ce,CMx,Cc Cr for form,top-level form and region分别将自己发送到nrepl缓冲区并进行评估,而不是默认的评估屏幕外的行为,结果返回到echo区域。
有没有办法做到这一点,或者是否有另一组用于此目的的键绑定,我不会通过他们的描述来识别?
感谢。
答案 0 :(得分:12)
nrepl.el目前不支持您描述的行为。
但好消息是你在emacs-land中,所以应该可以编写自己的自定义处理程序来将输出定向到nrepl缓冲区并根据需要调整你的键绑定。
例如,这相当于C-x C-e,但是将评估结果发送到repl缓冲区而不是迷你缓冲区:
(defun my-interactive-eval-to-repl (form)
(let ((buffer nrepl-nrepl-buffer))
(nrepl-send-string form (nrepl-handler buffer) nrepl-buffer-ns)))
(defun my-eval-last-expression-to-repl ()
(interactive)
(my-interactive-eval-to-repl (nrepl-last-expression)))
答案 1 :(得分:1)
这是一个也将错误发送到正确的窗口的版本:
(defun my-nrepl-handler (buffer)
"Make an interactive eval handler for buffer, but emit the value or out to the repl, not the minibuffer."
(nrepl-make-response-handler buffer
(lambda (buffer value)
(progn
(nrepl-emit-result (nrepl-current-repl-buffer) value t)
(nrepl-emit-prompt (nrepl-current-repl-buffer))))
(lambda (buffer out)
(nrepl-emit-interactive-output out)
(nrepl-emit-prompt (nrepl-current-repl-buffer)))
(lambda (buffer err)
(message "%s" err)
(nrepl-highlight-compilation-errors buffer err))
(lambda (buffer)
(nrepl-emit-prompt buffer))))
(defun my-interactive-eval-to-repl (form)
"Evaluate the given FORM and print value in the repl."
(remove-overlays (point-min) (point-max) 'nrepl-note-p t)
(let ((buffer (current-buffer)))
(nrepl-send-string form (my-nrepl-handler buffer) (nrepl-current-ns))))
(defun my-eval-last-expression-to-repl ()
(interactive)
(my-interactive-eval-to-repl (nrepl-last-expression)))
(eval-after-load 'nrepl
'(progn
(define-key nrepl-interaction-mode-map (kbd "C-x C-e") 'my-eval-last-expression-to-repl)))
答案 2 :(得分:0)
由于此处提供的解决方案均不适用于我的版本,因此我想出了自己的实现:
(defun eval-in-nrepl ()
(interactive)
(let ((exp (nrepl-last-expression)))
(with-current-buffer (nrepl-current-repl-buffer)
(nrepl-replace-input exp)
(nrepl-return))))
(eval-after-load 'nrepl
'(define-key nrepl-interaction-mode-map
(kbd "C-x C-.")
'eval-in-nrepl))
它结合C-x C-。达到预期的行为。