Commit 09c3e903 authored by Manu Beffara's avatar Manu Beffara
Browse files

Merge branch 'sentence-recognition' into 'master'

Better sentence recognition.

See merge request !2
parents 1ff3c89b 2223093c
......@@ -1595,6 +1595,7 @@ function s:coq.to_cursor ()
call self.infos.clear()
call self.clear_zones('CoqError')
let pos = getpos('.')[1:2]
let pos[1] = pos[1] + 1
if s:pos_lt(self.states[self.focus].range[1], pos)
" The current position is after the focus, add sentences.
" Fake a return code from call_add to initialise the loop.
......
......@@ -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