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

🚀 Provide a map-syntax feature, like bat does #326

Open
ahmedelgabri opened this issue Sep 18, 2020 · 18 comments
Open

🚀 Provide a map-syntax feature, like bat does #326

ahmedelgabri opened this issue Sep 18, 2020 · 18 comments

Comments

@ahmedelgabri
Copy link

As far as I understand, delta uses bat for its syntax highlighting, etc… And bat supports having a config file (bat --config-file /path/to/file or by setting BAT_CONFIG_PATH), I'm interested in the second case BAT_CONFIG_PATH.

In this file you can have some file mapping like this for example:

--map-syntax '.gitconfig.local:Git Config'
--map-syntax '.zsh*:Bourne Again Shell (bash)'
--map-syntax '.vimrc.local:VimL'
--map-syntax 'vimrc:VimL'

But it seems like this is not being picked up by the bat version used by delta

@dandavison
Copy link
Owner

Hi @ahmedelgabri, thanks for this, but delta doesn't use bat for syntax highlighting. So, currently at least, delta doesn't look at the bat config file. So, perhaps this is best turned into a feature request for map-syntax functionality in delta? I'll have to think about whether we should go down the path of honoring the bat config map-syntax entries. Although in practice I know one would almost always want the same mappings in both, it may not make sense to link the two applications like that -- what do you think? There is one point of shared configuration at the moment -- delta honors the BAT_THEME env var.

@ahmedelgabri
Copy link
Author

If delta honors BAT_THEME already why not honor the config too. The config can actually contain the theme too.

@ahmedelgabri
Copy link
Author

Unless you plan not to use bat, I don’t see why you shouldn’t pick up it’s config. Yes it will couple the projects together but bat can be used as a library already so it’s not like you are going to be tied to an external app. It can be a direct dependency of the project which you can swap later if you want.

@nickspoons
Copy link

I found this confusing too, when trying to work out how to map my ~/.vim/vimrc syntax to VimL, which worked as expected for bat ~/.vim/vimrc but not git diff ~/.vim/vimrc.

+1 for some form of map-syntax for delta. I don't understand where delta is using bat and where it is not, as a new user it seems like the bat config file would have been used here. Clearly not, but if parsing the bat config file is an option, that might make things "just work" for a lot of users. For 2 of us, at least 😄

@SuperCuber
Copy link

I don't understand where delta is using bat and where it is not, as a new user it seems like the bat config file would have been used here

I agree with this, the readme mentions over and over how delta supports everything bat does so I just assumed that it uses bat as a dependency and the config would work. In particular I'm also interested in having the equivalent of --map-syntax 'vimrc:VimL'

@dandavison
Copy link
Owner

Thanks for the design input here @ahmedelgabri @nickspoons @SuperCuber. On the one hand the way the documentation has mentioned bat has caused some confusion, and there is probably no need for delta to support BAT_PAGER for example, seeing as we have DELTA_PAGER and PAGER. But on the other hand Delta does absolutely make use of the syntax and theme assets from the bat project, so perhaps that's an area where they should be coupled at the level of configuration files?

cc @MarcoIeni @Kr1ss-XD any thoughts here?

ref #116 "Make use of bat as a library"

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Nov 6, 2020

On the one hand I think it would be nice if delta could parse the bat configuration file and make use of the settings in it, to have a single place where syntax- and color-schemes would be defined.

Nonetheless, I do find it really useful that I can define different settings for

a) standalone use of bat, and
b) syntax highlighting with delta.

Hence my suggestion would be to either

  • use bat's config file, but only as a default for the delta.<xyz> options in gitconfig that we currently have, so that its options can be overridden, or
  • introduce an additional option like delta.batconfig or similar, so one can have a "delta-specific" bat configuration in addition to the default one for general use of bat.

If it comes to one of these two alternatives, I'd prefer the first one. It would cause less of a change compared to the current status.

@dandavison
Copy link
Owner

dandavison commented Nov 6, 2020

I definitely agree we need to make map-syntax functionality available for delta: the situation with the vim config files sounds really annoying :/

The syntax of the bat config file is simply strings representing bat command line options. So one option would be to undertake to read that but only respect certain entries such as --map-syntax. However, delta and bat have similar and partially overlapping sets of command line options. Delta can't honor all the entries in the bat config file and I worry that partial honoring of the bat config file will be the source of even more confusion. @ahmedelgabri what do you think?

I'm honestly not sure yet what's best here, so do keep the opinions coming! What we're talking about is configuring the usage of the binary sublime syntax and theme definitions that both delta and bat use. Other than --map-syntax and BAT_THEME (aka --syntax-theme in delta and --theme in bat) are there any other points of configuration that we should be considering in this conversation?

Nonetheless, I do find it really useful that I can define different settings

@Kr1ss-XD I'm guessing you wouldn't want to map syntax differently in bat vs delta, right?

