[StGIT PATCH] contrib/vim: Add vim syntax highlighting for StGit commit messages

Subsystems: the rest

STALE3730d

3 messages, 3 authors, 2016-06-15 · open the first message on its own page

[StGIT PATCH] contrib/vim: Add vim syntax highlighting for StGit commit messages

From: Zane Bitter <hidden>
Date: 2016-06-15 22:50:05

---

 contrib/vim/README               |   11 ++++++++++
 contrib/vim/ftdetect/stg.vim     |   44 ++++++++++++++++++++++++++++++++++++++
 contrib/vim/syntax/stgedit.vim   |   40 +++++++++++++++++++++++++++++++++++
 contrib/vim/syntax/stgmail.vim   |   33 +++++++++++++++++++++++++++++
 contrib/vim/syntax/stgnew.vim    |   33 +++++++++++++++++++++++++++++
 contrib/vim/syntax/stgsquash.vim |   40 +++++++++++++++++++++++++++++++++++
 6 files changed, 201 insertions(+), 0 deletions(-)
 create mode 100644 contrib/vim/README
 create mode 100644 contrib/vim/ftdetect/stg.vim
 create mode 100644 contrib/vim/syntax/stgedit.vim
 create mode 100644 contrib/vim/syntax/stgmail.vim
 create mode 100644 contrib/vim/syntax/stgnew.vim
 create mode 100644 contrib/vim/syntax/stgsquash.vim
diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644
index 0000000..4899b6e
--- /dev/null
+++ b/contrib/vim/README
@@ -0,0 +1,11 @@
+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..ef46a8d
--- /dev/null
+++ b/contrib/vim/syntax/stgedit.vim
@@ -0,0 +1,40 @@
+" 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..bd5a77d
--- /dev/null
+++ b/contrib/vim/syntax/stgmail.vim
@@ -0,0 +1,33 @@
+" 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..a794cf5
--- /dev/null
+++ b/contrib/vim/syntax/stgnew.vim
@@ -0,0 +1,33 @@
+" 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..9524963
--- /dev/null
+++ b/contrib/vim/syntax/stgsquash.vim
@@ -0,0 +1,40 @@
+" 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"
+

Re: [StGIT PATCH] contrib/vim: Add vim syntax highlighting for StGit commit messages

From: Chris Packham <hidden>
Date: 2016-06-15 22:50:06

Hi Zane,

On Wed, Nov 24, 2010 at 4:46 AM, Zane Bitter
[off-list ref] wrote:
I'm not sure about how Catalin runs stgit, but in for git having a
Signed-off-by: line is mandatory and usually indicates that the patch
considered ready for inclusion and acts as the "developers certificate
of authenticity" (i.e. it is the developers own work or the developer
has based it on other compatibly licensed code).

A commit message would also be nice but in this case I think it just
does what it says on the tin.

For the reviewers I can add that I've been using Zane's patch for a
while now and it works well for me (although I'm not exactly a vim
guru).
---

 contrib/vim/README               |   11 ++++++++++
 contrib/vim/ftdetect/stg.vim     |   44 ++++++++++++++++++++++++++++++++++++++
 contrib/vim/syntax/stgedit.vim   |   40 +++++++++++++++++++++++++++++++++++
 contrib/vim/syntax/stgmail.vim   |   33 +++++++++++++++++++++++++++++
 contrib/vim/syntax/stgnew.vim    |   33 +++++++++++++++++++++++++++++
 contrib/vim/syntax/stgsquash.vim |   40 +++++++++++++++++++++++++++++++++++
 6 files changed, 201 insertions(+), 0 deletions(-)
 create mode 100644 contrib/vim/README
 create mode 100644 contrib/vim/ftdetect/stg.vim
 create mode 100644 contrib/vim/syntax/stgedit.vim
 create mode 100644 contrib/vim/syntax/stgmail.vim
 create mode 100644 contrib/vim/syntax/stgnew.vim
 create mode 100644 contrib/vim/syntax/stgsquash.vim

Re: [StGIT PATCH] contrib/vim: Add vim syntax highlighting for StGit commit messages

From: Catalin Marinas <hidden>
Date: 2016-06-15 22:50:06

On 24 November 2010 00:38, Chris Packham [off-list ref] wrote:
On Wed, Nov 24, 2010 at 4:46 AM, Zane Bitter
[off-list ref] wrote:
quoted
I'm not sure about how Catalin runs stgit, but in for git having a
Signed-off-by: line is mandatory and usually indicates that the patch
considered ready for inclusion and acts as the "developers certificate
of authenticity" (i.e. it is the developers own work or the developer
has based it on other compatibly licensed code).

A commit message would also be nice but in this case I think it just
does what it says on the tin.
That would be nice but I'm not usually rejecting patches on this basis.
For the reviewers I can add that I've been using Zane's patch for a
while now and it works well for me (although I'm not exactly a vim
guru).
I can add a Tested-by then :)

-- 
Catalin
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help