Say I'm editing a file ~/mydirectory/foo.txt.

I'd like to be able to issue a command M-x switch-to-bar-file that copies current contents of ~/mydirectory/foo.txt to a file ~/mydirectory/foo-bar.txt and drops me into a new buffer where I can edit ~/mydirectory/foo-bar.txt.

When I'm done editing ~/mydirectory/foo-bar.txt, I'd like to issue a command M-x unswitch-from-bar-file which copies the current contents of ~/mydirectory/foo-bar.txt back over to ~/mydirectory/foo.txt and drops me back into the buffer where I can edit ~/mydirectory/foo.txt.

It seems that there may be a way to do this with indirect buffers, but I can't quite figure out how to solve my problem.

Is this sort of thing possible?

I can post an example if that would help.

  • 1
    write-file (C-x C-w) doesn't meet your needs? I'm not sure what you're getting at here. This workflow seems very strange. – Tianxiang Xiong Nov 28 '17 at 21:26
  • Maybe I didn't do a great job explaining. I'm trying to keep track of two versions of a latex document (one "quiz" and one "quiz-solutions"). – Brian Fitzpatrick Nov 28 '17 at 21:29
  • Not to be snide, but the usual way one goes about that is to write the quiz, then fill in the solutions... – Tianxiang Xiong Nov 28 '17 at 21:32
  • The reason I left out the context is because I wasn't interested in commentary on my workflow. I think for now your write-file recommendation will do. – Brian Fitzpatrick Nov 28 '17 at 21:37
  • Sounds like a job for org-mode. You can choose to export your solution or not. So you only need single file instead of switching and tracking between files – Enze Chi Nov 28 '17 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.