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 git show highlighting #1735

Open
scop opened this issue Jul 16, 2021 · 3 comments
Open

Improve git show highlighting #1735

scop opened this issue Jul 16, 2021 · 3 comments
Labels
feature-request New feature or request syntax-highlighting upstream-error A bug in an upstream component

Comments

@scop
Copy link
Contributor

scop commented Jul 16, 2021

git show output is currently detected and highlighted as gitlog, which means the diff part is not highlighted. Would be great if both of them would be.

@scop scop added the feature-request New feature or request label Jul 16, 2021
@keith-hall keith-hall added syntax-highlighting upstream-error A bug in an upstream component labels Jul 16, 2021
@keith-hall
Copy link
Collaborator

I have played around with the Git Log syntax definition, and have added support for highlighting diffs - the patch (including the fix for #1632) is:

--- Shipped Packages/Git Formats/Git Log.sublime-syntax	2021-04-02 13:30:54
+++ Packages/Git Formats/Git Log.sublime-syntax	2021-07-16 23:43:48
@@ -13,13 +13,37 @@
   main:
     # 1st header line
     # commit d9d9fb804f5d61c13ba2f8746af33a9f3c609075
-    - match: (?:(commit)\s+(\h{7,}))?\s*\n
-      scope: meta.header.git.commit markup.raw.block.git.log
+    - match: ^(commit)\s+(\h{7,})
       captures:
         1: keyword.other.commit.git.log
         2: constant.other.hash.git.log
-      embed: commit-header
-      escape: (?=^commit\s)
+      push:
+        - meta_scope: meta.header.git.commit markup.raw.block.git.log
+        - match: $\n?
+          scope: meta.header.git.commit markup.raw.block.git.log
+          pop: true
+          embed: commit-header
+          escape: (?=^(?:commit|diff)\s)
+        - match: (\()(HEAD)\s*(->)
+          captures:
+            1: punctuation.section.parens.begin.git.log
+            2: support.type.git.log
+            3: punctuation.separator.mapping.git.log
+          push:
+            - match: \)
+              scope: punctuation.section.parens.end.git.log
+              pop: true
+            - match: \bmaster\b
+              scope: entity.other.branch-name.master.git.log
+            - match: (\w+)(?:(/)(\w+))?
+              scope: entity.other.branch-name.git.log
+            - match: ','
+              scope: punctuation.separator.sequence.git.log
+    - match: '^(?=diff\s)'
+      embed: scope:source.shell.bash
+      escape: $
+    - match: (?=^index\s)
+      set: scope:source.diff
 
   commit-header:
     # All header attributes are mappings of `key: value` format.

and here's an example of how bat renders it with these changes: (it looks better in ST, my color scheme there targets more scopes with colors I guess)

image

I will try to make a PR to the Packages repo with these changes soon ™️

@arcnmx
Copy link

arcnmx commented Sep 19, 2023

The relevant PR to packages was merged quickly, is this still blocked on supporting newer syntax features?

@keith-hall
Copy link
Collaborator

Yeah, we can't straight up bump the submodule version used due to #2358.
But perhaps we can apply individual patches which are compatible. It just seems like a maintenance nightmare to me though.
Perhaps if someone else were to take on the work... ;) #919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request syntax-highlighting upstream-error A bug in an upstream component
Projects
None yet
Development

No branches or pull requests

3 participants