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-gitdoes not work anymore. compile-commandcompiles the original buffer file and not the clone
clone-bufferon a file-visiting buffer created withclone-indirect-buffer. Does cloning from an indirect buffer fix the issues withvc-gitandcompile-command? – Melioratus Jan 23 '19 at 19:39write-bufferandfind-filethe old one when I need it again. Alternatively one couldinsertthebuffer-stringinto a new file buffer if it is clear that one wants to keep the original buffer. – Tobias Jan 24 '19 at 03:18clone-indirect-bufferis also faulty. It keepsvcmode despite it is not working there (buffer-file-nameis nil). So it seemsvcis not really the reason for restrictingclone-bufferto non-file buffers. – Tobias Jan 24 '19 at 03:25diff-buffer-with-filewas fixed not so long ago to handle being called from indirect buffers. It may be sensible for othervcfeatures to do likewise. Raise bug reports, if there aren't any already. – phils Jan 24 '19 at 07:41