Why does clone-buffer
not work on file buffers.
I can make it work by the following advice:
(advice-add 'clone-buffer :around
(lambda (oldfun &rest args)
"Allow cloning file buffers."
(interactive "bName of new cloned buffer: ")
(let (buffer-file-name)
(apply oldfun args))))
The clone is a non-file buffer. One can modify it and save it into a new file with save-buffer
.
Everything is working quite fine. So why does the original command clone-buffer
test whether the current buffer is a file buffer and disallow cloning in that case?
My current best guess for the motivation of the restriction: The change from a file buffer to a non-file buffer is quite hard.
Examples:
- Version control like
vc-git
does not work anymore. compile-command
compiles the original buffer file and not the clone
clone-buffer
on a file-visiting buffer created withclone-indirect-buffer
. Does cloning from an indirect buffer fix the issues withvc-git
andcompile-command
? – Melioratus Jan 23 '19 at 19:39write-buffer
andfind-file
the old one when I need it again. Alternatively one couldinsert
thebuffer-string
into a new file buffer if it is clear that one wants to keep the original buffer. – Tobias Jan 24 '19 at 03:18clone-indirect-buffer
is also faulty. It keepsvc
mode despite it is not working there (buffer-file-name
is nil). So it seemsvc
is not really the reason for restrictingclone-buffer
to non-file buffers. – Tobias Jan 24 '19 at 03:25diff-buffer-with-file
was fixed not so long ago to handle being called from indirect buffers. It may be sensible for othervc
features to do likewise. Raise bug reports, if there aren't any already. – phils Jan 24 '19 at 07:41