nrepl.el: how to eval clojure buffer form to nrepl buffer instead of echo area?

后端 未结 3 2037
粉色の甜心
粉色の甜心 2021-02-05 20:51

I\'m using nrepl.el from git (0.1.6-preview, via el-get recipe), and I would like clojure buffer evals: C-x C-e, C-M-x, C-c C-r for form, top-level form and region respectively,

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 21:13

    Here is a version that also sends errors to the correct windows:

    (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)))
    

提交回复
热议问题