Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to easily experiment with elisp code that involves moving a cursor (caret)?

Tags:

emacs

caret

elisp

I usually play with elisp code on my scratch buffer. I find it hard to play with elisp code that moves cursors in this way because I don't know how to separate the buffer for editing code and the buffer for testing the code.

For example if I want to play with the following code:

(backward-up-list 1)
(backward-sexp 1)
(kill-sexp 2)

from searching with intelligent bracket counting elisp, I'd like to run one line at a time and see what each line does. But the code moves the caret in the very scratch buffer I pasted that code in and I'm already using that caret to edit or run the code. Another problem is that this code is supposed to be tested on a TeX document and my scratch buffer is not a TeX document.

It all comes down to how to separate the painter and the painting.

Though in that example, just looking at the C-h f manual would be enough to understand what's going on. But that's only because this example code is simple enough.

like image 518
Yoo Avatar asked Jan 24 '23 11:01

Yoo


1 Answers

Compile the function with edebug (C-u C-M-x instead of C-M-x), switch to a buffer to experiment in, invoke the function via M-:, and then single-step (n) in the debugger.

Otherwise, learn to think in bigger chunks, and test in your test buffer with M-:. This is what I do for nearly everything, including very complicated code like cperl-mode.

like image 108
jrockway Avatar answered Jan 30 '23 23:01

jrockway