Commit 8bb03577 authored by Adam Matoušek's avatar Adam Matoušek
Browse files

Handle deeper bullets (--, ++, etc.) correctly.

parent 10ee9a51
......@@ -76,6 +76,14 @@ function! s:SearchBackward (pattern, immediate)
endwhile
endfunction
" Jump to the leftmost character of a bullet. Returns original position.
function! s:ToBulletBegin ()
let position = getpos(".")
call search('[-+*]\+\%#', 'bW')
return position
endfunction
" Check if the current position is a beginning of sentence, i.e. if it is
" located between a period or bullet and the next non-blank character. The
" argument indicates how the cursor is considered:
......@@ -84,11 +92,13 @@ endfunction
" - if false, the cursor position is accepted even if it contains the first
" non-blank character of a sentence.
let s:coq_sentence_pattern = '\.\_s\|\([-+*]\_s\|[{}]\)\|\(\S\)'
function! s:IsBeginningOfSentence (immediate)
let immediate = a:immediate
let position = getpos(".")
while v:true
let result = s:SearchBackward('\.\_s\|\([-+*{}]\)\|\(\S\)', immediate)
let result = s:SearchBackward(s:coq_sentence_pattern, immediate)
if result <= 1
" A period or the beginning of the buffer was found.
call setpos(".", position)
......@@ -96,6 +106,7 @@ function! s:IsBeginningOfSentence (immediate)
elseif result ==# 2
" A potential bullet was found, validate it by checking it is a
" beginning of sentence.
call s:ToBulletBegin()
let immediate = v:false
continue
else
......@@ -110,15 +121,18 @@ endfunction
" otherwise (i.e. when the end of the buffer was reached). The argument
" indicates whether a match at the current position is accepted.
let s:coq_period_pattern = '\%(\.\@<!\)\.\_s\@=\|\([-+*]*\zs[-+*]\ze\_s\|[{}]\)'
function! CoqNextPeriod (immediate)
let immediate = a:immediate
while v:true
let result = s:SearchForward('\.\@<!\.\_s\@=\|\([-+*{}]\)', immediate)
let result = s:SearchForward(s:coq_period_pattern, immediate)
if result ==# 2
" A potential bullet was found, check it.
if s:IsBeginningOfSentence(v:false)
return v:true
endif
let position = s:ToBulletBegin()
let isbegin = s:IsBeginningOfSentence(v:false)
call setpos(".", position)
if isbegin | return v:true | endif
else
return result !=# 0
endif
......@@ -132,12 +146,13 @@ endfunction
function! CoqPreviousPeriod (immediate)
let immediate = a:immediate
while v:true
let result = s:SearchBackward('\.\@<!\.\_s\|\([-+*{}]\)', immediate)
let result = s:SearchBackward(s:coq_period_pattern, immediate)
if result ==# 2
" A potential bullet was found, check it.
if s:IsBeginningOfSentence(v:false)
return v:true
endif
let position = s:ToBulletBegin()
let isbegin = s:IsBeginningOfSentence(v:false)
call setpos(".", position)
if isbegin | return v:true | endif
else
return result !=# 0
endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment