Skip to content

Commit

Permalink
Add gitstash syntax highlighter, for git stash list -p format
Browse files Browse the repository at this point in the history
See the added comments for more details.

Quick usage example:

    git stash list -p | dte -c 'set filetype gitstash'

...or alternatively, from inside the editor:

    open -t; set filetype gitstash; pipe-from git stash list -p
  • Loading branch information
craigbarnes committed Dec 21, 2024
1 parent fc7389e commit 03900b6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions config/rc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ option python indent-regex ':[ \t]*(#.*)?$'
option sh indent-regex '(^|;)[ \t]*(do|else|then) *$'
option html,xml indent-regex '(^[ \t]*>|<[A-Za-z]>|<[^/][^<]*[^/]>)[ \t]*$'

# Don't highlight whitespace errors in diff and mail files
option diff,mail ws-error 0
# Don't highlight whitespace errors in diff/gitstash/mail files
option diff,gitstash,mail ws-error 0

# Aliases for renamed/removed commands (for backwards compatibility)
alias filter 'exec -s -i buffer -o buffer -e errmsg'
Expand Down
6 changes: 3 additions & 3 deletions config/syntax/diff
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require diff

syntax diff

state start
# The `.diff` sub-syntax has no `END` destination states, so the return
# state here just uses a dummy value (`this`)
# Jump into the ".diff" sub-syntax and transition straight back to it,
# whenever it returns here (see also: the comment in syntax/inc/diff)
state subsyn-loop
noeat .diff:this
7 changes: 6 additions & 1 deletion config/syntax/gitcommit
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ state maybe-scissors comment

state scissors comment
char ' -' this
char "\n" .diff:this
char "\n" subsyn-loop
noeat comment

# Jump into the ".diff" sub-syntax and transition straight back to it,
# whenever it returns here (see also: the comment in syntax/inc/diff)
state subsyn-loop
noeat .diff:this

state comment
char "\n" start
eat this
Expand Down
22 changes: 22 additions & 0 deletions config/syntax/gitstash
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require diff

# This is very similar to the `diff` syntax, but also allows
# highlighting lines like e.g. "stash@{0}: WIP on master: ...".
# Usage example: git stash list -p | dte -c 'set filetype gitstash'

syntax gitstash

state start
char s maybe-stashline
noeat .diff:this

state maybe-stashline stashline
str 'tash@{' stashline
recolor text 1
noeat .diff:start

state stashline
char "\n" start
eat this

default string stashline
14 changes: 10 additions & 4 deletions config/syntax/inc/diff
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ state headers diff-header
str '+++ ' header
str '@@ ' chunk
char # comment
char "\n" this
noeat text

# Note that all "END" destinations in this sub-syntax are only for the
# benefit of the "gitstash" syntax and could otherwise just be replaced
# with "headers". This sub-syntax also used by the "diff" and "gitcommit"
# syntaxes.

state header diff-header
char "\n" headers
char "\n" END
eat this

state chunk diff-chunk
Expand All @@ -23,7 +29,7 @@ state diff code
char + added
char - removed
str '@@ ' chunk
noeat headers
noeat END

state context diff-context
char "\n" diff
Expand All @@ -38,9 +44,9 @@ state removed diff-removed
eat this

state comment
char "\n" headers
char "\n" END
eat this

state text
char "\n" headers
char "\n" END
eat this
2 changes: 1 addition & 1 deletion mk/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VERSION = $(shell mk/version.sh 1.11.1)

BUILTIN_SYNTAX_FILES ?= \
awk c coccinelle config css ctags d diff docker dte gcode gitblame \
gitcommit gitignore gitrebase go gomod html haskell ini java \
gitcommit gitignore gitrebase gitstash go gomod html haskell ini java \
javascript json lisp lua mail make markdown meson nftables nginx \
ninja php python robotstxt roff ruby scheme sed sh sql tex texmfcnf \
tmux vala weechatlog xml xresources zig inc/c-comment inc/c-uchar \
Expand Down

0 comments on commit 03900b6

Please sign in to comment.