Fork me on GitHub
#emacs
<
2023-02-10
>
Lyn Headley15:02:52

I feel like I am leaving value on the table through the clumsiness of how I access and manipulate the history of my interactions with the repl. I should be able to see and re-execute prior expressions, but since I send everything to the repl by evaluating code within its context in the source code rather than by typing into a repl, The cider history mode shows me nothing. Any thoughts on this?

otfrom16:02:54

aaaaand I should have read your post a bit better (sorry)

otfrom17:02:56

yes, having the things you C-x C-e go to the repl history would be nice

practicalli-johnny19:02:14

I would like understand what value an expression by expression history would provide so I can understand what I may be missing. To me the source code buffers are the repl history (without the repeated evaluations of very similar things). When using Cider to evaluate code in a source code buffer, a marker in the margin (gutter) indicates it was evaluate. If the code is changed, the marker is removes so I know the function is different to what is evaluated in the REPL. When I want to remember the shape of data that a function returns I'll print the evaluation result as a comment. Or for larger results I'll use the cider inspector, which will update each time a function is evaluated if it's buffer is kept open. Or I'll connect Portal data inspector and do the same. If I am evolving the design of a function, then I keep a design journal. I create a rich comment with different versions of a function (or functions) to help determine what design choices I want to make. I usually start the rich comment in the same namespace and migrate any code I want to keep into a separate namespace when I am done. If I am breaking ground on a completely new challenge or new set of libraries, I my start the design journal in a separate namespace (still in a comment so it doesn't get loaded unless I want it too) If the experiments are valuable I'll keep them in the project but move them to a path that is outside the normal class path used for the project, e.g. develop, defining an alias I can optionally use when running the reply to include these experiments on the class path. Before the comment form I add a directive to tell clj-kondo to ignore duplicate definitions which I added as a Clojure LSP snippet for convenience Are there further things I could do with the repl history? I must admit that I rarely use a repl prompt directly, except for separation of long running processes or interacting with component lifecycles (start/refresh/stop).

👍 2
Lyn Headley19:02:57

I use comment blocks too, but sometimes I jump around in files and evaluate comment blocks in several different files, and then I lose track of my history.

practicalli-johnny20:02:53

As far as I know the only way to have a repl buffer history is to use the repl buffer, sending each evaluation to the repl buffer. Then the history can be scrolled. I assume it would be possible to write an elisp function that calls both evaluate in the source code buffer and send expression to repl buffer cider commands. Then add a different key bindings for this function.

Benjamin12:02:40

(advice-add
 #'cider-nrepl-request:eval
 :before
 (defun my-cider-add-evals-to-history (input callback &optional ns line column additional-params connection)
   (let ((connection (or connection (cider-current-repl nil 'ensure))))
     (with-current-buffer connection
       (cider-repl--add-to-input-history input)))))
sounds like you want to add to the history when evaling

👍 2