我正在使用来自 git 的 nrepl.el(0.1.6-preview,通过 el-get 配方),我希望 clojure buffer evals: Cx Ce, CMx, Cc Cr 分别用于表单、顶级表单和区域,以将自己发送到 nrepl 缓冲区并在那里进行评估,而不是在屏幕外评估并将结果返回到回显区域的默认行为。
有什么方法可以做到这一点,或者是否有另一组用于此目的的键绑定,我无法通过他们的描述来识别?
谢谢。
nrepl.el 目前不支持您描述的行为。
但好消息是您在 emacs 领域,因此应该可以编写自己的自定义处理程序以将输出定向到 nrepl 缓冲区并根据需要调整键绑定。
例如,这相当于 Cx Ce,但将评估结果发送到 repl 缓冲区而不是 minibuffer:
(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)))
这是一个也将错误发送到正确窗口的版本:
(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)))
由于此处提供的解决方案均不适用于我拥有的版本,因此我提出了自己的实现:
(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))
它结合 Cx C-。到所需的行为。