Subject: bug#25674: Support for subfiles in `reftex-TeX-master-file'

From: Arash Esbati <[email-masked]>
Date: Mon, 13 Feb 2017 09:34:12 +0100

Hi Mosè,

Mosè Giordano <[email-masked]> writes:

> 2017-02-10 9:48 GMT+01:00 Arash Esbati <[email-masked]>:
>>
>> I think the regexp can be reduced to
>>
>> --8<---------------cut here---------------start------------->8---
>>             (re-search-forward
>>              "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
>>              nil t))
>> --8<---------------cut here---------------end--------------->8---
>>
>> as `reftex-TeX-master-file' checks if .tex extension is given or not.
>> With this change, one can use `C-c )' over all files in a project and
>> `C-c C-c' compiles a only subfile when issued in it.
>>
>> Any comments?  I would prepare a patch after confirmation here.
>
> `thing-at-point-file-name-chars' is a good list of characters
> allowable in filenames (maybe it won't work in some corner case but
> should do the job in most cases).  However I don't have a preference
> between your regexp and `thing-at-point-file-name-chars'.

Thanks for your response and the hint.  I see that @ is missing in
`thing-at-point-file-name-chars', I hope that nobody names a file
"[email-masked]" (corner case as you said), but I think we are on the safe
side if we match everything and reduce the support factor in future ;-)

@Tassilo: Can please apply this patch to Emacs master?  TIA.

>From 19541d95dcfcd167f4cf729434341b630bba0e1b Mon Sep 17 00:00:00 2001
From: Arash Esbati <[email-masked]>
Date: Mon, 13 Feb 2017 09:22:12 +0100
Subject: [PATCH] Match all characters in optional argument of \documentclass

* lisp/textmodes/reftex.el (reftex-TeX-master-file): Match all
characters in optional argument containing name of the main file.
---
 lisp/textmodes/reftex.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index 18b35981f8..9754d2b20f 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -352,7 +352,7 @@ reftex-TeX-master-file
 	 ((save-excursion
             (goto-char (point-min))
             (re-search-forward
-             "^[[:space:]]*\\\\documentclass\\[\\([[:word:].]+\\)\\]{subfiles}"
+             "^[[:space:]]*\\\\documentclass\\[\\([^]]+\\)\\]{subfiles}"
              nil t))
           (match-string-no-properties 1))
          ;; AUCTeX is loaded.  Use its mechanism.
-- 
2.11.0

Best, Arash