I am debugging an ocaml program with M-x camldebug while adding comments to the source code and the debugger shows incorrect positions in my tuareg/merlin window. It shows the positions as present in the original source file that do not match the edited file.

As a workaround, I would like to have my file opened in one buffer (the one I'm using with the debugger), and have another buffer with the same file opened that is not synchonized with the first one, i.e., as if it was open in a separate process and without changes in one buffer appearing in the other. Then, I'd just save my files after I'm done debugging.

I tried C-x 4 c, but that still makes changes in one buffer appear in the other. I have an obvious workaround of copying the file to scratch to edit it and then back again, but I am searching for a cleaner way.

  • 1
    Try M-: (setq buffer-file-name nil) RET in the debugger's buffer. That will enable you to visit the file in a new buffer for editing. It's unclear to me whether this would break the debugger's connection with the original buffer, though.
    – phils
    Nov 28, 2018 at 2:48
  • 1
    If it's a problem, you could alternatively leave the debugger's buffer alone, switch to a new empty buffer, use M-x set-visited-file-name, and then M-x revert-buffer.
    – phils
    Nov 28, 2018 at 2:56
  • 1
    I feel like there ought to be an easier existing way of doing this; but if there is then I'm not seeing it... I think most of the related functions go via find-file-noselect which implements the "If a buffer exists visiting FILENAME, return that one" behaviour.
    – phils
    Nov 28, 2018 at 2:57
  • I tried using the method in the first comment: opened file in two buffers (1) (2), set buffer-file-name to nil in (2) (the buffer that the debugger was using to show currently debugged code) and made changes in (1). It worked separately. I saved (1), prompted a few times where do I want to save it. Then, the debugger started following the code in (1) instead of (2), i.e., in the freshly saved buffer. So, as long as I save after finishing debugging the file, it works for me. I'll check second comment now.
    – Xilexio
    Nov 28, 2018 at 3:19
  • I tried the second method - C-x b to open buffer named -, then M-x set-visited-file-name to my file, then M-x revert-buffer and it loaded the file that was editable separately. However, then the debugger started using that buffer instead of the originally opened one. The problem is that after saving the one not used by the debugger, it started asking for confirmation to reload from disk on each debugger step. Probably debugger kept triggering some kind of refresh. Not sure how it decides which buffer to use.
    – Xilexio
    Nov 28, 2018 at 3:26

1 Answer 1


From the experimentation in the comments, the following worked, albeit with a few rough edges.

In the debugger's buffer, use:

M-: (setq buffer-file-name nil) RET

That then enables you to visit the file again in a separate new buffer for editing, with C-xC-f.

The reported result was that, as desired, it was possible to edit in the new buffer without affecting the buffer being used by the debugger; however saving the new buffer caused the debugger to 'notice it' and start using it instead of the original buffer, so it was necessary to not save the changes until debugging was completed.

Your Answer

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

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