mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #8896 from janlazo/vim-8.1.0083
This commit is contained in:
commit
2ab80b944b
@ -2211,21 +2211,17 @@ showmatch(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// Find the start of the next sentence, searching in the direction specified
|
||||||
* findsent(dir, count) - Find the start of the next sentence in direction
|
// by the "dir" argument. The cursor is positioned on the start of the next
|
||||||
* "dir" Sentences are supposed to end in ".", "!" or "?" followed by white
|
// sentence when found. If the next sentence is found, return OK. Return FAIL
|
||||||
* space or a line break. Also stop at an empty line.
|
// otherwise. See ":h sentence" for the precise definition of a "sentence"
|
||||||
* Return OK if the next sentence was found.
|
// text object.
|
||||||
*/
|
int findsent(Direction dir, long count)
|
||||||
int findsent(int dir, long count)
|
|
||||||
{
|
{
|
||||||
pos_T pos, tpos;
|
pos_T pos, tpos;
|
||||||
int c;
|
int c;
|
||||||
int (*func)(pos_T *);
|
int (*func)(pos_T *);
|
||||||
int startlnum;
|
bool noskip = false; // do not skip blanks
|
||||||
int noskip = FALSE; /* do not skip blanks */
|
|
||||||
int cpo_J;
|
|
||||||
int found_dot;
|
|
||||||
|
|
||||||
pos = curwin->w_cursor;
|
pos = curwin->w_cursor;
|
||||||
if (dir == FORWARD)
|
if (dir == FORWARD)
|
||||||
@ -2259,30 +2255,30 @@ int findsent(int dir, long count)
|
|||||||
decl(&pos);
|
decl(&pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// go back to the previous non-blank char
|
// go back to the previous non-white non-punctuation character
|
||||||
found_dot = false;
|
bool found_dot = false;
|
||||||
while ((c = gchar_pos(&pos)) == ' ' || c == '\t'
|
while (c = gchar_pos(&pos), ascii_iswhite(c)
|
||||||
|| (dir == BACKWARD
|
|| vim_strchr((char_u *)".!?)]\"'", c) != NULL) {
|
||||||
&& vim_strchr((char_u *)".!?)]\"'", c) != NULL)) {
|
tpos = pos;
|
||||||
if (vim_strchr((char_u *)".!?", c) != NULL) {
|
if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD)) {
|
||||||
/* Only skip over a '.', '!' and '?' once. */
|
|
||||||
if (found_dot)
|
|
||||||
break;
|
|
||||||
found_dot = TRUE;
|
|
||||||
}
|
|
||||||
if (decl(&pos) == -1) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// when going forward: Stop in front of empty line
|
if (found_dot) {
|
||||||
if (LINEEMPTY(pos.lnum) && dir == FORWARD) {
|
break;
|
||||||
incl(&pos);
|
|
||||||
goto found;
|
|
||||||
}
|
}
|
||||||
|
if (vim_strchr((char_u *) ".!?", c) != NULL) {
|
||||||
|
found_dot = true;
|
||||||
|
}
|
||||||
|
if (vim_strchr((char_u *) ")]\"'", c) != NULL
|
||||||
|
&& vim_strchr((char_u *) ".!?)]\"'", gchar_pos(&tpos)) == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
decl(&pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remember the line where the search started */
|
// remember the line where the search started
|
||||||
startlnum = pos.lnum;
|
const int startlnum = pos.lnum;
|
||||||
cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL;
|
const bool cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL;
|
||||||
|
|
||||||
for (;; ) { /* find end of sentence */
|
for (;; ) { /* find end of sentence */
|
||||||
c = gchar_pos(&pos);
|
c = gchar_pos(&pos);
|
||||||
@ -2310,7 +2306,7 @@ int findsent(int dir, long count)
|
|||||||
if ((*func)(&pos) == -1) {
|
if ((*func)(&pos) == -1) {
|
||||||
if (count)
|
if (count)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
noskip = TRUE;
|
noskip = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,3 +182,78 @@ x
|
|||||||
norm it
|
norm it
|
||||||
q!
|
q!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_sentence()
|
||||||
|
enew!
|
||||||
|
call setline(1, 'A sentence. A sentence? A sentence!')
|
||||||
|
|
||||||
|
normal yis
|
||||||
|
call assert_equal('A sentence.', @")
|
||||||
|
normal yas
|
||||||
|
call assert_equal('A sentence. ', @")
|
||||||
|
|
||||||
|
normal )
|
||||||
|
|
||||||
|
normal yis
|
||||||
|
call assert_equal('A sentence?', @")
|
||||||
|
normal yas
|
||||||
|
call assert_equal('A sentence? ', @")
|
||||||
|
|
||||||
|
normal )
|
||||||
|
|
||||||
|
normal yis
|
||||||
|
call assert_equal('A sentence!', @")
|
||||||
|
normal yas
|
||||||
|
call assert_equal(' A sentence!', @")
|
||||||
|
|
||||||
|
normal 0
|
||||||
|
normal 2yis
|
||||||
|
call assert_equal('A sentence. ', @")
|
||||||
|
normal 3yis
|
||||||
|
call assert_equal('A sentence. A sentence?', @")
|
||||||
|
normal 2yas
|
||||||
|
call assert_equal('A sentence. A sentence? ', @")
|
||||||
|
|
||||||
|
%delete _
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_sentence_with_quotes()
|
||||||
|
enew!
|
||||||
|
call setline(1, 'A "sentence." A sentence.')
|
||||||
|
|
||||||
|
normal yis
|
||||||
|
call assert_equal('A "sentence."', @")
|
||||||
|
normal yas
|
||||||
|
call assert_equal('A "sentence." ', @")
|
||||||
|
|
||||||
|
normal )
|
||||||
|
|
||||||
|
normal yis
|
||||||
|
call assert_equal('A sentence.', @")
|
||||||
|
normal yas
|
||||||
|
call assert_equal(' A sentence.', @")
|
||||||
|
|
||||||
|
%delete _
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func! Test_sentence_with_cursor_on_delimiter()
|
||||||
|
enew!
|
||||||
|
call setline(1, "A '([sentence.])' A sentence.")
|
||||||
|
|
||||||
|
normal! 15|yis
|
||||||
|
call assert_equal("A '([sentence.])'", @")
|
||||||
|
normal! 15|yas
|
||||||
|
call assert_equal("A '([sentence.])' ", @")
|
||||||
|
|
||||||
|
normal! 16|yis
|
||||||
|
call assert_equal("A '([sentence.])'", @")
|
||||||
|
normal! 16|yas
|
||||||
|
call assert_equal("A '([sentence.])' ", @")
|
||||||
|
|
||||||
|
normal! 17|yis
|
||||||
|
call assert_equal("A '([sentence.])'", @")
|
||||||
|
normal! 17|yas
|
||||||
|
call assert_equal("A '([sentence.])' ", @")
|
||||||
|
|
||||||
|
%delete _
|
||||||
|
endfunc
|
||||||
|
Loading…
Reference in New Issue
Block a user