Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements, issue fixes #21

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions autoload/smoothie.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
let s:ctrl_f_invoked = v:false

if !exists('g:smoothie_update_interval')
""
" Time (in milliseconds) between subseqent screen/cursor postion updates.
Expand All @@ -22,6 +24,14 @@ if !exists('g:smoothie_break_on_reverse')
let g:smoothie_break_on_reverse = 0
endif

if !exists('g:smoothie_bell_enabled')
""
" Enable beeping when either end of the buffer has been reached, and we
" cannot proceed any further
subnut marked this conversation as resolved.
Show resolved Hide resolved
" disabled by default
let g:smoothie_bell_enabled = 0
endif

""
" Execute {command}, but saving 'scroll' value before, and restoring it
" afterwards. Useful for some commands (such as ^D or ^U), which overwrite
Expand All @@ -48,9 +58,28 @@ endfunction
" Scroll the window down by one line, or move the cursor down if the window is
" already at the bottom. Return 1 if cannot move any lower.
function s:step_down()
if !(line('.') < line('$')) && !s:ctrl_f_invoked
" i.e. cursor is at last line of buffer, and movement is not Ctrl-F
" cannot move
return 1
endif
if line('.') < line('$')
if s:ctrl_f_invoked && (winheight(0) - winline()) >= (line('$') - line('.'))
call s:execute_preserving_scroll("normal! \<C-E>")
endif
" NOTE: the three lines of code following this comment block
" have been implemented as a temporary workaround for a vim issue
subnut marked this conversation as resolved.
Show resolved Hide resolved
" regarding Ctrl-D and folds.
"
" See: psliwka/vim-smoothie#20
if foldclosedend('.') != -1
call cursor(foldclosedend('.'), col('.'))
endif
call s:execute_preserving_scroll("normal! 1\<C-D>")
return 0
elseif s:ctrl_f_invoked && winline() > 1
call s:execute_preserving_scroll("normal! \<C-E>")
return 0
else
return 1
endif
Expand Down Expand Up @@ -140,6 +169,13 @@ function s:movement_tick(_)
if s:step_many(l:step_size)
" we've collided with either buffer end
call s:stop_moving()
if g:smoothie_bell_enabled
" bell
let l:belloff = &belloff
set belloff=
exe "normal \<Esc>"
exe 'set belloff=' . l:belloff
endif
else
let s:target_displacement -= l:step_size
let s:subline_position = l:subline_step_size - l:step_size
Expand Down Expand Up @@ -177,25 +213,29 @@ endfunction
""
" Smooth equivalent to ^D.
function smoothie#downwards()
let s:ctrl_f_invoked = v:false
call s:count_to_scroll()
call s:update_target(&scroll)
endfunction

""
" Smooth equivalent to ^U.
function smoothie#upwards()
let s:ctrl_f_invoked = v:false
call s:count_to_scroll()
call s:update_target(-&scroll)
endfunction

""
" Smooth equivalent to ^F.
function smoothie#forwards()
let s:ctrl_f_invoked = v:true
call s:update_target(winheight(0) * v:count1)
endfunction

""
" Smooth equivalent to ^B.
function smoothie#backwards()
let s:ctrl_f_invoked = v:false
call s:update_target(-winheight(0) * v:count1)
endfunction
44 changes: 31 additions & 13 deletions plugin/smoothie.vim
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
nnoremap <silent> <Plug>(SmoothieDownwards) :<C-U>call smoothie#downwards() <CR>
nnoremap <silent> <Plug>(SmoothieUpwards) :<C-U>call smoothie#upwards() <CR>
nnoremap <silent> <Plug>(SmoothieForwards) :<C-U>call smoothie#forwards() <CR>
nnoremap <silent> <Plug>(SmoothieBackwards) :<C-U>call smoothie#backwards() <CR>
if has('nvim') || has("patch-8.2.1280")
noremap <silent> <Plug>(SmoothieDownwards) <cmd>call smoothie#downwards() <CR>
noremap <silent> <Plug>(SmoothieUpwards) <cmd>call smoothie#upwards() <CR>
noremap <silent> <Plug>(SmoothieForwards) <cmd>call smoothie#forwards() <CR>
noremap <silent> <Plug>(SmoothieBackwards) <cmd>call smoothie#backwards() <CR>

if !get(g:, 'smoothie_no_default_mappings', v:false)
silent! nmap <unique> <C-D> <Plug>(SmoothieDownwards)
silent! nmap <unique> <C-U> <Plug>(SmoothieUpwards)
silent! nmap <unique> <C-F> <Plug>(SmoothieForwards)
silent! nmap <unique> <S-Down> <Plug>(SmoothieForwards)
silent! nmap <unique> <PageDown> <Plug>(SmoothieForwards)
silent! nmap <unique> <C-B> <Plug>(SmoothieBackwards)
silent! nmap <unique> <S-Up> <Plug>(SmoothieBackwards)
silent! nmap <unique> <PageUp> <Plug>(SmoothieBackwards)
if !get(g:, 'smoothie_no_default_mappings', v:false)
silent! map <unique> <C-D> <Plug>(SmoothieDownwards)
silent! map <unique> <C-U> <Plug>(SmoothieUpwards)
silent! map <unique> <C-F> <Plug>(SmoothieForwards)
silent! map <unique> <S-Down> <Plug>(SmoothieForwards)
silent! map <unique> <PageDown> <Plug>(SmoothieForwards)
silent! map <unique> <C-B> <Plug>(SmoothieBackwards)
silent! map <unique> <S-Up> <Plug>(SmoothieBackwards)
silent! map <unique> <PageUp> <Plug>(SmoothieBackwards)
endif
else
nnoremap <silent> <Plug>(SmoothieDownwards) :<C-U>call smoothie#downwards() <CR>
nnoremap <silent> <Plug>(SmoothieUpwards) :<C-U>call smoothie#upwards() <CR>
nnoremap <silent> <Plug>(SmoothieForwards) :<C-U>call smoothie#forwards() <CR>
nnoremap <silent> <Plug>(SmoothieBackwards) :<C-U>call smoothie#backwards() <CR>

if !get(g:, 'smoothie_no_default_mappings', v:false)
silent! nmap <unique> <C-D> <Plug>(SmoothieDownwards)
silent! nmap <unique> <C-U> <Plug>(SmoothieUpwards)
silent! nmap <unique> <C-F> <Plug>(SmoothieForwards)
silent! nmap <unique> <S-Down> <Plug>(SmoothieForwards)
silent! nmap <unique> <PageDown> <Plug>(SmoothieForwards)
silent! nmap <unique> <C-B> <Plug>(SmoothieBackwards)
silent! nmap <unique> <S-Up> <Plug>(SmoothieBackwards)
silent! nmap <unique> <PageUp> <Plug>(SmoothieBackwards)
endif
endif