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

Improve syntax detection #2524

Merged
merged 3 commits into from
Feb 19, 2025

Conversation

acuteenvy
Copy link
Contributor

Currently, gitui prioritizes file extensions for syntax detection. When a file lacks an extension (e.g. Makefile), or the extension isn't tied to a specific format (e.g. .lock), it disables syntax highlighting.

This PR changes the syntax detecton method to the entire filename and the first line of the file using find_syntax_for_file().

I followed the checklist:

  • I added unittests
  • I ran make check without errors
  • I tested the overall application
  • I added an appropriate item to the changelog

Screenshots of highlighting Cargo.lock and Makefile from this repository:

Before

old1
old2

After

new1
new2

Currently, gitui prioritizes file extensions for syntax detection.
When a file lacks an extension (e.g. Makefile), or the extension
isn't tied to a specific format (e.g. .lock), it disables syntax
highlighting. Gitui will now try to detect the syntax from the entire
filename and the first line of the file using find_syntax_for_file().
@extrawurst extrawurst added this to the v0.28 milestone Feb 19, 2025
@extrawurst
Copy link
Collaborator

This is really cool! Thanks for the contribution!

@extrawurst extrawurst merged commit 338dc2f into gitui-org:master Feb 19, 2025
21 checks passed
@acuteenvy acuteenvy deleted the better-syntax-detection branch February 19, 2025 20:25
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