bug-auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#58005: 13.1.4; Can't work with indirect buffers


From: Vangelis Evangelou
Subject: bug#58005: 13.1.4; Can't work with indirect buffers
Date: Mon, 15 Apr 2024 10:48:02 +0100

Hi Ikumi.

Thank you for your email.

Current AUCTeX source has some references to the variable
`buffer-file-name', as well as call to the function of the same name. It
seems that the variable is nil in indirect buffers. Is it safe to leave
those references unchanged?

You are correct. I can see a few cases:

./tex.el:2440:      (and buffer-file-name
./tex.el:2441:           (file-name-directory buffer-file-name)))))))

In the above, I think that part of the code is in fact redundant. That's because if the function's `expand-file-name'  second argument is nil, then it's taken to be the default-directory. Quoting from the help page:

Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative
(does not start with slash or tilde); both the directory name and
a directory’s file name are accepted.  If DEFAULT-DIRECTORY is nil or
missing, the current buffer’s value of ‘default-directory’ is used.
NAME should be a string that is a valid file name for the underlying
filesystem.

So, with the current code, the second argument will be something like /home/me/file.tex, while if nil, it is assumed to be /home/me/ which in the end has the same effect. I can't imagine a situation where that's not the case.

For all other cases:

./style/catchfilebetweentags.el:70:                 (buffer-file-name (current-buffer)))))
./style/pdfsync.el:40:                (file-relative-name (buffer-file-name)
./tex-info.el:707:                              (unless (file-exists-p (buffer-file-name))
./toolbar-x.el:1465:                           (buffer-file-name (buffer-base-buffer))
./toolbar-x.el:1469:                 :visible (or buffer-file-name
./toolbar-x.el:1479:                :visible (or buffer-file-name
./latex.el:2564:  (let ((name (file-name-nondirectory buffer-file-name)))
./latex.el:2585:               (file-name-nondirectory buffer-file-name))))

I believe we can change buffer-file-name to (TeX-buffer-file-name) where the file "tex.el" is loaded for consistency. The function with nil argument has the same effect as the variable. I'm happy to make the changes to that too if that's OK with you.

The major portion of the addition is
        (cond
[...]
         ;; Indirect buffer
         (my-buffer
          (with-current-buffer my-buffer
            (TeX-master-file nil nondirectory ask)))
                             ^^^
. Why is the first argument always nil? The original function receives
the second argument as `extension'. Aren't there cases that we should
provide the same argument `extension' here?

As far as I understand the variable TeX-master always points to the name of the file *without* the extension. That's why the first argument is nil. Otherwise, if extension is say "pdf", then the TeX-master for the indirect buffer will be something like "foo.pdf". The extension part is added later in the code in the function TeX-master-file.

I don't get the error that you mentioned. Can you please send me a traceback?



On Sun, 14 Apr 2024 at 16:01, Ikumi Keita <ikumi@ikumi.que.jp> wrote:
Hi Vangelis,

>>>>> Vangelis Evangelou <evangelou@gmail.com> writes:
> I am using indirect buffers with auctex and I am affected by this. My use
> is to have an indirect buffer narrowed to the preamble of my file.
> Typically, if I want to define a new command, I switch to the narrowed
> buffer instead of jumping at the top of the buffer to type the command and
> then go back to where I was later. I implemented a patch (attached) where,
> essentially, I replace instances of `buffer-file-name' with a new function
> `TeX-buffer-file-name' defined as

> (defun TeX-buffer-file-name (&optional BUFFER)
>   (buffer-file-name (or (buffer-base-buffer BUFFER) BUFFER)))

Thank you for your proposal. I'd like to comment on it. Please bear with
me if I'm saying something stupid since I don't know indirect buffer well.

Current AUCTeX source has some references to the variable
`buffer-file-name', as well as call to the function of the same name. It
seems that the variable is nil in indirect buffers. Is it safe to leave
those references unchanged?

> I also added a condition in TeX-master-file to check for indirect
> buffer.

The major portion of the addition is
        (cond
[...]
         ;; Indirect buffer
         (my-buffer
          (with-current-buffer my-buffer
            (TeX-master-file nil nondirectory ask)))
                             ^^^
. Why is the first argument always nil? The original function receives
the second argument as `extension'. Aren't there cases that we should
provide the same argument `extension' here?

There are still some calls to the function `buffer-file-name' which
weren't replaced by `TeX-buffer-file-name' in the source. You can see
them with
git grep -E "[^-]buffer-file-name"
on the repo directory. (This lists references to the variable
`buffer-file-name' as well.)

It seems that the proposed change doesn't work in indirect buffer if
`TeX-output-dir' is specified. To try:
1. Open the following file.
2. Type C-x 4 c
3. Type C-c C-c RET
4. Then AUCTeX signals error with "LaTeX errors in ‘*~/test-tex/<none> output*’. Use C-c ` to display."
Can you resolve this problem?
----------------------------------------------------------------------
\documentclass{article}
\begin{document}

dummy

\end{document}

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: t
%%% TeX-output-dir: "build"
%%% End:
----------------------------------------------------------------------

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
#Gaza #StopMassiveKilling #CeasefireNOW

reply via email to

[Prev in Thread] Current Thread [Next in Thread]