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

Cannot set --map-syntax .resource:.robot #1386

Closed
stdedos opened this issue Nov 16, 2020 · 10 comments · Fixed by #1504
Closed

Cannot set --map-syntax .resource:.robot #1386

stdedos opened this issue Nov 16, 2020 · 10 comments · Fixed by #1504
Labels
documentation help wanted Extra attention is needed
Milestone

Comments

@stdedos
Copy link

stdedos commented Nov 16, 2020

What version of bat are you using?
[paste the output of bat --version here]

Describe the bug you encountered:
While .robot syntax highlighting is supported (#343, regardless of what #1213 is saying), it seems that .resource files are not included.

So I am trying to do that manually for myself. None of:

  • --map-syntax .resource:robot
  • --map-syntax .resource:.robot
  • --map-syntax .resource:Robot Framework syntax highlighting (bat -L)
  • --map-syntax .resource:"Robot Framework syntax highlighting" (bat -L)
    works.

What did you expect to happen instead?

  • --map-syntax .resource:.robot works
  • --map-syntax .resource:Robot Framework syntax highlighting quoted-or-not works (bat -L)

Or specify at the beginning/end of bat -L how is it supposed to be done and/or an example (feel free to use this one; I feel that you may not want to touch your git-submoduled repo).

Also, use your own machinery to page bat -L: It's already too big to be displayed in one screenful.

How did you install bat?

github-latest deprecated script


[paste the output of info.sh here]

@stdedos stdedos added the bug Something isn't working label Nov 16, 2020
@sharkdp
Copy link
Owner

sharkdp commented Nov 23, 2020

Thank you for reporting this. The Robot syntax file apparently has a trailing dot (.) in its name:

name: Robot Framework syntax highlighting.
file_extensions:
  - robot

None of the other syntaxes have this. So the correct way would be:

--map-syntax .resource:"Robot Framework syntax highlighting."

In 51463a4, I have changed the name to "Robot Framework", so in the future, it would be:

--map-syntax .resource:"Robot Framework"

If .resource is a standard name, we should also consider adding it to the syntax file.

Or specify at the beginning/end of bat -L how is it supposed to be done and/or an example (feel free to use this one; I feel that you may not want to touch your git-submoduled repo).

I think it could be explained better in the help text for --map-syntax. I used "Git Ignore" as an example for a syntax with a space in the name, but I think we should emphasize, that you need to map to the name of the syntax.

Also, use your own machinery to page bat -L: It's already too big to be displayed in one screenful.

Great idea! 👍 This should be tracked in a separate ticket.

Tasks:

  • Change Robot syntax name
  • Add .resource as a standard file name (to the upstream syntax repo)
  • Consider asking the upstream maintainer to change the syntax name ("syntax highlighting." seems superfluous)
  • Improve --map-syntax documentation (see also: README section)

@sharkdp
Copy link
Owner

sharkdp commented Nov 23, 2020

regardless of what #1213 is saying

this issue is about syntax highlighting TESTS, not general support for a language

@sharkdp sharkdp removed the bug Something isn't working label Nov 23, 2020
@stdedos
Copy link
Author

stdedos commented Nov 23, 2020

None of the other syntaxes have this. So the correct way would be:

--map-syntax .resource:"Robot Framework syntax highlighting."

FYI as of bat 0.16.0, still not working:

--map-syntax .resource:"Robot Framework syntax highlighting."

If .resource is a standard name, we should also consider adding it to the syntax file.

https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#supported-file-formats:~:text=Resource%20files%20can%20use%20the%20.robot,the%20dedicated%20.resource%20extension%20is%20recommended.

Resource files can use the .robot extension as well, but using the dedicated .resource extension is recommended.

Or specify at the beginning/end of bat -L how is it supposed to be done and/or an example (feel free to use this one; I feel that you may not want to touch your git-submoduled repo).

I think it could be explained better in the help text for --map-syntax. I used "Git Ignore" as an example for a syntax with a space in the name, but I think we should emphasize, that you need to map to the name of the syntax.

That would be a good place too! However, from my use perspective: I will only use bat -L to verify whether a language is supported, and then "I'll use it somehow"; be it -Llang or --map-syntax.

It's not that far fetched for bat -L to have "what to do with this information next" text.

Also, use your own machinery to page bat -L: It's already too big to be displayed in one screenful.

Great idea! 👍 This should be tracked in a separate ticket.

#1394

@sharkdp
Copy link
Owner

sharkdp commented Nov 23, 2020

FYI as of bat 0.16.0, still not working:

--map-syntax .resource:"Robot Framework syntax highlighting."

Works for me with bat 0.17:

image

That would be a good place too! However, from my use perspective: I will only use bat -L to verify whether a language is supported, and then "I'll use it somehow"; be it -Llang or --map-syntax.

It's not that far fetched for bat -L to have "what to do with this information next" text.

Sounds good 👍

@stdedos
Copy link
Author

stdedos commented Dec 1, 2020

I am sorry to make your life so complicated... but I don't see anything:

u@h:~/robot$ bat res/host/network.resource
... (more shown in less)
u@h:~/robot$ bat res/host/network.resource --map-syntax resource:"Robot Framework"
... (more shown in less)
u@h:~/robot$ cat  ~/.config/bat/config 
# Set the theme to "TwoDark"
--theme=OneHalfDark

# Show line numbers, Git modifications, file header and grid
--style="numbers,changes,header,grid"
--style="snip"

# Use italic text on the terminal
--italic-text=always

# Use "gitignore" highlighting for ".ignore" files
--map-syntax .ignore:.gitignore
--map-syntax .resource:"Robot Framework"

--pager="~/.installs/smartless/smartless -H"
u@h:~/robot$ bat --version
bat 0.17.1

Did you, by accident (or my miscommunication), create a weird rule?
Because bat .resource works, but no other filename e.g. bat a.resource ...

@sharkdp
Copy link
Owner

sharkdp commented Dec 1, 2020

My mistake. I thought the files are named .resource. If you want to highlight *.resource files, just add:

--map-syntax '*.resource:Robot Framework'

The left-hand side of the colon is a glob pattern.

@stdedos
Copy link
Author

stdedos commented Dec 1, 2020

Oh, I see ... Then, why is "robot" highlighting *.robot files?

It works btw, just add that fix on master 😀

@sharkdp
Copy link
Owner

sharkdp commented Dec 1, 2020

Oh, I see ... Then, why is "robot" highlighting *.robot files?

You mean.. in the bat --list-languages output? That is confusing, yes. Basically, there are two sources of file name patterns:

  • The Sublime syntax itself
  • bats additional glob patterns

The Sublime syntaxes have a very limited pattern format. If they specify "robot", that could either mean files names "robot" OR files with extension "robot". bat highlights files robot and a.robot in the same way because that's how the Sublime syntaxes patterns are intended to be used.

But that's not ideal. For Makefiles, there is a "Makefile" pattern. But we don't really want to highlight a.Makefile files.

bat patterns add two things: they are glob patterns which solve the problem above (but need to specify *.robot or *.resource). Also, they can be matched on the whole path. This allows us to add special pattenrs for /etc/passwd, for example (but not for other passwd files).

This should really be documented somewhere. Ideally, in the bat -L output. Any suggestions or help is welcome.

@sharkdp sharkdp added the help wanted Extra attention is needed label Dec 1, 2020
@stdedos
Copy link
Author

stdedos commented Dec 1, 2020

I think that's "too verbose" for the bat -L output (unless it's like 80-180 characters).

Can be added in a man section

@sharkdp
Copy link
Owner

sharkdp commented Feb 28, 2021

This has now been released in bat v0.18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants