-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Rd (R Documentation)
file is not detected correctly
#1357
Comments
The official Sublime syntax for R Documentation only specifies And yet, Sublime itself will detect a file with a In the same vein, Sublime will detect @sharkdp @keith-hall, I think this should be fixed. Official and unofficial A took a bit of time to experiment with how Sublime deals with conflicting extensions, and this is what I determined:
I'm not sure if first-line detection takes place anywhere before, during, or after that process. More experimentation will be necessary to figure that part out. Related: |
Yes, I completely agree. Sounds like the best place to fix this is in syntect, then. It's a shame that Sublime doesn't allow explicitly setting whether an extension should be case sensitive or not - perhaps it would make sense if an all lowercase definition in
It's explicit. Syntect behaves the same. trishume/syntect#217 |
There is a bit difference for First, the definition of the an R documentation file exactly matches both <?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/x-r-doc">
<!--Created automatically by update-mime-database. DO NOT EDIT!-->
<sub-class-of type="text/plain"/>
<comment>R Documentation File</comment>
<glob pattern="*.Rd"/>
<glob pattern="*.rd"/>
</mime-type> But for <?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/x-makefile">
<!--Created automatically by update-mime-database. DO NOT EDIT!-->
<comment>Makefile</comment>
......
<sub-class-of type="text/plain"/>
<glob pattern="makefile"/>
<glob pattern="GNUmakefile"/>
<glob pattern="*.mk"/>
<glob pattern="*.mak"/>
<glob weight="10" pattern="Makefile.*"/>
</mime-type> BUT, as of Shared MIME-info Database specification 0.21,
In my opinion the only correct and safe way to infer the type of a file is via it's mime info. This could be done via xdg-mime or xdgmime for example. |
So we would need to maintain a mapping of mime types to Edit: plus I don't know offhand how portable it would be - does Windows have decent mime type reporting support? Somehow I think not, but could be wrong - maybe through an additional dependency only...? |
As mentioned in #807 (reference above), there are cases like this:
Apparently, <?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/x-objcsrc">
…
<sub-class-of type="text/x-csrc"/>
<glob pattern="*.m"/>
</mime-type> without any case-sensitive attribute. |
@sharkdp
Also a good thing about querying system mime database is, the system administrator can add/modify it. Therefore, I think |
Keeping a mapping inside In normal case when If it cannot determine the type and if mime database is available, it can then rely on the mapping and mime query to determine the type. Since the database is mutable,
|
I'm skeptical about the whole idea of adding syntax detection via MIME querying directly to bat. While it would be useful for accuracy, I think it's important that we keep bat's syntax detection behavior similar to Sublime's. We're piggybacking off the Sublime ecosystem for syntax highlighting, and intentionally diverging from it isn't going to do us any favors in compatibility. Additionally, it's going to be an issue from maintenance standpoint. Using operating system APIs to query the MIME type of a file is going to make bat's behavior much more dependent on system configuration. For example, what if a user files a bug report about incorrect syntax detection because their system has a bad extension to MIME mapping? Finally, adding on to @keith-hall's compatibility concerns: How would we handle a MIME querying API that only accepts files? That wouldn't be possible with pipes unless we buffer the data and save it somewhere, which goes against the core principle that bat should be unbuffered. |
Unfortunately, this wouldn't be enough. I don't know about Linux, but part of the MIME type detection process on MacOS involves reading the file contents and attempting to match them with rules relating to that specific type. We would need valid files to query the MIME type properly. |
Ok, so what should be done here? Report (and fix) the issue in |
Yes, I believe so. |
What version of
bat
are you using?bat 0.16.0
Describe the bug you encountered:
When use
bat
on a.Rd
file, it cannot correctly render it as an R documentation file.I have to manually add
--language=rd
.Describe what you expected to happen?
This should be automatically detected.
The output of
bat -L
showsAnd I've verified that when the extension becomes
rd
instead ofRd
, it'd be correctlyrecognised by `bat.
Even though both
Rd
andrd
file would be recognised astext/x-r-doc
byxdg-mime
,the extension of R documentation files is
Rd
in the officialrepository of
R
. For example: https://svn.r-project.org/R/trunk/doc/NEWS.RdHow did you install
bat
?cargo install bat
[paste the output of
info.sh
here]system
$ uname -srm
Linux 5.9.1-992.native x86_64
bat
$ bat --version
bat 0.16.0
$ env
PAGER=less
$ bat --list-languages
Found custom syntax set.
$ bat --list-themes
Found custom theme set.
bat_config
$ cat /home/lucius/.config/bat/config
bat_wrapper
No wrapper script for 'bat'.
bat_wrapper_function
No wrapper function for 'bat'.
No wrapper function for 'cat'.
tool
$ less --version
less 551 (POSIX regular expressions)
The text was updated successfully, but these errors were encountered: