cider icon indicating copy to clipboard operation
cider copied to clipboard

cider-insert-in-repl can't be run twice in a row

Open neilyio opened this issue 5 years ago • 3 comments

Expected behavior

(cider-insert-in-repl
   "(quil.applet/with-applet user/sketch-path (quil.core/redraw))"
   t)

I have the above elisp statement bound to a key, so I easily call re-draw my Quil sketch.

I should be able to call this as many times as needed, with the "(quil.applet/...)" form appearing in the REPL and being evaluated. All the while, the current window that I'm working on stays focused.

Actual behavior

The above elisp works the first time, but if called again immediately produces an error in the repl:

Syntax error compiling at (quil-workflow:localhost:65305(clj)*:1:7700).
Unable to resolve symbol: user> in this context

Steps to reproduce the problem

It seems as if cider-insert-in-repl tries to evaluate the user> prompt itself. This only happens upon successive calls without switching over to the repl window. If I switch over to the repl window and click anywhere, then switch back to my working window, my elisp function with cider-insert-in-repl will work again exactly once. Here's a gif:

cider-insert-issue

Environment & Version information

CIDER version information

CIDER 0.25.0snapshot (package: 20200420.735), nREPL 0.7.0 Clojure 1.10.0, Java 1.8.0_252

Emacs version

GNU Emacs 26.3 (build 1, x86_64-apple-darwin19.3.0, Carbon Version 162 AppKit 1894.3) of 2020-02-09

Operating system

Mac OS Catalina Version 10.15.4 (19E287)

neilyio avatar May 12 '20 20:05 neilyio

I fixed this in the meantime by adding a newline to the string in my elisp code, like so:

(cider-insert-in-repl
   "(quil.applet/with-applet user/sketch-path (quil.core/redraw))\n"
   t)

neilyio avatar May 13 '20 17:05 neilyio

i don't think this function exists anymore

boxxxie avatar Dec 19 '20 23:12 boxxxie

its still there: https://github.com/clojure-emacs/cider/blob/master/cider-mode.el#L241

I'm not able to reproduce but i know these kinds of things are really annoying. image

Some things to try:

Investigate what's going on with cider-repl-input-start-mark. This is what CIDER uses to know where the prompt is. You can see this in action in cider-repl--current-input. In the repl, after you get this you can evaluate (goto-char cider-repl-input-start-mark) and see where it takes you. The function that gets the input is cider-repl--current-input and its called from cider-repl--send-input.

The flip side of this is on the output side. At the end of the send-input function is where the code is sent with cider-nrepl-request:eval. The first arg is the code to evaluate and the second arg is (cider-repl-handler (current-buffer)) which is what to do with it. Step into this and we see a builder function nrepl-make-response-handler which takes a bunch of lambdas, what to do with the return value, what to do with errors, prints, etc. The fifth argument is the done-handler

(lambda (buffer)
       (when show-prompt
         (cider-repl-emit-prompt buffer))
       (when cider-repl-buffer-size-limit
         (cider-repl-maybe-trim-buffer buffer)))

And you probably want to investigate the cider-repl-emit-prompt function to see where that in function the markers are getting set. This stuff isn't particularly fun to work through and doubly so if others can't reproduce. But if you know how to go-to source (M-.) and how to debug functions in elisp, it might take just a few times of seeing what's going on, seeing where the markers are, etc.

dpsutton avatar Dec 20 '20 03:12 dpsutton

Cannot repro

Feel free to re-open if you can on CIDER 1.9.0+

Cheers - V

vemv avatar Oct 28 '23 21:10 vemv