Is there a way in emacs to open a file (or a dired directory) in a new buffer, even if there's a buffer with the same file (or directory)?

find-file and find-alternate-file always return the open buffer instead of creating a new one.

EDIT: The use case I have is that I am using dired-single to navigate through directories using a single buffer (so that new directories are opened in the same buffer using find-alternate-file). However, if I have two separate buffers for two different directories (which I do when copying files from directory to another, for example) and I navigate in one buffer to the directory of the other, I end up with a single buffer and two frames. I would instead like to have two separate buffers showing the same directory. Much like what happens when I explore directories in my file explorer.

  • 1
    Why do you want to do that? If you make changes in one buffer, what do you expect to happen in the other? Emacs is trying to protect you from screwing up your file by returning the old buffer, so trying to circumvent that behavior is probably a mistake. You might want to edit your question with what you are really trying to accomplish. – NickD May 28 '19 at 13:04
  • I added the use case I am trying to address. – Tohiko May 28 '19 at 13:22
  • 1
    I'm not quite getting it. What's the problem with having one buffer shown in two frames? Would a cloned buffer suffice for your purposes? – zck May 28 '19 at 13:42
  • I find myself in the following situation many times: I have two open dired buffers one at /A/B and one at /A. I want to copy a file from /A/C to /A. So I use the first buffer starting from /A/B and I hit up (calling dired-single-up-directory) to go to /A, intending to navigate to C within A. However, since I have /A already open, that buffer is just brought up I end with a single buffer. A file explorer allows multiple independent views of the same directory and I am trying to a achieve that with dired. – Tohiko May 28 '19 at 14:07
  • If you intend to navigate to A/C then why don't you just do that directly from A/B instead of first going up (^) to A? Just C-x d, remove the B from the inserted default directory name A/B, and hit RET. Or, if you also want to keep buffer A/B and its window, use C-x 4 d and do the same thing. It sounds like you are complicating things for yourself. – Drew May 28 '19 at 15:50

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.