Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: rename "recursive search" to "directory scan" #2559

Closed
wants to merge 3 commits into from

Conversation

shuber2
Copy link
Contributor

@shuber2 shuber2 commented Nov 4, 2022

The method 6 of finding the main file is based on a directory scan which is described as "recursive" scan. However, while a recursive scan suggests a (recursive) directory descent, the opposite is true: the unique ascending path of parent directories is scanned.

This is fixed in the following steps:

  1. The method is renamed to "directory scan method"
  2. The method description is adapted to reflect this behavior more clearly. In particular, it is explicitly mentioned that no recursive directory descent is performed.
  3. The option to disable this method is renamed to g:vimtex_disable_directory_scan_main_file_detection

As a side effect, the overall description of the directory scan method is reworked.

As a further side effect, the name of this method is more independent of the algorithmic mechanism, but rather reflects the policy, cf. "policy versus mechanism" paradigm.

@shuber2
Copy link
Contributor Author

shuber2 commented Nov 4, 2022

@lervag Sorry, I was not thinking you would be that quick with the work on the other issue. So this pull request will have merge conflict with #2558.

@lervag
Copy link
Owner

lervag commented Nov 5, 2022

The method 6 of finding the main file is based on a directory scan which is described as "recursive" scan. However, while a recursive scan suggests a (recursive) directory descent, the opposite is true: the unique ascending path of parent directories is scanned.

Interesting point. The reason I use "recursive" here is because it is functionally recursive in the sense that same algorithm is used recursively for complex documents, e.g. main.tex ← chapter.tex ← section.tex. If you open section.tex, it will being the search from itself, then find that chapter.tex contains section.tex. It then recurses and finds main.tex in the next "iteration". Thus, the point of "recursive" is not about the directory descent at all, it has to do with the project graph of a multi-file LaTeX project.

I'm, curious, though, if you may still have a point with regard to user point of view. What I explained above is an implementation detail, and it is not important (in most cases) for users to care about that.

I'm curious what you think about this.

In any case, I notice that your PR also has good suggestions for how to rephrase and improve the wording, also in general. So I will want to merge it somehow, regardless of the outcome of this discussion!

  1. The option to disable this method is renamed to g:vimtex_disable_directory_scan_main_file_detection

If we rename an option, we should put the old option in a deprecated list to guide users. That's trivial for me, so I can do it if we go this way. Or I could show you the relevant part in the code.

As a further side effect, the name of this method is more independent of the algorithmic mechanism, but rather reflects the policy, cf. "policy versus mechanism" paradigm.

Yes, this seems to be relevant to what I wrote above.

Sorry, I was not thinking you would be that quick with the work on the other issue. So this pull request will have merge conflict with #2558.

I have no problems with merge conflicts. It should be mostly trivial in this case, I think. I'll let you decide if you want to rebase your PR on top of the current master, or if you want me to handle the merge when we've settled the discussions.

doc/vimtex.txt Outdated Show resolved Hide resolved
doc/vimtex.txt Outdated Show resolved Hide resolved
doc/vimtex.txt Outdated Show resolved Hide resolved
@shuber2
Copy link
Contributor Author

shuber2 commented Nov 5, 2022

@lervag Thank you for your feedback. I did some work on this:

  • Rebase to current master
  • Rephrasing to address your feedback
  • Adding deprecation information in logic and doc

I also rephased the description of the directory scan method again to make the point on the recursive expansion clearer, including a reference to g:vimtex_include_indicators.

When it comes to the overview of methods, the essence of method 6 is that directories are scanned to find a suitable main file. In my opinion, the name of the method should therefore reflect this aspect. When we now describe details when a candidate tex file qualifies as a main file, the aspect of parsing it and recursively expanding it through included tex files becomes relevant. But this is a downstream aspect. And it is an aspect that is true for method 1-5 as well, namely checking whether a candidate tex file is a suitable main file for the current file. What distinguishes method 6 from method 1-5 is that a search for a main file is performed, i.e., directories are scanned for such a file.

@shuber2
Copy link
Contributor Author

