[PATCH v3] VIM: Improve moving between messages in a thread

2015-02-03 Thread Bartosz Telenczuk
> I think the API should be clear and easy to understand, because people will 
> probably bind them to custom shortcuts. You should not have to think about 
> what that weird extra parameter (-1, false, ...) means and go read the docs.

I agree. One might replace the parameter with a string like "prev" and "next".

> But I agree that the code duplication is not optimal. The code in Ians repo 
> already has split out the ruby code. There is still code duplication. But 
> that can easily be split out into a function on its own. 

That's the way to go.

Bartosz


RE: [PATCH v3] VIM: Improve moving between messages in a thread

2015-02-02 Thread Bartosz Telenczuk
> I think the API should be clear and easy to understand, because people will 
> probably bind them to custom shortcuts. You should not have to think about 
> what that weird extra parameter (-1, false, ...) means and go read the docs.

I agree. One might replace the parameter with a string like "prev" and "next".

> But I agree that the code duplication is not optimal. The code in Ians repo 
> already has split out the ruby code. There is still code duplication. But 
> that can easily be split out into a function on its own. 

That's the way to go.

Bartosz
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3] VIM: Improve moving between messages in a thread

2015-01-21 Thread Franz Fellner
Bartosz Telenczuk wrote:
> Hi Ian,
> 
> The patch looks good. I tested it on my system and it works fine.  I just 
> have one suggestion regarding coding style.
> 
> > +function! s:show_prev_msg()
> >  function! s:show_next_msg()
> 
> Since these functions are almost the same, you could avoid code repetition by 
> replacing them by a function which takes (positive or negative) increment as 
> an argument.

I think the API should be clear and easy to understand, because people will 
probably bind them to custom shortcuts. You should not have to think about what 
that weird extra parameter (-1, false, ...) means and go read the docs.
But I agree that the code duplication is not optimal. The code in Ians repo 
already has split out the ruby code. There is still code duplication. But that 
can easily be split out into a function on its own. 

Franz


RE: [PATCH v3] VIM: Improve moving between messages in a thread

2015-01-21 Thread Franz Fellner
Bartosz Telenczuk wrote:
> Hi Ian,
> 
> The patch looks good. I tested it on my system and it works fine.  I just 
> have one suggestion regarding coding style.
> 
> > +function! s:show_prev_msg()
> >  function! s:show_next_msg()
> 
> Since these functions are almost the same, you could avoid code repetition by 
> replacing them by a function which takes (positive or negative) increment as 
> an argument.

I think the API should be clear and easy to understand, because people will 
probably bind them to custom shortcuts. You should not have to think about what 
that weird extra parameter (-1, false, ...) means and go read the docs.
But I agree that the code duplication is not optimal. The code in Ians repo 
already has split out the ruby code. There is still code duplication. But that 
can easily be split out into a function on its own. 

Franz
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


RE: [PATCH v3] VIM: Improve moving between messages in a thread

2015-01-13 Thread Bartosz Telenczuk
Hi Ian,

The patch looks good. I tested it on my system and it works fine.  I just have 
one suggestion regarding coding style.

> +function! s:show_prev_msg()
>  function! s:show_next_msg()

Since these functions are almost the same, you could avoid code repetition by 
replacing them by a function which takes (positive or negative) increment as an 
argument.

Cheers,

Bartosz

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3] VIM: Improve moving between messages in a thread

2015-01-13 Thread Bartosz Telenczuk
Hi Ian,

The patch looks good. I tested it on my system and it works fine.  I just have 
one suggestion regarding coding style.

> +function! s:show_prev_msg()
>  function! s:show_next_msg()

Since these functions are almost the same, you could avoid code repetition by 
replacing them by a function which takes (positive or negative) increment as an 
argument.

Cheers,

Bartosz



[PATCH v3] VIM: Improve moving between messages in a thread

2014-10-20 Thread Ian Main
Add a few changes to moving between threads:

