1

I teach, and I like to use real files as examples in class. I want to be able to edit the buffer to show student things, but I don't want to risk accidentally writing the changes on the file.

What I currently do is to open them, run write-file and save them as a different file in a temp directory. But I wonder if there's a more elegant way. I tried find-file-read-only, but it doesn't allow me to edit. I couldn't find anything in the Manual, at least in the File Handling chapter.

I wonder if I can open a file in a buffer that acts like the Tutorial buffer. I can edit the buffer, but if I try to close it, it won't prompt me to save it. And even if I try to save it, it won't assume me the original file path/name as the place to write it on.

Any ideas?

11
  • 1
    Why not open a random buffer and do insert-file (usually bound to C-x i) to put the file contents into said buffer? Commented May 15, 2022 at 13:04
  • Trivial workaround: Make the file read-only on the filesystem.
    – phils
    Commented May 15, 2022 at 13:35
  • @phils, if I do that, it doesn't let me edit it. Commented May 15, 2022 at 13:46
  • @FranBurstall, thanks I didn't know about insert-file. I tried that, but a side effect is that because I'm bringing the contents without the file-name, the buffer won't automatically activate the modes I need on the file. If it is an org file, I'll have to run org-mode, python-mode for python files, etc. That makes it kind of cumbersome as well. Commented May 15, 2022 at 13:50
  • 3
    @elPolloDiablo The file itself being read-only will prevent you from being able to clobber it if you try to save changes, but you can still edit the buffer by togging read-only mode with C-x C-q.
    – phils
    Commented May 15, 2022 at 15:18

0

Your Answer

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