aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZane Bitter <zane.bitter@alliedtelesis.co.nz>2010-11-24 04:46:51 +1300
committerCatalin Marinas <catalin.marinas@gmail.com>2010-11-24 16:58:20 +0000
commitcd4aec96b72dda05135696da85b2d6ce7132bcea (patch)
treee80961a78bd19c2451a83d1c27d30cd453092c93
parentfa3f66e9cd4a7e0f019f226c37e4ab377269abc3 (diff)
downloadstgit-cd4aec96b72dda05135696da85b2d6ce7132bcea.tar.gz
contrib/vim: Add vim syntax highlighting for StGit commit messages
Signed-off-by: Zane Bitter <zane.bitter@alliedtelesis.co.nz> Tested-by: Chris Packham <judge.packham@gmail.com> Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
-rw-r--r--contrib/vim/README10
-rw-r--r--contrib/vim/ftdetect/stg.vim44
-rw-r--r--contrib/vim/syntax/stgedit.vim39
-rw-r--r--contrib/vim/syntax/stgmail.vim32
-rw-r--r--contrib/vim/syntax/stgnew.vim32
-rw-r--r--contrib/vim/syntax/stgsquash.vim39
6 files changed, 196 insertions, 0 deletions
diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644
index 0000000..882f6f9
--- /dev/null
+++ b/contrib/vim/README
@@ -0,0 +1,10 @@
+To syntax highlight StGit commit messages in vim:
+
+ * For the current user only:
+ > mkdir -p ~/.vim/ftdetect ~/.vim/syntax
+ > cp syntax/*.vim ~/.vim/syntax/
+ > cp ftdetect/*.vim ~/.vim/ftdetect/
+
+ * For all users:
+ # cp syntax/*.vim /usr/share/vim/site/syntax/
+ # cp ftdetect/*.vim /usr/share/vim/site/ftdetect/
diff --git a/contrib/vim/ftdetect/stg.vim b/contrib/vim/ftdetect/stg.vim
new file mode 100644
index 0000000..abd4d9f
--- /dev/null
+++ b/contrib/vim/ftdetect/stg.vim
@@ -0,0 +1,44 @@
+" Vim filetype detection plugin
+" Language: StGit commit messages
+" Author: Zane Bitter <zane.bitter@alliedtelesis.co.nz>
+
+
+if has("autocmd")
+
+ " Detect 'stg new' files
+ autocmd BufNewFile,BufRead .stgit-new.txt setf stgnew
+ autocmd BufNewFile,BufRead .stgitmsg.txt setf stgnew
+ " Ignore the modeline so we get type 'stgnew' instead of 'diff'
+ autocmd BufNewFile,BufRead .stgitmsg.txt setlocal nomodeline
+
+ " Detect 'stg edit' files
+ autocmd BufNewFile,BufRead .stgit-edit.txt setf stgedit
+ " Use set filetype instead of setfiletype to override detection as patch
+ autocmd BufNewFile,BufRead .stgit-edit.patch setlocal filetype=stgedit
+ autocmd BufNewFile,BufRead .stgit-edit.diff setlocal filetype=stgedit
+ autocmd BufNewFile,BufRead .stgit-failed.patch setlocal filetype=stgedit
+
+ " Detect 'stg squash' files
+ autocmd BufNewFile,BufRead .stgit-squash.txt setf stgsquash
+
+ " Detect 'stg mail' files
+ autocmd BufNewFile,BufRead .stgitmail.txt setf stgmail
+
+
+ " A modeline in a diff belongs to the diffed file, so ignore it
+ autocmd BufNewFile,BufRead .stgit-edit.patch setlocal nomodeline
+ autocmd BufNewFile,BufRead .stgit-edit.diff setlocal nomodeline
+ autocmd BufNewFile,BufRead .stgit-failed.patch setlocal nomodeline
+ autocmd BufNewFile,BufRead .stgitmail.txt setlocal nomodeline
+
+
+ " Set parameters on 'stg new' files to be consistent with the modeline
+ autocmd FileType stgnew setlocal textwidth=75
+ autocmd FileType stgnew setlocal nobackup
+
+ " For other stg files set textwidth the same as 'stg new'
+ autocmd FileType stgedit setlocal textwidth=75
+ autocmd FileType stgmail setlocal textwidth=75
+ autocmd FileType stgsquash setlocal textwidth=75
+
+endif " has("autocmd")
diff --git a/contrib/vim/syntax/stgedit.vim b/contrib/vim/syntax/stgedit.vim
new file mode 100644
index 0000000..9ee4e85
--- /dev/null
+++ b/contrib/vim/syntax/stgedit.vim
@@ -0,0 +1,39 @@
+" Vim syntax file
+" Language: StGit 'stg edit' commit message file
+" Author: Zane Bitter <zane.bitter@alliedtelesis.co.nz>
+
+if exists("b:current_syntax")
+ finish
+endif
+
+
+runtime! syntax/mail.vim
+unlet b:current_syntax
+
+syn include @stgDiff syntax/diff.vim
+
+
+syn case match
+syn sync minlines=50
+
+
+if has("spell")
+ syn spell toplevel
+endif
+
+
+syn match stgeditFrom "\%^From:.*" contains=mailHeader nextgroup=stgeditFirstLine skipempty
+syn match stgeditFirstLine "^.\+" contained nextgroup=stgeditDiffs,stgeditComment,stgeditBlank skipnl
+syn match stgeditSummary "^.\{0,50\}" contained containedin=stgeditFirstLine nextgroup=stgeditOverflow contains=@Spell
+syn match stgeditOverflow ".*" contained contains=@Spell
+syn match stgeditBlank "^.\+" contained contains=@Spell
+syn match stgeditComment "^#.*"
+syn region stgeditDiffs start="^---" end="%$" contains=@stgDiff fold
+syn region stgeditDiff start="^\%(diff --git \)\@=" end="^\%(diff --git \|$\)\@=" contained containedin=stgeditDiffs contains=@stgDiff fold
+
+hi def link stgeditSummary Keyword
+hi def link stgeditComment Comment
+hi def link stgeditBlank Error
+
+
+let b:current_syntax = "stgedit"
diff --git a/contrib/vim/syntax/stgmail.vim b/contrib/vim/syntax/stgmail.vim
new file mode 100644
index 0000000..dbd962c
--- /dev/null
+++ b/contrib/vim/syntax/stgmail.vim
@@ -0,0 +1,32 @@
+" Vim syntax file
+" Language: StGit 'stg mail' file
+" Author: Zane Bitter <zane.bitter@alliedtelesis.co.nz>
+
+if exists("b:current_syntax")
+ finish
+endif
+
+
+runtime! syntax/mail.vim
+unlet b:current_syntax
+
+syn include @stgDiff syntax/diff.vim
+
+
+syn case match
+syn sync minlines=50
+
+
+if has("spell")
+ syn spell toplevel
+endif
+
+
+syn match stgmailComment "^#.*"
+syn region stgmailDiffs start="^---" end="%$" contains=@stgDiff fold
+syn region stgmailDiff start="^\%(diff --git \)\@=" end="^\%(diff --git \|$\)\@=" contained containedin=stgmailDiffs contains=@stgDiff fold
+
+hi def link stgmailComment Comment
+
+
+let b:current_syntax = "stgmail"
diff --git a/contrib/vim/syntax/stgnew.vim b/contrib/vim/syntax/stgnew.vim
new file mode 100644
index 0000000..d01226d
--- /dev/null
+++ b/contrib/vim/syntax/stgnew.vim
@@ -0,0 +1,32 @@
+" Vim syntax file
+" Language: StGit 'stg new' commit message file
+" Author: Zane Bitter <zane.bitter@alliedtelesis.co.nz>
+
+if exists("b:current_syntax")
+ finish
+endif
+
+
+syn case match
+syn sync minlines=50
+
+
+if has("spell")
+ syn spell toplevel
+endif
+
+
+syn match stgnewFirstLine "\%^.*" nextgroup=stgnewSTG,stgnewComment,stgnewBlank skipnl
+syn match stgnewSummary "^.\{0,50\}" contained containedin=stgnewFirstLine nextgroup=stgnewOverflow contains=@Spell
+syn match stgnewOverflow ".*" contained contains=@Spell
+syn match stgnewBlank "^.\+" contained contains=@Spell
+syn match stgnewSTG "^STG:.*"
+syn match stgnewComment "^#.*"
+
+hi def link stgnewSummary Keyword
+hi def link stgnewComment Comment
+hi def link stgnewSTG Comment
+hi def link stgnewBlank Error
+
+
+let b:current_syntax = "stgnew"
diff --git a/contrib/vim/syntax/stgsquash.vim b/contrib/vim/syntax/stgsquash.vim
new file mode 100644
index 0000000..e2dbeda
--- /dev/null
+++ b/contrib/vim/syntax/stgsquash.vim
@@ -0,0 +1,39 @@
+" Vim syntax file
+" Language: StGit 'stg squash' commit message file
+" Author: Zane Bitter <zane.bitter@alliedtelesis.co.nz>
+
+if exists("b:current_syntax")
+ finish
+endif
+
+
+syn case match
+syn sync minlines=50
+
+
+if has("spell")
+ syn spell toplevel
+endif
+
+
+syn match stgsqFirstLine "\%^.*" nextgroup=stgsqComment,stgsqContext,stgsqBlank skipnl
+syn match stgsqSummary "^.\{0,50\}" contained containedin=stgsqFirstLine nextgroup=stgsqOverflow contains=@Spell
+syn match stgsqOverflow ".*" contained contains=@Spell
+syn match stgsqBlank "^.\+" contained contains=@Spell
+syn match stgsqSeparator "-\+$" contained
+syn region stgsqPatch start="^\(.\{66\}-\{4\}$\)\@=" end="\(^.\{66\}-\{4\}$\)\@=" contained containedin=stgsqContext contains=@Spell fold
+syn match stgsqNextPatch "^.\{66\}-\{4\}$" contained containedin=stgsqPatch contains=stgsqPatchName
+syn match stgsqPatchName "^.\{-\}\(-*$\)\@=" contained containedin=stgsqNextPatch nextgroup=stgsqSeparator
+syn region stgsqContext start="^---" end="%$" contains=@Spell fold
+syn match stgsqComment "^#.*"
+
+hi def link stgsqSummary Keyword
+hi def link stgsqComment Comment
+hi def link stgsqBlank Error
+hi def link stgsqContext Comment
+hi def link stgsqPatch Constant
+hi def link stgsqPatchName Identifier
+hi def link stgsqSeparator Comment
+
+
+let b:current_syntax = "stgsquash"