0

The find-file command automatically selects and uses a preexisting buffer that is visiting the same file.

My problem is, when using the same buffer in multiple frames, the frames will lag significantly (slow response, delayed input, etc.). This problem also occurs when using indirect buffers.

Is there a way to tell Emacs to open a file in a new buffer instead of reusing a preexisting buffer?

  • 1
    Are you sure you don't mean window instead of frame (or perhaps instead of buffer)? – Drew Jun 11 '18 at 14:00
  • find-file re-using an existing buffer for a filename is the standard behaviour regardless of whether Emacs is running as a daemon. The two things are unrelated. I have therefore removed mention of "daemon" from the question. – phils Sep 4 at 23:37
1

Emacs tries to prevent multiple buffers visiting a given file because that's not generally desirable (e.g. you can then have conflicting changes in each of the buffers); but it's certainly possible. In essence you just need the buffer-local buffer-file-name variable to be set.

Here's a very basic command:

(defun find-file-new-buffer (filename)
  "Very basic `find-file' which does not use a pre-existing buffer."
  (interactive "fFind file in new buffer: ")
  (let ((buf (create-file-buffer filename)))
    (with-current-buffer buf
      (insert-file-contents filename t))
    (pop-to-buffer-same-window buf)))
0

When running Emacs as daemon, the different frames that might be open have access to the buffers on memory. a file will not be open twice to prevent conflicts (any changes should be consistent.

Try running M-x ibuffer usually C-x b and choose a buffer to open in window rather than C-x C-f

Your Answer

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

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