git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.
@ 2006-10-17  0:31 Pierre Habouzit
  2006-10-17  0:31 ` [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
  2006-10-17  7:46 ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Junio C Hamano
  0 siblings, 2 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-17  0:31 UTC (permalink / raw)
  To: git; +Cc: Pierre Habouzit

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/syntax/gitcommit.vim |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17  0:31 [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
@ 2006-10-17  0:31 ` Pierre Habouzit
  2006-10-17  8:22   ` Peter Baumann
  2006-10-17  7:46 ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Junio C Hamano
  1 sibling, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-17  0:31 UTC (permalink / raw)
  To: git; +Cc: Pierre Habouzit

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
+    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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.
  2006-10-17  0:31 [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
  2006-10-17  0:31 ` [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
@ 2006-10-17  7:46 ` Junio C Hamano
  2006-10-18  0:38   ` contrib/vim patches, replace the previous set Pierre Habouzit
  2006-10-18  0:39   ` Pierre Habouzit
  1 sibling, 2 replies; 23+ messages in thread
From: Junio C Hamano @ 2006-10-17  7:46 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git, Jeff King

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?

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17  0:31 ` [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
@ 2006-10-17  8:22   ` Peter Baumann
  2006-10-17 10:38     ` Pierre Habouzit
  0 siblings, 1 reply; 23+ messages in thread
From: Peter Baumann @ 2006-10-17  8:22 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git, Jeff King

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.

Greetings,
  Peter

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17  8:22   ` Peter Baumann
@ 2006-10-17 10:38     ` Pierre Habouzit
  2006-10-17 10:59       ` Peter Baumann
  0 siblings, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-17 10:38 UTC (permalink / raw)
  To: Peter Baumann; +Cc: git, Jeff King

[-- Attachment #1: Type: text/plain, Size: 3826 bytes --]

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.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17 10:38     ` Pierre Habouzit
@ 2006-10-17 10:59       ` Peter Baumann
  2006-10-17 11:04         ` Pierre Habouzit
  0 siblings, 1 reply; 23+ messages in thread
From: Peter Baumann @ 2006-10-17 10:59 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git, Jeff King

2006/10/17, Pierre Habouzit <madcoder@debian.org>:
> 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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17 10:59       ` Peter Baumann
@ 2006-10-17 11:04         ` Pierre Habouzit
  2006-10-17 21:48           ` Christian MICHON
  0 siblings, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-17 11:04 UTC (permalink / raw)
  To: Peter Baumann; +Cc: git, Jeff King

[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]

Le mar 17 octobre 2006 12:59, Peter Baumann a écrit :
> 2006/10/17, Pierre Habouzit <madcoder@debian.org>:

> > 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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17 11:04         ` Pierre Habouzit
@ 2006-10-17 21:48           ` Christian MICHON
  2006-10-17 22:04             ` Junio C Hamano
  2006-10-18  1:57             ` Petr Baudis
  0 siblings, 2 replies; 23+ messages in thread
From: Christian MICHON @ 2006-10-17 21:48 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17 21:48           ` Christian MICHON
@ 2006-10-17 22:04             ` Junio C Hamano
  2006-10-18  1:57             ` Petr Baudis
  1 sibling, 0 replies; 23+ messages in thread
From: Junio C Hamano @ 2006-10-17 22:04 UTC (permalink / raw)
  To: Christian MICHON; +Cc: git, Pierre Habouzit

"Christian MICHON" <christian.michon@gmail.com> writes:

> 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.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* contrib/vim patches, replace the previous set
  2006-10-17  7:46 ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Junio C Hamano
@ 2006-10-18  0:38   ` Pierre Habouzit
  2006-10-18  0:39   ` Pierre Habouzit
  1 sibling, 0 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:38 UTC (permalink / raw)
  To: Jeff King; +Cc: git

  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.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* contrib/vim patches, replace the previous set
  2006-10-17  7:46 ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Junio C Hamano
  2006-10-18  0:38   ` contrib/vim patches, replace the previous set Pierre Habouzit
@ 2006-10-18  0:39   ` Pierre Habouzit
  2006-10-18  0:39     ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
  1 sibling, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:39 UTC (permalink / raw)
  To: Jeff King; +Cc: git

  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.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.
  2006-10-18  0:39   ` Pierre Habouzit
@ 2006-10-18  0:39     ` Pierre Habouzit
  2006-10-18  0:39       ` [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
                         ` (2 more replies)
  0 siblings, 3 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:39 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Pierre Habouzit

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/syntax/gitcommit.vim |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-18  0:39     ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
@ 2006-10-18  0:39       ` Pierre Habouzit
  2006-10-18  0:40         ` Pierre Habouzit
  2006-10-18  0:47       ` Make the ftplugin right wrt gitdir Pierre Habouzit
  2006-10-18  6:59       ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Jeff King
  2 siblings, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:39 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Pierre Habouzit

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(-)

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-18  0:39       ` [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
@ 2006-10-18  0:40         ` Pierre Habouzit
  0 siblings, 0 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:40 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Make the ftplugin right wrt gitdir
  2006-10-18  0:39     ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
  2006-10-18  0:39       ` [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
@ 2006-10-18  0:47       ` Pierre Habouzit
  2006-10-18  0:47         ` [PATCH] be more robust wrt the git-dir Pierre Habouzit
  2006-10-18  7:02         ` Make the ftplugin right wrt gitdir Jeff King
  2006-10-18  6:59       ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Jeff King
  2 siblings, 2 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:47 UTC (permalink / raw)
  To: Jeff King; +Cc: git

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.

^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH] be more robust wrt the git-dir.
  2006-10-18  0:47       ` Make the ftplugin right wrt gitdir Pierre Habouzit
@ 2006-10-18  0:47         ` Pierre Habouzit
  2006-10-18  7:02         ` Make the ftplugin right wrt gitdir Jeff King
  1 sibling, 0 replies; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  0:47 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Pierre Habouzit

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 contrib/vim/ftplugin/gitcommit.vim |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

* Re: [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer.
  2006-10-17 21:48           ` Christian MICHON
  2006-10-17 22:04             ` Junio C Hamano
@ 2006-10-18  1:57             ` Petr Baudis
  1 sibling, 0 replies; 23+ messages in thread
From: Petr Baudis @ 2006-10-18  1:57 UTC (permalink / raw)
  To: Christian MICHON; +Cc: git

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*',/((..)*)$/)

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines.
  2006-10-18  0:39     ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
  2006-10-18  0:39       ` [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
  2006-10-18  0:47       ` Make the ftplugin right wrt gitdir Pierre Habouzit
@ 2006-10-18  6:59       ` Jeff King
  2 siblings, 0 replies; 23+ messages in thread
From: Jeff King @ 2006-10-18  6:59 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Make the ftplugin right wrt gitdir
  2006-10-18  0:47       ` Make the ftplugin right wrt gitdir Pierre Habouzit
  2006-10-18  0:47         ` [PATCH] be more robust wrt the git-dir Pierre Habouzit
@ 2006-10-18  7:02         ` Jeff King
  2006-10-18  8:10           ` Pierre Habouzit
  1 sibling, 1 reply; 23+ messages in thread
From: Jeff King @ 2006-10-18  7:02 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Make the ftplugin right wrt gitdir
  2006-10-18  7:02         ` Make the ftplugin right wrt gitdir Jeff King
@ 2006-10-18  8:10           ` Pierre Habouzit
  2006-10-18  9:02             ` Jeff King
  0 siblings, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  8:10 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

Le mer 18 octobre 2006 09:02, Jeff King a écrit :
> 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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Make the ftplugin right wrt gitdir
  2006-10-18  8:10           ` Pierre Habouzit
@ 2006-10-18  9:02             ` Jeff King
  2006-10-18  9:07               ` Pierre Habouzit
  0 siblings, 1 reply; 23+ messages in thread
From: Jeff King @ 2006-10-18  9:02 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git

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

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Make the ftplugin right wrt gitdir
  2006-10-18  9:02             ` Jeff King
@ 2006-10-18  9:07               ` Pierre Habouzit
  2006-10-18  9:46                 ` Jeff King
  0 siblings, 1 reply; 23+ messages in thread
From: Pierre Habouzit @ 2006-10-18  9:07 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1237 bytes --]

Le mer 18 octobre 2006 11:02, Jeff King a écrit :
> 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

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: Make the ftplugin right wrt gitdir
  2006-10-18  9:07               ` Pierre Habouzit
@ 2006-10-18  9:46                 ` Jeff King
  0 siblings, 0 replies; 23+ messages in thread
From: Jeff King @ 2006-10-18  9:46 UTC (permalink / raw)
  To: Pierre Habouzit; +Cc: git

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.

>  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?

>  "{{{ 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. :)

>      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?

>  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

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-10-18  9:46 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-17  0:31 [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
2006-10-17  0:31 ` [PATCH] nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
2006-10-17  8:22   ` Peter Baumann
2006-10-17 10:38     ` Pierre Habouzit
2006-10-17 10:59       ` Peter Baumann
2006-10-17 11:04         ` Pierre Habouzit
2006-10-17 21:48           ` Christian MICHON
2006-10-17 22:04             ` Junio C Hamano
2006-10-18  1:57             ` Petr Baudis
2006-10-17  7:46 ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Junio C Hamano
2006-10-18  0:38   ` contrib/vim patches, replace the previous set Pierre Habouzit
2006-10-18  0:39   ` Pierre Habouzit
2006-10-18  0:39     ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Pierre Habouzit
2006-10-18  0:39       ` [PATCH] Nice ftplugin for vim, that shows the commited diff in a split'ed buffer Pierre Habouzit
2006-10-18  0:40         ` Pierre Habouzit
2006-10-18  0:47       ` Make the ftplugin right wrt gitdir Pierre Habouzit
2006-10-18  0:47         ` [PATCH] be more robust wrt the git-dir Pierre Habouzit
2006-10-18  7:02         ` Make the ftplugin right wrt gitdir Jeff King
2006-10-18  8:10           ` Pierre Habouzit
2006-10-18  9:02             ` Jeff King
2006-10-18  9:07               ` Pierre Habouzit
2006-10-18  9:46                 ` Jeff King
2006-10-18  6:59       ` [PATCH] be more vim-ish, and also syntax hilight Signed-off-by lines Jeff King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).