0

The below function creates a new instance of the file myfile.txt (regardless of if myfile.txt is already opened or not).

How to force emacs to use the existing frame of that file (if any)?

(defun visit_my_file ()
(interactive)
(find-file "/path/to/myfile.txt" t))

Any alternative solution is welcomed.

1 Answer 1

1

It already does that. It checks both for buffers that have opened the same exact filename, and for buffers that have opened the same file but under a different name (think of cases involving symlinks, for example). If it finds a buffer with the same buffer-filename, then it simply selects that buffer. If it finds a buffer that has opened the same file under a different name, then it either issues a warning or, if find-file-existing-other-name or find-file-visit-truename are non–nil, then it selects the existing buffer instead of creating a new one.

Your Answer

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

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