threads / patch / 5539

patchcontrib/vim: add syntax highlighting file for commits

Subject: [PATCH] contrib/vim: add syntax highlighting file for commits

## tl;dr

6 messages between Sep 11, 2006 and Sep 13, 2006. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Jeff King· Sep 11, 2006, 23:22 UTC · lore
Signed-off-by: Jeff King <peff@peff.net>
---
There were at least a few positive comments on this, and hey, we have to
balance the contrib/emacs directory!
 contrib/vim/README            |    7 +++++++
 contrib/vim/commit-syntax.vim |   18 ++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)
Show changes to 2 files +25 −0

contrib/vim/README, contrib/vim/commit-syntax.vim

diff --git a/contrib/vim/README b/contrib/vim/README
new file mode 100644
index 0000000..bad0a05
--- /dev/null
+++ b/contrib/vim/README
@@ -0,0 +1,7 @@
+To syntax highlight git's commit messages, you need to:
+  1. Copy commit-syntax.vim to vim's syntax directory:
+     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  2. Auto-detect the editing of git commit files:
+     $ cat >>$HOME/.vimrc <<'EOF'
+     autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
+     EOF
diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/commit-syntax.vim
new file mode 100644
index 0000000..a9de09f
--- /dev/null
+++ b/contrib/vim/commit-syntax.vim
@@ -0,0 +1,18 @@
+syn region gitLine start=/^#/ end=/$/
+syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile
+syn region gitHead contained start=/^#   (.*)/ end=/^#$/
+syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile
+syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile
+
+syn match gitCommitFile contained /^#\t.*/hs=s+2
+syn match gitChangedFile contained /^#\t.*/hs=s+2
+syn match gitUntrackedFile contained /^#\t.*/hs=s+2
+
+hi def link gitLine Comment
+hi def link gitCommit Comment
+hi def link gitChanged Comment
+hi def link gitHead Comment
+hi def link gitUntracked Comment
+hi def link gitCommitFile Type
+hi def link gitChangedFile Constant
+hi def link gitUntrackedFile Constant
-- 
1.4.2.g39f1
Tom Prince· Sep 12, 2006, 02:08 UTC · re: Jeff King · lore

Re: [PATCH] contrib/vim: add syntax highlighting file for commits

On Mon, Sep 11, 2006 at 07:22:49PM -0400, Jeff King wrote:
> +  1. Copy commit-syntax.vim to vim's syntax directory:
> +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
...
> diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/commit-syntax.vim
It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/
  Tom
Jeff King· Sep 12, 2006, 02:32 UTC · re: Tom Prince · lore

Re: [PATCH] contrib/vim: add syntax highlighting file for commits

On Mon, Sep 11, 2006 at 08:08:13PM -0600, Tom Prince wrote:
> > +  1. Copy commit-syntax.vim to vim's syntax directory:
> > +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
> It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/

It would be with only one file, but you could just as easily have a .vim/ftplugin/gitcommit.vim file (I think there are others, too). If you want to give it the "proper" name, it should probably be syntax/gitcommit.vim.

-Peff
Junio C Hamano· Sep 13, 2006, 06:12 UTC · re: Jeff King · lore

Re: [PATCH] contrib/vim: add syntax highlighting file for commits

Jeff King <peff@peff.net> writes:
Show 10 quoted lines
> On Mon, Sep 11, 2006 at 08:08:13PM -0600, Tom Prince wrote:
>
>> > +  1. Copy commit-syntax.vim to vim's syntax directory:
>> > +     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
>> It would be more obvious if you could do cp gitcomit.vim $HOME/.vim/syntax/
>
> It would be with only one file, but you could just as easily have a
> .vim/ftplugin/gitcommit.vim file (I think there are others, too). If you
> want to give it the "proper" name, it should probably be
> syntax/gitcommit.vim.

I am not a vim user, but my reading of Tom's comment is that he thinks it would have been nicer if the file the patch adds were named gitcommit.vim, not commit-syntax.vim. As you seem to agree that the preferred name for this file when deployed is gitcommit.vim, how about something like this on top of your patch perhaps?

Show changes to 2 files +2 −2

contrib/vim/README, contrib/vim/commit-syntax.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index bad0a05..f574cc8 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,6 +1,6 @@
 To syntax highlight git's commit messages, you need to:
-  1. Copy commit-syntax.vim to vim's syntax directory:
-     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  1. Copy gitcommit.vim to vim's syntax directory:
+     $ cp gitcommit.vim $HOME/.vim/syntax/
   2. Auto-detect the editing of git commit files:
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/gitcommit.vim
similarity index 100%
rename from contrib/vim/commit-syntax.vim
rename to contrib/vim/gitcommit.vim
Jeff King· Sep 13, 2006, 06:25 UTC · re: Junio C Hamano · lore

Re: [PATCH] contrib/vim: add syntax highlighting file for commits

On Tue, Sep 12, 2006 at 11:12:08PM -0700, Junio C Hamano wrote:
Show 6 quoted lines
> I am not a vim user, but my reading of Tom's comment is that he
> thinks it would have been nicer if the file the patch adds were
> named gitcommit.vim, not commit-syntax.vim.  As you seem to
> agree that the preferred name for this file when deployed is
> gitcommit.vim, how about something like this on top of your
> patch perhaps?

My point was that there may be many files named gitcommit.vim; the directory they appear in under your .vim directory has significance. If we add another such file, they will conflict in the flattened namespace of contrib/vim. See below (which also adds the necessary mkdir command):

-- >8 -- contrib/vim: give commit-syntax a more sensible name

Show changes to 2 files +3 −2

contrib/vim/README, contrib/vim/commit-syntax.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index bad0a05..9e7881f 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -1,6 +1,7 @@
 To syntax highlight git's commit messages, you need to:
-  1. Copy commit-syntax.vim to vim's syntax directory:
-     $ cp commit-syntax.vim $HOME/.vim/syntax/gitcommit.vim
+  1. Copy syntax/gitcommit.vim to vim's syntax directory:
+     $ mkdir -p $HOME/.vim/syntax
+     $ cp syntax/gitcommit.vim $HOME/.vim/syntax
   2. Auto-detect the editing of git commit files:
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
diff --git a/contrib/vim/commit-syntax.vim b/contrib/vim/syntax/gitcommit.vim
similarity index 100%
rename from contrib/vim/commit-syntax.vim
rename to contrib/vim/syntax/gitcommit.vim
Tom Prince· Sep 13, 2006, 06:46 UTC · re: Jeff King · lore

Re: [PATCH] contrib/vim: add syntax highlighting file for commits

On Wed, Sep 13, 2006 at 02:25:57AM -0400, Jeff King wrote:
 
Show 6 quoted lines
> My point was that there may be many files named gitcommit.vim; the
> directory they appear in under your .vim directory has significance. If
> we add another such file, they will conflict in the flattened namespace
> of contrib/vim.  See below (which also adds the necessary mkdir
> command):
> 

Much clearer. I had glanced at the readme and did cp commit-syntax.vim ~/.vim/syntax and it took me a minute or so to figure what was wrong.

  Tom

← back to recent threads