2

I've been able to do this before, but I can't remember the 'recipe' of sorts.

Say I've got the following function:

(defun fancy-stuff ()
  (with-current-buffer (get-crazy-process-output)
    (do-crazy-post-process)))

I want to debug the crazy post-processing and be able to see where/when it moves point in that buffer.

I've of course instrumented do-crazy-post-process with edebug-defun, but when I step through the code, I have no visual indication of how point is moving in the temporary buffer.

3
  • Did you try M-x debug-on-entry do-crazy-post-process? What did you try? The question might be clearer if you described what you tried.
    – Drew
    Jul 30, 2017 at 14:52
  • @Drew See edit. Jul 30, 2017 at 21:31
  • 1
    In edebug, pressing p will temporarily select the current buff in a window and show where point is.
    – YoungFrog
    Jul 30, 2017 at 22:12

2 Answers 2

4

True to form, I found the answer while asking the question. For anyone else who finds this useful:

(view-buffer-other-window (current-buffer))

If you place this form anywhere in the form that's being instrumented, you'll see point move in real-time as you step through the code. For example,

(defun fancy-stuff ()
  (with-current-buffer (get-crazy-process-output)
    (view-buffer-other-window (current-buffer))
    (do-crazy-post-process)))
4
  • Please consider showing how you use that in connection with the code in your question.
    – Drew
    Jul 30, 2017 at 14:51
  • 1
    @Drew Good advice, thank you :-) See edit. It's been a while since I've been on SE – my habits are a little rusty. Jul 30, 2017 at 21:32
  • It turns out it is not a good idea to use view-buffer-other-window for this purpose because it makes the buffer read-only. Can cause a very confusing debugging experience. Jul 19, 2020 at 14:49
  • @LionelHenry interesting -- is there an alternative folks should prefer? Jul 21, 2020 at 14:00
2

I found this question because I was having trouble debugging a function that used with-temp-buffer. Using edebug one can press p to temporarily switch to where point is, but this isn't much good because the temp buffer will be gone once edebug is finished.

The easy way in this case is to replace

(with-temp-buffer
  stuff)

with

(with-current-buffer (get-buffer-create "temp-buffer")
  stuff)

And then use the trick above, so:

(with-current-buffer (get-buffer-create "temp-buffer")
  (view-buffer-other-window (current-buffer))
  stuff)

Now the temp buffer will still be around afterwards for inspection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.