- It supports 'scrolloff' so that if you have this set it will move the
  buffer and cursor so the next/prev email starts at the top of the
  screen.
- It adds the ability to use shift-tab to go to the previous msg in
  the thread.

Ian
---

Remove spurious vim_puts.

 vim/notmuch.vim | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index 331e930..bd007b1 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -39,6 +39,7 @@ let g:notmuch_show_maps = {
\ 'p':  'show_save_patches()',
\ 'r':  'show_reply()',
\ '?':  'show_info()',
+   \ '':'show_prev_msg()',
\ '':  'show_next_msg()',
\ 'c':  'compose()',
\ }
@@ -113,6 +114,21 @@ EOF
call s:kill_this_buffer()
 endfunction
 
+function! s:show_prev_msg()
+ruby << EOF
+   r, c = $curwin.cursor
+   n = $curbuf.line_number
+   i = $messages.index { |m| n >= m.start && n <= m.end }
+   m = $messages[i - 1] if i > 0
+   if m
+   r = m.body_start + 1
+   scrolloff = VIM::evaluate("&scrolloff")
+   VIM::command("normal #{m.start + scrolloff}zt")
+   $curwin.cursor = r + scrolloff, c
+   end
+EOF
+endfunction
+
 function! s:show_next_msg()
 ruby << EOF
r, c = $curwin.cursor
@@ -121,8 +137,9 @@ ruby << EOF
m = $messages[i + 1]
if m
r = m.body_start + 1
-   VIM::command("normal #{m.start}zt")
-   $curwin.cursor = r, c
+   scrolloff = VIM::evaluate("&scrolloff")
+   VIM::command("normal #{m.start + scrolloff}zt")
+   $curwin.cursor = r + scrolloff, c
end
 EOF
 endfunction
-- 
1.9.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH v3] VIM: Improve moving between messages in a thread

2014-10-20 Thread Ian Main
Add a few changes to moving between threads:

- It supports 'scrolloff' so that if you have this set it will move the
  buffer and cursor so the next/prev email starts at the top of the
  screen.
- It adds the ability to use shift-tab to go to the previous msg in
  the thread.

Ian
---

Remove spurious vim_puts.

 vim/notmuch.vim | 21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/vim/notmuch.vim b/vim/notmuch.vim
index 331e930..bd007b1 100644
--- a/vim/notmuch.vim
+++ b/vim/notmuch.vim
@@ -39,6 +39,7 @@ let g:notmuch_show_maps = {
\ 'p':  'show_save_patches()',
\ 'r':  'show_reply()',
\ '?':  'show_info()',
+   \ '':'show_prev_msg()',
\ '':  'show_next_msg()',
\ 'c':  'compose()',
\ }
@@ -113,6 +114,21 @@ EOF
call s:kill_this_buffer()
 endfunction

+function! s:show_prev_msg()
+ruby << EOF
+   r, c = $curwin.cursor
+   n = $curbuf.line_number
+   i = $messages.index { |m| n >= m.start && n <= m.end }
+   m = $messages[i - 1] if i > 0
+   if m
+   r = m.body_start + 1
+   scrolloff = VIM::evaluate("&scrolloff")
+   VIM::command("normal #{m.start + scrolloff}zt")
+   $curwin.cursor = r + scrolloff, c
+   end
+EOF
+endfunction
+
 function! s:show_next_msg()
 ruby << EOF
r, c = $curwin.cursor
@@ -121,8 +137,9 @@ ruby << EOF
m = $messages[i + 1]
if m
r = m.body_start + 1
-   VIM::command("normal #{m.start}zt")
-   $curwin.cursor = r, c
+   scrolloff = VIM::evaluate("&scrolloff")
+   VIM::command("normal #{m.start + scrolloff}zt")
+   $curwin.cursor = r + scrolloff, c
end
 EOF
 endfunction
-- 
1.9.3