Igor Sosa Mayor <[email protected]> writes:

Hi Igor,

> I use very often the function clone-indirect-buffer for editing a file
> in different points and above to have different narrows (this works
> with org files/buffer perfectly).
>
> With auctex (reftex?) I have the problem that I can not add
> bibliographical refs in a cloned buffer, because I get the error
> "Reftex can only work in buffers with a file" (or something like
> that). (The buffer is obviously related to a file...)
>
> Is there maybe something to do?

The problem is that in an indirect buffer, `buffer-file-name' is nil and
the function of the same name also returns nil but reftex requires that
it returns a file name.  (I have no idea why indirect buffers don't have
the file association of their base buffer...)

It's possible to check if we're in an indirect buffer and if so use the
base buffer's buffer-file-name, so reftex could be made functional in
indirect buffers.  But I'm currently not sure about possible
consequences.

For the time being, you can use this piece of advice which makes
`buffer-file-name' return the base buffer's buffer-file-name in buffers
where reftex is active.

--8<---------------cut here---------------start------------->8---
(defun my/buffer-file-name-for-reftex (old-fn &optional buffer)
  (let ((bfn (funcall old-fn buffer)))
    (if reftex-mode
        (or bfn
            (let ((base (buffer-base-buffer buffer)))
              (when base
                (funcall old-fn base))))
      bfn)))

(advice-add #'buffer-file-name :around #'my/buffer-file-name-for-reftex)
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo


_______________________________________________
auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex

Reply via email to