threads / patch / 5941

patchbe more vim-ish, and also syntax hilight Signed-off-by lines.

Subject: [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.

## tl;dr

23 messages between Oct 17, 2006 and Oct 18, 2006. Diffs are folded; open one to read it.

replies: 22people: 6as markdown or json

Pierre Habouzit· Oct 17, 2006, 00:31 UTC · lore
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/syntax/gitcommit.vim |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
Show changes to contrib/vim/syntax/gitcommit.vim +18 −0
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
index a9de09f..d0c6e5d 100644
--- a/contrib/vim/syntax/gitcommit.vim
+++ b/contrib/vim/syntax/gitcommit.vim
@@ -1,3 +1,14 @@
+" Vim syntax file
+" Language:	git commit message
+
+" Quit when a (custom) syntax file was already loaded
+if exists("b:current_syntax")
+  finish
+endif
+
+syn region gitSignedOff start=/^Signed-off-by:/ end=/$/ contains=gitAuthor,gitEmail
+syn region gitAuthor contained start=/\s/ end=/$/
+
 syn region gitLine start=/^#/ end=/$/
 syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile
 syn region gitHead contained start=/^#   (.*)/ end=/^#$/
@@ -8,6 +19,9 @@ syn match gitCommitFile contained /^#\t.
 syn match gitChangedFile contained /^#\t.*/hs=s+2
 syn match gitUntrackedFile contained /^#\t.*/hs=s+2
 
+hi def link gitSignedOff Keyword
+hi def link gitAuthor Normal
+
 hi def link gitLine Comment
 hi def link gitCommit Comment
 hi def link gitChanged Comment
@@ -16,3 +30,7 @@ hi def link gitUntracked Comment
 hi def link gitCommitFile Type
 hi def link gitChangedFile Constant
 hi def link gitUntrackedFile Constant
+
+let b:current_syntax = "git"
+
+" vim: ts=8 sw=2
-- 
1.4.2.3
Pierre Habouzit· Oct 17, 2006, 00:31 UTC · re: Pierre Habouzit · lore

[PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/README                 |    6 ++++
 contrib/vim/ftplugin/gitcommit.vim |   61 ++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 0 deletions(-)
Show changes to 2 files +67 −0

contrib/vim/README, contrib/vim/ftplugin/gitcommit.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..26c1682 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -6,3 +6,9 @@ To syntax highlight git's commit message
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
      EOF
+
+To use the fancy split-view with the currently commited diff, you need to:
+  1. Copy ftplugin/gitcommit.vim to vim's ftplugin directory:
+     $ mkdir -p $HOME/.vim/ftplugin
+     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
+  2. Auto-detect the editing of git commit files (see above).
diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
new file mode 100644
index 0000000..f9efd59
--- /dev/null
+++ b/contrib/vim/ftplugin/gitcommit.vim
@@ -0,0 +1,61 @@
+if exists("b:did_ftplugin")
+  finish
+endif
+
+let b:did_ftplugin = 1
+
+setlocal tw=74
+setlocal nowarn nowb
+
+"{{{ function Git_diff_windows
+
+function! Git_diff_windows()
+    let i = 0
+    let list_of_files = ''
+
+    " drop everything until '#  (will commit)' and the next empty line
+    while i <= line('$')
+        let line = getline(i)
+        if line =~ '^#\s*(will commit)$'
+            let i = i + 2
+            break
+        endif
+
+        let i = i + 1
+    endwhile
+
+    " read file names until we have EOF or an empty line
+    while i <= line('$')
+        let line = getline(i)
+        if line =~ '^#\s*[a-z ]*:.*->.*$'
+            let file = substitute(line, '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+        elseif line =~ '^#\s*[a-z ]*:'
+            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+        elseif line =~ '^#\s*$'
+            break
+        endif
+
+        let i = i + 1
+    endwhile
+
+    if list_of_files == ""
+        return
+    endif
+
+    rightbelow vnew
+    silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
+    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd"
+    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
+    setlocal nomodifiable
+    redraw!
+    wincmd p
+    redraw!
+endfunction
+
+"}}}
+
+call Git_diff_windows()
-- 
1.4.2.3
Peter Baumann· Oct 17, 2006, 08:22 UTC · re: Pierre Habouzit · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

2006/10/17, Pierre Habouzit <madcoder@debian.org>:
Show 75 quoted lines
> Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> ---
>  contrib/vim/README                 |    6 ++++
>  contrib/vim/ftplugin/gitcommit.vim |   61 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/contrib/vim/README b/contrib/vim/README
> index 9e7881f..26c1682 100644
> --- a/contrib/vim/README
> +++ b/contrib/vim/README
> @@ -6,3 +6,9 @@ To syntax highlight git's commit message
>       $ cat >>$HOME/.vimrc <<'EOF'
>       autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
>       EOF
> +
> +To use the fancy split-view with the currently commited diff, you need to:
> +  1. Copy ftplugin/gitcommit.vim to vim's ftplugin directory:
> +     $ mkdir -p $HOME/.vim/ftplugin
> +     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
> +  2. Auto-detect the editing of git commit files (see above).
> diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
> new file mode 100644
> index 0000000..f9efd59
> --- /dev/null
> +++ b/contrib/vim/ftplugin/gitcommit.vim
> @@ -0,0 +1,61 @@
> +if exists("b:did_ftplugin")
> +  finish
> +endif
> +
> +let b:did_ftplugin = 1
> +
> +setlocal tw=74
> +setlocal nowarn nowb
> +
> +"{{{ function Git_diff_windows
> +
> +function! Git_diff_windows()
> +    let i = 0
> +    let list_of_files = ''
> +
> +    " drop everything until '#  (will commit)' and the next empty line
> +    while i <= line('$')
> +        let line = getline(i)
> +        if line =~ '^#\s*(will commit)$'
> +            let i = i + 2
> +            break
> +        endif
> +
> +        let i = i + 1
> +    endwhile
> +
> +    " read file names until we have EOF or an empty line
> +    while i <= line('$')
> +        let line = getline(i)
> +        if line =~ '^#\s*[a-z ]*:.*->.*$'
> +            let file = substitute(line, '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '')
> +            let list_of_files = list_of_files . ' '.file
> +            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '')
> +            let list_of_files = list_of_files . ' '.file
> +        elseif line =~ '^#\s*[a-z ]*:'
> +            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$', '\1', '')
> +            let list_of_files = list_of_files . ' '.file
> +        elseif line =~ '^#\s*$'
> +            break
> +        endif
> +
> +        let i = i + 1
> +    endwhile
> +
> +    if list_of_files == ""
> +        return
> +    endif
> +
> +    rightbelow vnew
I find it confusing that you split vertically, especially if I work in
 small terminals.
I would prefere a horizontal split, thats why I changed it to the way
to the way it is
handled in the svn.vim commit case:
below new
> +    silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
> +    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd"
> +    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"

Why changing directory? I had to remove the cd .. to make it work. Otherwise git diff couldn't find the repository.

Greetings,
  Peter
Pierre Habouzit· Oct 17, 2006, 10:38 UTC · re: Peter Baumann · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Le mar 17 octobre 2006 10:22, Peter Baumann a écrit :
Show 96 quoted lines
> 2006/10/17, Pierre Habouzit <madcoder@debian.org>:
> > Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> > ---
> >  contrib/vim/README                 |    6 ++++
> >  contrib/vim/ftplugin/gitcommit.vim |   61
> > ++++++++++++++++++++++++++++++++++++ 2 files changed, 67
> > insertions(+), 0 deletions(-)
> >
> > diff --git a/contrib/vim/README b/contrib/vim/README
> > index 9e7881f..26c1682 100644
> > --- a/contrib/vim/README
> > +++ b/contrib/vim/README
> > @@ -6,3 +6,9 @@ To syntax highlight git's commit message
> >       $ cat >>$HOME/.vimrc <<'EOF'
> >       autocmd BufNewFile,BufRead COMMIT_EDITMSG set
> > filetype=gitcommit EOF
> > +
> > +To use the fancy split-view with the currently commited diff, you
> > need to: +  1. Copy ftplugin/gitcommit.vim to vim's ftplugin
> > directory: +     $ mkdir -p $HOME/.vim/ftplugin
> > +     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
> > +  2. Auto-detect the editing of git commit files (see above).
> > diff --git a/contrib/vim/ftplugin/gitcommit.vim
> > b/contrib/vim/ftplugin/gitcommit.vim new file mode 100644
> > index 0000000..f9efd59
> > --- /dev/null
> > +++ b/contrib/vim/ftplugin/gitcommit.vim
> > @@ -0,0 +1,61 @@
> > +if exists("b:did_ftplugin")
> > +  finish
> > +endif
> > +
> > +let b:did_ftplugin = 1
> > +
> > +setlocal tw=74
> > +setlocal nowarn nowb
> > +
> > +"{{{ function Git_diff_windows
> > +
> > +function! Git_diff_windows()
> > +    let i = 0
> > +    let list_of_files = ''
> > +
> > +    " drop everything until '#  (will commit)' and the next empty
> > line +    while i <= line('$')
> > +        let line = getline(i)
> > +        if line =~ '^#\s*(will commit)$'
> > +            let i = i + 2
> > +            break
> > +        endif
> > +
> > +        let i = i + 1
> > +    endwhile
> > +
> > +    " read file names until we have EOF or an empty line
> > +    while i <= line('$')
> > +        let line = getline(i)
> > +        if line =~ '^#\s*[a-z ]*:.*->.*$'
> > +            let file = substitute(line,
> > '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '') +            let
> > list_of_files = list_of_files . ' '.file
> > +            let file = substitute(line,
> > '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '') +            let
> > list_of_files = list_of_files . ' '.file
> > +        elseif line =~ '^#\s*[a-z ]*:'
> > +            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$',
> > '\1', '') +            let list_of_files = list_of_files . ' '.file
> > +        elseif line =~ '^#\s*$'
> > +            break
> > +        endif
> > +
> > +        let i = i + 1
> > +    endwhile
> > +
> > +    if list_of_files == ""
> > +        return
> > +    endif
> > +
> > +    rightbelow vnew
>
> I find it confusing that you split vertically, especially if I work
> in small terminals.
> I would prefere a horizontal split, thats why I changed it to the way
> to the way it is
> handled in the svn.vim commit case:
>
> below new
>
> > +    silent! setlocal ft=diff previewwindow bufhidden=delete
> > nobackup noswf nobuflisted nowrap buftype=nofile +    exe 'normal
> > :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd" +   
> > exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "
> > \| git apply --stat\no\<esc>1GddO\<esc>"
>
> Why changing directory? I had to remove the cd .. to make it work.
> Otherwise git diff couldn't find the repository.

because for me, wherever I'm from, the cwd is .git/ but it's maybe due to the fact that I use autochdir, I don't know.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Peter Baumann· Oct 17, 2006, 10:59 UTC · re: Pierre Habouzit · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

2006/10/17, Pierre Habouzit <madcoder@debian.org>:
Show 101 quoted lines
> Le mar 17 octobre 2006 10:22, Peter Baumann a écrit :
> > 2006/10/17, Pierre Habouzit <madcoder@debian.org>:
> > > Signed-off-by: Pierre Habouzit <madcoder@debian.org>
> > > ---
> > >  contrib/vim/README                 |    6 ++++
> > >  contrib/vim/ftplugin/gitcommit.vim |   61
> > > ++++++++++++++++++++++++++++++++++++ 2 files changed, 67
> > > insertions(+), 0 deletions(-)
> > >
> > > diff --git a/contrib/vim/README b/contrib/vim/README
> > > index 9e7881f..26c1682 100644
> > > --- a/contrib/vim/README
> > > +++ b/contrib/vim/README
> > > @@ -6,3 +6,9 @@ To syntax highlight git's commit message
> > >       $ cat >>$HOME/.vimrc <<'EOF'
> > >       autocmd BufNewFile,BufRead COMMIT_EDITMSG set
> > > filetype=gitcommit EOF
> > > +
> > > +To use the fancy split-view with the currently commited diff, you
> > > need to: +  1. Copy ftplugin/gitcommit.vim to vim's ftplugin
> > > directory: +     $ mkdir -p $HOME/.vim/ftplugin
> > > +     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
> > > +  2. Auto-detect the editing of git commit files (see above).
> > > diff --git a/contrib/vim/ftplugin/gitcommit.vim
> > > b/contrib/vim/ftplugin/gitcommit.vim new file mode 100644
> > > index 0000000..f9efd59
> > > --- /dev/null
> > > +++ b/contrib/vim/ftplugin/gitcommit.vim
> > > @@ -0,0 +1,61 @@
> > > +if exists("b:did_ftplugin")
> > > +  finish
> > > +endif
> > > +
> > > +let b:did_ftplugin = 1
> > > +
> > > +setlocal tw=74
> > > +setlocal nowarn nowb
> > > +
> > > +"{{{ function Git_diff_windows
> > > +
> > > +function! Git_diff_windows()
> > > +    let i = 0
> > > +    let list_of_files = ''
> > > +
> > > +    " drop everything until '#  (will commit)' and the next empty
> > > line +    while i <= line('$')
> > > +        let line = getline(i)
> > > +        if line =~ '^#\s*(will commit)$'
> > > +            let i = i + 2
> > > +            break
> > > +        endif
> > > +
> > > +        let i = i + 1
> > > +    endwhile
> > > +
> > > +    " read file names until we have EOF or an empty line
> > > +    while i <= line('$')
> > > +        let line = getline(i)
> > > +        if line =~ '^#\s*[a-z ]*:.*->.*$'
> > > +            let file = substitute(line,
> > > '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '') +            let
> > > list_of_files = list_of_files . ' '.file
> > > +            let file = substitute(line,
> > > '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '') +            let
> > > list_of_files = list_of_files . ' '.file
> > > +        elseif line =~ '^#\s*[a-z ]*:'
> > > +            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$',
> > > '\1', '') +            let list_of_files = list_of_files . ' '.file
> > > +        elseif line =~ '^#\s*$'
> > > +            break
> > > +        endif
> > > +
> > > +        let i = i + 1
> > > +    endwhile
> > > +
> > > +    if list_of_files == ""
> > > +        return
> > > +    endif
> > > +
> > > +    rightbelow vnew
> >
> > I find it confusing that you split vertically, especially if I work
> > in small terminals.
> > I would prefere a horizontal split, thats why I changed it to the way
> > to the way it is
> > handled in the svn.vim commit case:
> >
> > below new
> >
> > > +    silent! setlocal ft=diff previewwindow bufhidden=delete
> > > nobackup noswf nobuflisted nowrap buftype=nofile +    exe 'normal
> > > :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd" +
> > > exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "
> > > \| git apply --stat\no\<esc>1GddO\<esc>"
> >
> > Why changing directory? I had to remove the cd .. to make it work.
> > Otherwise git diff couldn't find the repository.
>
> because for me, wherever I'm from, the cwd is .git/ but it's maybe due
> to the fact that I use autochdir, I don't know.
>

Wouldn't it make sense to use something like 'git-rev-parse --git-dir' or 'git-rev-parse --show-cdup' to get to the root of the repository?

Greetings,
  Peter
Pierre Habouzit· Oct 17, 2006, 11:04 UTC · re: Peter Baumann · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Le mar 17 octobre 2006 12:59, Peter Baumann a écrit :
> 2006/10/17, Pierre Habouzit <madcoder@debian.org>:
Show 6 quoted lines
> > because for me, wherever I'm from, the cwd is .git/ but it's maybe
> > due to the fact that I use autochdir, I don't know.
>
> Wouldn't it make sense to use something like 'git-rev-parse
> --git-dir' or 'git-rev-parse --show-cdup' to get to the root of the
> repository?
Yes it does, SungHyun Nam already sent a patch to me about that, that is 
quite interesting. I've merged it partly, and will make that commit 
plugin slightly better, so that people can:
 1/ trig it by hand
 2/ chose if the split is vertical or horizontal (I always have very big
    terms with a lot of vertical splits in vim, so I like the latter,
    other prefer the former)
 3/ chose via a let g:gitcommit_diff_mode or sth like that in the vimrc
    if that has to spawn automatically (0: none, 1: horiz split, 2: vert
    split)

and that time, I'll send that to the git contrib/vim maintainer so that I won't bother the list too much :)

a corrected version of the commit file wrt the cwd is on my site already, with a bit of SungHyun changes[1].

 [1] http://madism.org/~madcoder/dotfiles/vim/ftplugin/git.vim
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Christian MICHON· Oct 17, 2006, 21:48 UTC · re: Pierre Habouzit · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

On 10/17/06, Pierre Habouzit <madcoder@debian.org> wrote:
> and that time, I'll send that to the git contrib/vim maintainer so that
> I won't bother the list too much :)
>

so there is a contrib/vim maintainer ? Sorry I'm new on git list (though Pierre gave me some hints already with git/vim).

I'm interested in testing more of these goodies. Because I actually use git now on a daily basis for tcl/verilog/EDA together with (g)vim.

I'd like particularly to know if a git-explorer type of plugin makes sense for (g)vim and would like in this case be part of the team developping it... using git of course :)

-- 
Christian
Junio C Hamano· Oct 17, 2006, 22:04 UTC · re: Christian MICHON · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

"Christian MICHON" <christian.michon@gmail.com> writes:
Show 7 quoted lines
> On 10/17/06, Pierre Habouzit <madcoder@debian.org> wrote:
>> and that time, I'll send that to the git contrib/vim maintainer so that
>> I won't bother the list too much :)
>>
>
> so there is a contrib/vim maintainer ? Sorry I'm new on git list
> (though Pierre gave me some hints already with git/vim).
If you have git sources, check contrib/README please.

What I asked Pierre was to CC the patch to Jeff King who did contrib/vim -- it was "send it to him too", and not "do not send it to me". I do not actively use vim myself so I am a wrong person to judge patches to that part of the source tree.

Apparently Pierre seems to have thought that I thought patches to the contrib/ part is "bothering the list", but that was not my intention. I believe showing your patches for review by wider audiences is a good thing.

Petr Baudis· Oct 18, 2006, 01:57 UTC · re: Christian MICHON · lore

Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Dear diary, on Tue, Oct 17, 2006 at 11:48:51PM CEST, I got a letter where Christian MICHON <christian.michon@gmail.com> said that...

> I'd like particularly to know if a git-explorer type of plugin makes
> sense for (g)vim and would like in this case be part of the team
> developping it... using git of course :)
See also
	http://news.gmane.org/find-root.php?message_id=<20051124093322.GA3899@mail.yhbt.net>
Personally, I'd say "just use tig". :-)

If you insist on living instide vim, that particular script comes from the age before git-show and git-cat-file -p so it would probably make sense to move the bulk of the functionality there.

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
Junio C Hamano· Oct 17, 2006, 07:46 UTC · re: Pierre Habouzit · lore

Re: [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.

I'd prefer patches to contrib/ sections to be CC'ed to the owners of them (in this case that would be Jeff King) to be Acked, since I do not actively maintain anything under contrib/ myself.

Jeff, are you Ok with Pierre's two patches?
Pierre Habouzit· Oct 18, 2006, 00:38 UTC · re: Junio C Hamano · lore

contrib/vim patches, replace the previous set

  here is a brand new set of patches, the same update on the syntax
file, and an enhanced ftplugin that is very configureable.
  Those two patches replace the two previous ones.
Pierre Habouzit· Oct 18, 2006, 00:39 UTC · re: Junio C Hamano · lore

contrib/vim patches, replace the previous set

  here is a brand new set of patches, the same update on the syntax
file, and an enhanced ftplugin that is very configureable.
  Those two patches replace the two previous ones.
Pierre Habouzit· Oct 18, 2006, 00:39 UTC · re: Pierre Habouzit · lore
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/syntax/gitcommit.vim |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
Show changes to contrib/vim/syntax/gitcommit.vim +18 −0
diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim
index a9de09f..d0c6e5d 100644
--- a/contrib/vim/syntax/gitcommit.vim
+++ b/contrib/vim/syntax/gitcommit.vim
@@ -1,3 +1,14 @@
+" Vim syntax file
+" Language:	git commit message
+
+" Quit when a (custom) syntax file was already loaded
+if exists("b:current_syntax")
+  finish
+endif
+
+syn region gitSignedOff start=/^Signed-off-by:/ end=/$/ contains=gitAuthor,gitEmail
+syn region gitAuthor contained start=/\s/ end=/$/
+
 syn region gitLine start=/^#/ end=/$/
 syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile
 syn region gitHead contained start=/^#   (.*)/ end=/^#$/
@@ -8,6 +19,9 @@ syn match gitCommitFile contained /^#\t.
 syn match gitChangedFile contained /^#\t.*/hs=s+2
 syn match gitUntrackedFile contained /^#\t.*/hs=s+2
 
+hi def link gitSignedOff Keyword
+hi def link gitAuthor Normal
+
 hi def link gitLine Comment
 hi def link gitCommit Comment
 hi def link gitChanged Comment
@@ -16,3 +30,7 @@ hi def link gitUntracked Comment
 hi def link gitCommitFile Type
 hi def link gitChangedFile Constant
 hi def link gitUntrackedFile Constant
+
+let b:current_syntax = "git"
+
+" vim: ts=8 sw=2
-- 
1.4.2.3
Pierre Habouzit· Oct 18, 2006, 00:39 UTC · re: Pierre Habouzit · lore

[PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/README                 |   10 +++++
 contrib/vim/ftplugin/gitcommit.vim |   75 ++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)
Show changes to 2 files +85 −0

contrib/vim/README, contrib/vim/ftplugin/gitcommit.vim

diff --git a/contrib/vim/README b/contrib/vim/README
index 9e7881f..e5ca9ae 100644
--- a/contrib/vim/README
+++ b/contrib/vim/README
@@ -6,3 +6,13 @@ To syntax highlight git's commit message
      $ cat >>$HOME/.vimrc <<'EOF'
      autocmd BufNewFile,BufRead COMMIT_EDITMSG set filetype=gitcommit
      EOF
+
+To use the fancy split-view with the currently commited diff, you need to:
+  1. Copy ftplugin/gitcommit.vim to vim's ftplugin directory:
+     $ mkdir -p $HOME/.vim/ftplugin
+     $ cp ftplugin/gitcommit.vim $HOME/.vim/ftplugin
+  2. Auto-detect the editing of git commit files (see above).
+  3. You can configure the diff to spawn automatically by setting:
+     let git_diff_spawn_mode = 1 (or 2) for an horiz (resp. vert) split.
+     else you have the bindings ,gd or ,ghd to spawn an horiz split with
+     the diff, and ,gvd for the same with a vertical diff.
diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
new file mode 100644
index 0000000..a9cb946
--- /dev/null
+++ b/contrib/vim/ftplugin/gitcommit.vim
@@ -0,0 +1,75 @@
+if exists("b:did_ftplugin")
+  finish
+endif
+
+let b:did_ftplugin = 1
+
+setlocal tw=74
+setlocal nowarn nowb
+
+"{{{ function Git_diff_windows
+
+function! Git_diff_windows(vertsplit, auto)
+    let i = 0
+    let list_of_files = ''
+
+    " drop everything until '#  (will commit)' and the next empty line
+    while i <= line('$')
+        let line = getline(i)
+        if line =~ '^#\s*(will commit)$'
+            let i = i + 2
+            break
+        endif
+
+        let i = i + 1
+    endwhile
+
+    " read file names until we have EOF or an empty line
+    while i <= line('$')
+        let line = getline(i)
+        if line =~ '^#\s*[a-z ]*:.*->.*$'
+            let file = substitute(line, '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+        elseif line =~ '^#\s*[a-z ]*:'
+            let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$', '\1', '')
+            let list_of_files = list_of_files . ' '.file
+        elseif line =~ '^#\s*$'
+            break
+        endif
+
+        let i = i + 1
+    endwhile
+
+    if list_of_files == ""
+        return
+    endif
+
+    if a:vertsplit
+        rightbelow vnew
+    else
+        rightbelow new
+    endif
+    silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
+    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd"
+    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
+    setlocal nomodifiable
+    if a:auto
+        redraw!
+        wincmd p
+        redraw!
+    endif
+endfunction
+
+"}}}
+
+noremap <buffer> ,gd :call Git_diff_windows(0, 0)<cr>
+noremap <buffer> ,ghd :call Git_diff_windows(0, 0)<cr>
+noremap <buffer> ,gvd :call Git_diff_windows(1, 0)<cr>
+
+if g:git_diff_spawn_mode == 1
+    call Git_diff_windows(0, 1)
+elseif g:git_diff_spawn_mode == 2
+    call Git_diff_windows(1, 1)
+endif
-- 
1.4.2.3
Pierre Habouzit· Oct 18, 2006, 00:40 UTC · re: Pierre Habouzit · lore

Re: [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.

Le mer 18 octobre 2006 02:39, Pierre Habouzit a écrit :
> Signed-off-by: Pierre Habouzit <madcoder@debian.org>
damn, sorry, that's still not the good one :|
/me feels very tired.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Pierre Habouzit· Oct 18, 2006, 00:47 UTC · re: Pierre Habouzit · lore

[PATCH] be more robust wrt the git-dir.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/ftplugin/gitcommit.vim |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
Show changes to contrib/vim/ftplugin/gitcommit.vim +10 −2
diff --git a/contrib/vim/ftplugin/gitcommit.vim b/contrib/vim/ftplugin/gitcommit.vim
index a9cb946..e958fb1 100644
--- a/contrib/vim/ftplugin/gitcommit.vim
+++ b/contrib/vim/ftplugin/gitcommit.vim
@@ -52,9 +52,17 @@ function! Git_diff_windows(vertsplit, au
         rightbelow new
     endif
     silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
-    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . "\n1Gdd"
-    exe 'normal :r!LANG=C cd ..; git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
+    let gitDir = system('git rev-parse --git-dir 2>/dev/null')
+    let gitDir = substitute(gitDir, '.git\n', '', '')
+    let wd = getcwd()
+    if gitDir != ''
+        exe 'cd '.gitDir
+    endif
+    exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . "\n1Gdd"
+    exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
+    exe 'cd '.wd
     setlocal nomodifiable
+    noremap <buffer> q :bw<cr>
     if a:auto
         redraw!
         wincmd p
-- 
1.4.2.3
Jeff King· Oct 18, 2006, 07:02 UTC · re: Pierre Habouzit · lore

Re: Make the ftplugin right wrt gitdir

On Wed, Oct 18, 2006 at 02:47:25AM +0200, Pierre Habouzit wrote:
> sorry for the mess, I'm a bit tired :)
> Here is a third patch to fix the plugin to find the git-dir properly.
> 
> Also add a nice shortcut to quit that buffer.
Looks like the patch is missing (more sleep required?).
-Peff
Pierre Habouzit· Oct 18, 2006, 08:10 UTC · re: Jeff King · lore

Re: Make the ftplugin right wrt gitdir

Le mer 18 octobre 2006 09:02, Jeff King a écrit :
Show 8 quoted lines
> On Wed, Oct 18, 2006 at 02:47:25AM +0200, Pierre Habouzit wrote:
> > sorry for the mess, I'm a bit tired :)
> > Here is a third patch to fix the plugin to find the git-dir
> > properly.
> >
> > Also add a nice shortcut to quit that buffer.
>
> Looks like the patch is missing (more sleep required?).

err, the patch is here: <1161132446703-git-send-email-madcoder@debian.org>

at least I see it on the list for my part
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Jeff King· Oct 18, 2006, 09:02 UTC · re: Pierre Habouzit · lore

Re: Make the ftplugin right wrt gitdir

On Wed, Oct 18, 2006 at 10:10:59AM +0200, Pierre Habouzit wrote:
> > Looks like the patch is missing (more sleep required?).
> 
> err, the patch is here: 
> <1161132446703-git-send-email-madcoder@debian.org>

Right, that's the "be more robust" patch which applies on top of something else (presumably "nice ftplugin for vim"), but the last one I got of that (<11611319761977-git-send-email-madcoder@debian.org>) causes vim errors and you immediately followed up with "that's still not the good one." Where is that patch?

-Peff
Pierre Habouzit· Oct 18, 2006, 09:07 UTC · re: Jeff King · lore

Re: Make the ftplugin right wrt gitdir

Le mer 18 octobre 2006 11:02, Jeff King a écrit :
Show 11 quoted lines
> On Wed, Oct 18, 2006 at 10:10:59AM +0200, Pierre Habouzit wrote:
> > > Looks like the patch is missing (more sleep required?).
> >
> > err, the patch is here:
> > <1161132446703-git-send-email-madcoder@debian.org>
>
> Right, that's the "be more robust" patch which applies on top of
> something else (presumably "nice ftplugin for vim"), but the last one
> I got of that (<11611319761977-git-send-email-madcoder@debian.org>)
> causes vim errors and you immediately followed up with "that's still
> not the good one." Where is that patch?
hmm I see, curious though, I must have do sth stupid :|

well the result file is here: http://madism.org/~madcoder/dotfiles/vim/ftplugin/git.vim

I've not access to my git repo from here, feel free to grab it and commit it, I don't care if there is not my name on it.

and as of gitEmail you're right I don't use it, I wanted to to hilight the email address in the gitAuthor zone, but well, basically, it sucks, that makes too many colors.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Jeff King· Oct 18, 2006, 09:46 UTC · re: Pierre Habouzit · lore

Re: Make the ftplugin right wrt gitdir

On Wed, Oct 18, 2006 at 11:07:54AM +0200, Pierre Habouzit wrote:
> well the result file is here: 
> http://madism.org/~madcoder/dotfiles/vim/ftplugin/git.vim
I was able to grab it...my comments are below.
Show 8 quoted lines
>  if exists("b:did_ftplugin")
>    finish
>  endif
>  
>  let b:did_ftplugin = 1
>  
>  setlocal tw=74
>  setlocal nowarn nowb

Do things like tw really have anything to do with the ftplugin? Shouldn't they instead go into the user's vimrc?

Show 44 quoted lines
>  "{{{ function Git_diff_windows
>  
>  function! Git_diff_windows(vertsplit, auto)
>      let i = 0
>      let list_of_files = ''
>  
>      " drop everything until '#  (will commit)' and the next empty line
>      while i <= line('$')
>          let line = getline(i)
>          if line =~ '^#\s*(will commit)$'
>              let i = i + 2
>              break
>          endif
>  
>          let i = i + 1
>      endwhile
>  
>      " read file names until we have EOF or an empty line
>      while i <= line('$')
>          let line = getline(i)
>          if line =~ '^#\s*[a-z ]*:.*->.*$'
>              let file = substitute(line, '\v^#[^:]*:.*->\s*(.*)\s*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>              let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*->.*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>          elseif line =~ '^#\s*[a-z ]*:'
>              let file = substitute(line, '\v^#[^:]*:\s*(.*)\s*$', '\1', '')
>              let list_of_files = list_of_files . ' '.file
>          elseif line =~ '^#\s*$'
>              break
>          endif
>  
>          let i = i + 1
>      endwhile
>  
>      if list_of_files == ""
>          return
>      endif
>  
>      if a:vertsplit
>          rightbelow vnew
>      else
>          rightbelow new
>      endif

This all looks OK to me, but then I don't really know vim script very well. :)

Show 11 quoted lines
>      silent! setlocal ft=diff previewwindow bufhidden=delete nobackup noswf nobuflisted nowrap buftype=nofile
>      let gitDir = system('git rev-parse --git-dir 2>/dev/null')
>      let gitDir = substitute(gitDir, '.git\n', '', '')
>      let wd = getcwd()
>      if gitDir != ''
>          exe 'cd '.gitDir
>      endif
>      exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . "\n1Gdd"
>      exe 'normal :r!LANG=C git diff HEAD -- ' . list_of_files . " \| git apply --stat\no\<esc>1GddO\<esc>"
>      exe 'cd '.wd
>      setlocal nomodifiable

This procedure seems a bit hack-ish and fragile. I think the chdir is necessary not just to handle autochdir, but also because we want to do any diff from the top-level instead of a subdir. Why do we unconditionally set LANG=C? What about quoting for the file list?

In general, is this really that much nicer than simply using the '-v' flag to git-commit?

Show 5 quoted lines
>  if g:git_diff_spawn_mode == 1
>      call Git_diff_windows(0, 1)
>  elseif g:git_diff_spawn_mode == 2
>      call Git_diff_windows(1, 1)
>  endif
This should probably handle the case where g:git_diff_spawn_mode is not
defined (otherwise vim complains loudly):
  if exists("g:git_diff_spawn_mode")
     " do nothing
  elseif g:git_diff_spawn_mode == 1
etc.
-Peff
Jeff King· Oct 18, 2006, 06:59 UTC · re: Pierre Habouzit · lore

Re: [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.

On Wed, Oct 18, 2006 at 02:39:35AM +0200, Pierre Habouzit wrote:
> +if exists("b:current_syntax")
> +  finish
> +endif

I think this is a good change (along with commenting), but please write a more descriptive commit message than "be more vim-ish" (I wouldn't mind seeing this and the highlighting change broken into two patches, since they are functionally completely unrelated).

> +syn region gitSignedOff start=/^Signed-off-by:/ end=/$/ contains=gitAuthor,gitEmail
> +syn region gitAuthor contained start=/\s/ end=/$/
You mention gitEmail but never define it. Are people using other things
besides Signed-off-by? I think we might do better to simply write:
  syn region gitCommentHeader start=/^[^ ]\+:/ end=/$/ contains=gitCommentValue
  syn region gitCommentValue contained start=/\s/ end=/$/

Highlighting only the header is inconsistent with other highlighting (e.g., all of "new file: foo" is highlighted), but it looks so ugly to highlight the whole line, so I think this is fine.

-Peff

← back to recent threads