shuber2 commented Nov 6, 2022

A minor rephrasing and a minor spelling fix added.

Copy link
Owner

@lervag lervag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this is going in a good direction that should help make things clearer! I much appreciate your efforts, and I hope you don't find my feedback too nitpicky.

@@ -237,7 +237,7 @@ function! s:get_main() abort " {{{1
endif

" Search for main file recursively through include specifiers
if !get(g:, 'vimtex_disable_recursive_main_file_detection', 0)
if !get(g:, 'vimtex_disable_directory_scan_main_file_detection', 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually considering if we should instead just remove this option alltogether. I don't think anyone uses it. If someone complained, it would be a useful feedback in itself, and I could revert that specific change and use the name you suggest here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One would like to disable it for performance reasons. The feedback on #2558 seems that suggest that this is generally not an issue, but it is hard to estimate for all actual or potential users.
I will implement the removal as a dedicated commit, so it can be cleanly reverted.

@@ -394,7 +394,7 @@ function! s:get_main_recurse(...) abort " {{{1
let l:re_filter1 = fnamemodify(l:file, ':t:r')
let l:re_filter2 = g:vimtex#re#tex_input . '\s*\f*' . l:re_filter1

" Search through candidates found recursively upwards in the directory tree
" Search through candidates found upwards in the directory tree
let l:results = []
for l:cand in s:findfiles_recursive('*.tex', fnamemodify(l:file, ':p:h'))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should rename s:findfiles_recursive here? And possibly the s:get_main_recurse as well? It seems to be in line with your suggestions here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, perhaps the s:get_main_recurse is ok, since it is used recursively. But s:findfiles_recursive could perhaps be better named as s:findfiles_directory_scan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had the same thoughts. But I think this should be a separate commit to make debugging with git bisect easier later. I will work on that!

doc/vimtex.txt Outdated
There are several alternative methods for specifying the main file that can be
more flexible and are relevant for certain work flows and use cases. These
methods all require some explicit declaration of the main file and are
therefore tried prior the directory scan.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prior to the?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

doc/vimtex.txt Outdated
search detects the main LaTeX file by searching for a file in the current
and parent directories that
Directory scan~
If none of the above methods gives an appropriate candidate for a main file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • gives -> give
  • "for a main file that directly or indirectly includes the present file"

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, perhaps simply: "If none of the above methods yield an appropriate main file, then a search ..."?

Copy link
Contributor Author

@shuber2 shuber2 Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "gives" is ok because the indivual, single methods are meant; it can be read as "none of the [individual] above mehtods gives". It would need to be "give" if phrased as "If the above methods give no appropriate…".

By the way, it is "If x then y", not "If x, then y". I saw the comma somewhere else arleady in the docs I think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "gives" is ok because the indivual, single methods are meant; it can be read as "none of the [individual] above mehtods gives". It would need to be "give" if phrased as "If the above methods give no appropriate…".

Ok!

By the way, it is "If x then y", not "If x, then y". I saw the comma somewhere else arleady in the docs I think.

This is an example of a conditional subordinate conjunction, and I think you need the comma. I found a couple of semi-good references in a quick search:

doc/vimtex.txt Outdated
3. contains `\begin{document}` in its parsed content.
To test whether a candidate tex file qualifies as a main file the following
happens: First, the candidate tex file is parsed and recursively expanded by
all tex files included. Then it is checked whether all of the three
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the three "following" requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, makes sense.

Note that no recursive directory descents are performed to find a main file.
That is, if the current file is `./B/chapter.tex` then `./A/main.tex` will not
be found as the main file, because the descent to subdirectory `./A/` is not
performed.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: directory descent is when we go into subdirectories, right? And directory ascent goes towards the root?

Copy link
Contributor Author

@shuber2 shuber2 Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ascent resp. descent in the directory tree, and (rooted) trees are typically drawn from the root downwards.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's what confuses me. A tree is naturally pointed upwards, but in these cases they are used downwards. 🤷🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "naturally" you mean biological trees? Yes. In computer science, however, trees are drawn with the root at the top, see https://en.wikipedia.org/wiki/Tree_(data_structure)

Or consider the tree shell command or file browsers.

doc/vimtex.txt Outdated
performed.

In cases where the directory scan fails, one may instead rely on the TeX
root directive as an alternative.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should just refer to any of the methods 1-5, instead of only the tex root alternative?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is true, well spotted.

doc/vimtex.txt Outdated

Note: In rare cases, such as if there are _very_ many tex files in the
directory tree, this method may be slow. One may therefore disable it
through the option |g:vimtex_disable_recursive_main_file_detection|.
by the option |g:vimtex_disable_directory_scan_main_file_detection|.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this note and the option, as discussed earlier.

Copy link
Contributor Author

@shuber2 shuber2 Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above. I will do that in a separate commit, so it can be atomically reverted.

doc/vimtex.txt Outdated
In rare cases, the directory scan method of finding the main file in multi
file projects may be slow. This might happen for instance when there are
_very_ many tex files in the directories scanned. In such cases, one may
disable the directory scan method by setting this variable to a nonzero
value.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See earlier comments.

doc/vimtex.txt Outdated
2022-11-05: Better main file detection algorithm~
The detection whether a file is a main file has been improved. In course of
this *g:vimtex_disable_recursive_main_file_detection* has been deprecated in
favor of |g:vimtex_disable_directory_scan_main_file_detection|.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the option, it is still useful to give such a notice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. An the removal commit would rephrase it accordingly.

@shuber2
Copy link
Contributor Author

shuber2 commented Nov 6, 2022

@lervag All good comments, thanks! And I sympathize with "nitpicking". ;)

