1

I am working with Quarto, which is based on mixing Markdown with code snippets from various languages. Hence it relies on polymode.

Sometimes when I have multiple Quarto .qmd files open and want to save the buffer to file, the minibuffer sometimes prompts me whether I want to overwrite the contents to another .qmd file than the one I'm working on, and if I enter [y] then the original contents of the other file is overwritten and lost.

This only happens in with this type of file, and maybe due to polymode it seems there might be multiple buffers associated with the same file. For instance, for a file called "file.qmd", there may be a buffer called "file.qmd [Python]" and "file.qmd", and so on, from what I see in the buffer list.

Has anyone had this experience and know a workaround? I suppose I need to reassociate a buffer with the correct file but not sure how to do that or if there is a better way.

4
  • 1
    C-h v buffer-file-name holds the path of the visited file, so that will be what's being changed to the wrong value. If you use C-x C-w (write-file) you can write to any file, updating that variable. Or you could set the variable directly. Commented Aug 29, 2024 at 23:44
  • 1
    I don't know anything about polymode, but it sounds like a good line to follow if you're trying to debug this. Commented Aug 29, 2024 at 23:45
  • 1
    You can also M-x set-visited-file-name (which does quite a lot more than just setting buffer-file-name... it might be the better method of recovery... it's a bit hard to know for sure, though.) Commented Aug 29, 2024 at 23:55
  • @phils these are all great things to try. It doesn't happen every time which makes it hard to debug but I will inspect buffer-file-name and use set-visited-file-name at next occurrence. Many thanks. Commented Aug 30, 2024 at 7:28

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.