@Kr1ss-XD
Copy link
Contributor

Kr1ss-XD commented Nov 6, 2020

I'm guessing you wouldn't want to map syntax differently in bat vs delta, right?

No, I only find different color themes convenient. Sorry if I wasn't precise.

@dandavison
Copy link
Owner

cc @Ryuta69 who's also been thinking about ways to make command line configuration and on-the-fly config changes more convenient.

No, I only find different color themes convenient. Sorry if I wasn't precise.

Not at all; very helpful.

@ahmedelgabri
Copy link
Author

The syntax of the bat config file is simply strings representing bat command line options. So one option would be to undertake to read that but only respect certain entries such as --map-syntax. However, delta and bat have similar and partially overlapping sets of command line options. Delta can't honor all the entries in the bat config file and I worry that partial honoring of the bat config file will be the source of even more confusion. @ahmedelgabri what do you think?

For me, what I only want from delta to respect from bat is only the syntax mapping, the rest doesn't make sense to support (at least for me) I don't want to configure two places/tools to do the same thing if one of them consumes the other already.

@MarcoIeni
Copy link
Contributor

cc @MarcoIeni @Kr1ss-XD any thoughts here?

I am not an heavy delta user, so I don't have any particular opinion about this, but I will keep this discussion in mind while trying to solve #116

@dandavison dandavison changed the title Not picking up bat configuration file Provide a map-syntax feature, like bat does Dec 2, 2020
dandavison added a commit that referenced this issue Dec 8, 2020
Ref #326
@dandavison dandavison changed the title Provide a map-syntax feature, like bat does 🚀 Provide a map-syntax feature, like bat does Dec 27, 2020
@bamonroe
Copy link

bamonroe commented Feb 1, 2021

I would love to see the --map-syntax feature in delta, but until it gets there, a way to add your syntax mapping is to compile the syntaxes.bin file using bat. I did the following assuming bat was already installed to give files with a Rnw extension Latex syntax highlighting:

# Clone bat to get the syntax files it uses
git clone --recursive https://github.com/sharkdp/bat
# Make the default bat config dir
mkdir -p "$(bat --config-dir)/syntaxes"
# Copy the syntax dir for the language you want to extend
cp -r bat/assets/syntaxes/01_Packages/LaTeX "$(bat --config-dir)/syntaxes/"
# Add the extension you want to add to the list of "file_extensions:" at the top of the file (Rnw for me)
nvim "$(bat --config-dir)/syntaxes/LaTeX/LaTeX.sublime-syntax"
# Build the bat cache
bat cache --build

Now I see "Rnw" under LaTeX when I run delta --list-languages and I get LaTeX syntax highlighting with Rnw files. If you have constantly changing file extensions, much of this could be automated with some shell scripts and clever use of sed. Hope this helps.

@gibfahn
Copy link

gibfahn commented Feb 2, 2021

I'd be fine with different options in delta vs bat, and with copying things from my bat config to my delta config.

Ideally the argument names would be the same so I could just copy the --map-syntax lines into my git config, but it's not the end of the world.

Pulling some options from the bat config seems possible, but would also be confusing if only some options were respected.

@djmattyg007
Copy link

I agree with @gibfahn. I don't care if I have to maintain two separate sets of configuration (I already do), I just want the option to exist in delta so I can make use of it.

@phil-blain
Copy link
Contributor

phil-blain commented Jan 20, 2022

I would also like some way to customize the syntax detection, based on the file extension. For example, I'd want *.ftn90 files to be recognized as "Fortran (Modern)", so I would like to be able to put something to that effect in my .gitconfig .


As an aside, delta would be even more amazing if it could use the diff Git attribute mechanism to choose which language syntax to apply. Meaning, if I already have in my .gitattributes:

*.ftn90    diff=fortran

then delta would recognize those files as Fortran without me having to configure delta itself. One could even think of a further fall back to GitHub's and GitLab's special attributes for syntax highlighting:

@dandavison
Copy link
Owner

dandavison commented Jan 20, 2022

Those sound like good suggestions @phil-blain. In the absence of any actual work on this I just want to point out that it is possible to work around this by

  1. Install bat
  2. Copy the target syntax definition into ~/.config/bat/syntaxes/ with a new name. I.e. something like
 cp bat/assets/syntaxes/02_Extra/Fortran/grammars/FortranModern.sublime-syntax ~/.config/bat/syntaxes/Fortran90.sublime-syntax
  1. Modify the file in ~/.config/bat/syntaxes so that it has the desired file suffix
  2. Run bat cache --build

However. Please note that delta is not compatible with the binary assets produced by the newest version of bat. See #895. So either use an older version of bat < v0.19.0, or use my experimental delta branch: #903

If you have a recent bat version, then this requires delta >= 0.12.1.

@phil-blain
Copy link
Contributor

Thanks a lot for that suggestion, that's really great!

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

No branches or pull requests

10 participants