The method 6 of finding the main file is based on a directory scan which
is described as "recursive" scan. However, while a recursive scan
suggests a (recursive) directory descent, the opposite is true: the
unique ascending path of parent directories is scanned.

This is fixed in the following steps:

  1. The method is renamed to "directory scan method".
  2. The method description is adapted to reflect this behavior more
     clearly. In particular, it is explicitly mentioned that no
     recursive directory descent is performed.
  3. The option to disable this method is renamed to
     g:vimtex_disable_directory_scan_main_file_detection
  4. Some vimscript comments are fixed that actually mention an upwards
     recursion in the directory tree.

As a side effect, the overall description of the directory scan method
is reworked.

As a further side effect, the name of this method is more independent of
the algorithmic mechanism, but rather reflects the policy, cf. "policy
versus mechanism" paradigm
The static function s:findfiles_recursive(expr, path) in state.vim is
actually not recursive, but iterates from path upwards in the directory
tree. Furthermore, it is an extended version of globpath() with
(basically) the same signature. Rename it to s:globpathupwards() to
reflect this.
Performance evaluation for the work on PR lervag#2558 gave evidence that
disabling the directory scan method for the main file detection due to
performance concerns appears to be unjustified. Remove this option.

Note that recently g:vimtex_disable_recursive_main_file_detection has
been renamed to g:vimtex_disable_directory_scan_main_file_detection.
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Thanks! I'm glad you don't mind me being pedantic. :)

Looking forward to seeing an updated PR!

@shuber2
Copy link
Contributor Author

shuber2 commented Nov 6, 2022

@lervag There we go, let's give it another try. I have split the commits up into logical, independent blocks for their own fate. In particular the commit to remove the disable-method-6 option can be easily reverted by itself.

lervag added a commit that referenced this pull request Nov 6, 2022
lervag added a commit that referenced this pull request Nov 6, 2022
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Thanks! I've merged this now after making a few minor changes. Please feel free to let me know if you disagree with them, specifically this commit: af05c7b.

@lervag lervag closed this Nov 6, 2022
@lervag
Copy link
Owner

lervag commented Nov 6, 2022

Oh, and by the way: I very much appreciate this contribution. Documentation is important and hard! And this is actually a very important part of the docs. I hope and believe your contribution here may help make this stuff clearer to both new and existing users in the future, and as such, I think it is a very valuable contribution!

@shuber2
Copy link
Contributor Author

shuber2 commented Nov 6, 2022

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants