Suppose I'm working on a file in org-mode or enriched-mode or html-mode ..., and I wanted to see the same contents in an other window with an other mode, say text-mode, how to do that?
I tried to clone the buffer using C-x 4 c, but when I change the mode in the cloned buffer, It changes in the original buffer too, even that its mode line doesn't say so.
1 Answer
I have written up a library jac.el
that does exactly what I have described as solution in my comment:
The problem with clone-indirect-buffer is that text properties are attached to the text but not to the buffer and font-lock works on text properties. From what I know the only way to have two independent font-locks on the same text is to copy the text into another non-file buffer and to synchronize all modifications that are not text property changes.
Just put the file jac.el into your load-path
and add
(autoload 'jac "jac")
into your init file. Re-evaluate the init file or restart Emacs.
Afterwards you can clone buffers with jac
. The clones do not inherit the text properties from their originals.
Unlike it is the case for clone-indirect-buffer
buffers cloned with jac
can have different major modes and are nevertheless correctly fontified.
Disclaimer: Please use the package with caution. It is pretty new and there may be issues. Please report any issues you stumble over at the issue tracker.
clone-indirect-buffer
is that text properties are attached to the text but not to the buffer and font-lock works on text properties. From what I know the only way to have two independent font-locks on the same text is to copy the text into another non-file buffer and to synchronize all modifications that are not text property changes.mmm-mode
. One can have multiple major-modes on one buffer.clone-buffer-indirect
) and switch onauto-revert-mode
. Therewith you can have alternate font-lock for the same modified file whenever you save. The code follows...(defun new-buffer-same-file (&optional buf) "Create a new buffer for the same file as BUF is visiting." (interactive) (auto-revert-mode) (let ((file (buffer-file-name buf)) (new-buf (generate-new-buffer (buffer-name buf)))) (with-current-buffer new-buf (setq buffer-file-name file) (auto-revert-mode) (display-buffer))))