aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/colors/README.txt1
-rw-r--r--runtime/tools/check_colors.vim136
-rw-r--r--src/nvim/ex_docmd.c19
-rw-r--r--src/nvim/memline.c33
-rw-r--r--src/nvim/misc1.c4
-rw-r--r--src/nvim/ops.c2
-rw-r--r--src/nvim/testdir/setup.vim1
-rw-r--r--src/nvim/testdir/test_increment.vim22
-rw-r--r--src/nvim/testdir/test_search.vim9
9 files changed, 205 insertions, 22 deletions
diff --git a/runtime/colors/README.txt b/runtime/colors/README.txt
index 8fa6f322ab..7e845680a9 100644
--- a/runtime/colors/README.txt
+++ b/runtime/colors/README.txt
@@ -64,6 +64,7 @@ Search for "highlight_init".
If you think you have a color scheme that is good enough to be used by others,
please check the following items:
+- Source the $VIMRUNTIME/tools/check_colors.vim script to check for common mistakes.
- Does it work in a color terminal as well as in the GUI?
- Is "g:colors_name" set to a meaningful value? In case of doubt you can do
it this way:
diff --git a/runtime/tools/check_colors.vim b/runtime/tools/check_colors.vim
new file mode 100644
index 0000000000..0cfe5ec121
--- /dev/null
+++ b/runtime/tools/check_colors.vim
@@ -0,0 +1,136 @@
+" This script tests a color scheme for some errors. Load the scheme and source
+" this script. e.g. :e colors/desert.vim | :so test_colors.vim
+" Will output possible errors.
+
+let s:save_cpo= &cpo
+set cpo&vim
+
+func! Test_check_colors()
+ call cursor(1,1)
+ let err={}
+
+ " 1) Check g:colors_name is existing
+ if !search('\<\%(g:\)\?colors_name\>', 'cnW')
+ let err['colors_name'] = 'g:colors_name not set'
+ else
+ let err['colors_name'] = 'OK'
+ endif
+
+ " 2) Check for some well-defined highlighting groups
+ " Some items, check several groups, e.g. Diff, Spell
+ let hi_groups = ['ColorColumn', 'Diff', 'ErrorMsg', 'Folded',
+ \ 'FoldColumn', 'IncSearch', 'LineNr', 'ModeMsg', 'MoreMsg', 'NonText',
+ \ 'Normal', 'Pmenu', 'Todo', 'Search', 'Spell', 'StatusLine', 'TabLine',
+ \ 'Title', 'Visual', 'WarningMsg', 'WildMenu']
+ let groups={}
+ for group in hi_groups
+ if search('\c@suppress\s\+'.group, 'cnW')
+ " skip check, if the script contains a line like
+ " @suppress Visual:
+ let groups[group] = 'Ignoring '.group
+ continue
+ endif
+ if !search('hi\%[ghlight] \+'.group, 'cnW')
+ let groups[group] = 'No highlight definition for '.group
+ continue
+ endif
+ if !search('hi\%[ghlight] \+'.group. '.*fg=', 'cnW')
+ let groups[group] = 'Missing foreground color for '.group
+ continue
+ endif
+ if search('hi\%[ghlight] \+'.group. '.*guibg=', 'cnW') &&
+ \ !search('hi\%[ghlight] \+'.group. '.*ctermbg=', 'cnW')
+ let groups[group] = 'Missing bg terminal color for '.group
+ continue
+ endif
+ call search('hi\%[ghlight] \+'.group, 'cW')
+ " only check in the current line
+ if !search('guifg', 'cnW', line('.')) || !search('ctermfg', 'cnW', line('.'))
+ " do not check for background colors, they could be intentionally left out
+ let groups[group] = 'Missing fg definition for '.group
+ endif
+ call cursor(1,1)
+ endfor
+ let err['highlight'] = groups
+
+ " 3) Check, that it does not set background highlighting
+ " Doesn't ':hi Normal ctermfg=253 ctermfg=233' also set the background sometimes?
+ let bg_set='\(set\?\|setl\(ocal\)\?\) .*\(background\|bg\)=\(dark\|light\)'
+ let bg_let='let \%([&]\%([lg]:\)\?\)\%(background\|bg\)\s*=\s*\([''"]\?\)\w\+\1'
+ let bg_pat='\%('.bg_set. '\|'.bg_let.'\)'
+ let line=search(bg_pat, 'cnW')
+ if search(bg_pat, 'cnW')
+ exe line
+ if search('hi \U\w\+\s\+\S', 'cbnW')
+ let err['background'] = 'Should not set background option after :hi statement'
+ endif
+ else
+ let err['background'] = 'OK'
+ endif
+ call cursor(1,1)
+
+ " 4) Check, that t_Co is checked
+ let pat = '[&]t_Co\s*[<>=]=\?\s*\d\+'
+ if !search(pat, 'ncW')
+ let err['t_Co'] = 'Does not check terminal for capable colors'
+ endif
+
+ " 5) Initializes correctly, e.g. should have a section like
+ " hi clear
+ " if exists("syntax_on")
+ " syntax reset
+ " endif
+ let pat='hi\%[ghlight]\s*clear\n\s*if\s*exists(\([''"]\)syntax_on\1)\n\s*syn\%[tax]\s*reset\n\s*endif'
+ if !search(pat, 'cnW')
+ let err['init'] = 'No initialization'
+ endif
+
+ " 6) Does not use :syn on
+ if search('syn\%[tax]\s\+on', 'cnW')
+ let err['background'] = 'Should not issue :syn on'
+ endif
+
+ " 7) Does not define filetype specfic groups like vimCommand, htmlTag,
+ let hi_groups = ['vim', 'html', 'python', 'sh', 'ruby']
+ for group in hi_groups
+ let pat='\Chi\%[ghlight]\s*\zs'.group.'\w\+\>'
+ if search(pat, 'cnW')
+ let line = search(pat, 'cW')
+ let err['filetype'] = get(err, 'filetype', 'Should not define: ') . matchstr(getline('.'), pat). ' '
+ endif
+ call cursor(1,1)
+ endfor
+ let g:err = err
+
+ " print Result
+ call Result(err)
+endfu
+
+fu! Result(err)
+ let do_roups = 0
+ echohl Title|echomsg "---------------"|echohl Normal
+ for key in sort(keys(a:err))
+ if key is# 'highlight'
+ let do_groups = 1
+ continue
+ else
+ if a:err[key] !~ 'OK'
+ echohl Title
+ endif
+ echomsg printf("%15s: %s", key, a:err[key])
+ echohl Normal
+ endif
+ endfor
+ echohl Title|echomsg "---------------"|echohl Normal
+ if do_groups
+ echohl Title | echomsg "Groups" | echohl Normal
+ for v1 in sort(keys(a:err['highlight']))
+ echomsg printf("%25s: %s", v1, a:err['highlight'][v1])
+ endfor
+ endif
+endfu
+
+call Test_check_colors()
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index ac5de0733b..e4ab690bb9 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -3664,17 +3664,18 @@ static linenr_T get_address(exarg_T *eap,
*/
if (lnum != MAXLNUM)
curwin->w_cursor.lnum = lnum;
- /*
- * Start a forward search at the end of the line.
- * Start a backward search at the start of the line.
- * This makes sure we never match in the current
- * line, and can match anywhere in the
- * next/previous line.
- */
- if (c == '/')
+
+ // Start a forward search at the end of the line (unless
+ // before the first line).
+ // Start a backward search at the start of the line.
+ // This makes sure we never match in the current
+ // line, and can match anywhere in the
+ // next/previous line.
+ if (c == '/' && curwin->w_cursor.lnum > 0) {
curwin->w_cursor.col = MAXCOL;
- else
+ } else {
curwin->w_cursor.col = 0;
+ }
searchcmdlen = 0;
if (!do_search(NULL, c, cmd, 1L,
SEARCH_HIS | SEARCH_MSG, NULL)) {
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index ec9996810f..e84b8d623d 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -3999,18 +3999,15 @@ void goto_byte(long cnt)
/// Return 0 otherwise.
int inc(pos_T *lp)
{
- char_u *p = ml_get_pos(lp);
-
- if (*p != NUL) { // still within line, move to next char (may be NUL)
- if (has_mbyte) {
- int l = (*mb_ptr2len)(p);
+ // when searching position may be set to end of a line
+ if (lp->col != MAXCOL) {
+ const char_u *const p = ml_get_pos(lp);
+ if (*p != NUL) { // still within line, move to next char (may be NUL)
+ const int l = utfc_ptr2len(p);
lp->col += l;
- return (p[l] != NUL) ? 0 : 2;
+ return ((p[l] != NUL) ? 0 : 2);
}
- lp->col++;
- lp->coladd = 0;
- return (p[1] != NUL) ? 0 : 2;
}
if (lp->lnum != curbuf->b_ml.ml_line_count) { // there is a next line
lp->col = 0;
@@ -4035,20 +4032,32 @@ int incl(pos_T *lp)
int dec(pos_T *lp)
{
lp->coladd = 0;
- if (lp->col > 0) { // still within line
+ if (lp->col == MAXCOL) {
+ // past end of line
+ char_u *p = ml_get(lp->lnum);
+ lp->col = (colnr_T)STRLEN(p);
+ lp->col -= utf_head_off(p, p + lp->col);
+ return 0;
+ }
+
+ if (lp->col > 0) {
+ // still within line
lp->col--;
char_u *p = ml_get(lp->lnum);
lp->col -= utf_head_off(p, p + lp->col);
return 0;
}
- if (lp->lnum > 1) { // there is a prior line
+ if (lp->lnum > 1) {
+ // there is a prior line
lp->lnum--;
char_u *p = ml_get(lp->lnum);
lp->col = (colnr_T)STRLEN(p);
lp->col -= utf_head_off(p, p + lp->col);
return 1;
}
- return -1; // at start of file
+
+ // at start of file
+ return -1;
}
/// Same as dec(), but skip NUL at the end of non-empty lines.
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index ad0a8d409f..99dc29f119 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1752,6 +1752,10 @@ del_lines (
int gchar_pos(pos_T *pos)
{
+ // When searching columns is sometimes put at the end of a line.
+ if (pos->col == MAXCOL) {
+ return NUL;
+ }
return utf_ptr2char(ml_get_pos(pos));
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index d28e51ba4d..e902127a40 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -4418,7 +4418,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd)
length = (colnr_T)STRLEN(ml_get(pos.lnum));
} else {
// oap->motion_type == kMTCharWise
- if (!oap->inclusive) {
+ if (pos.lnum == oap->start.lnum && !oap->inclusive) {
dec(&(oap->end));
}
length = (colnr_T)STRLEN(ml_get(pos.lnum));
diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim
index b38f50b501..e1006fda3a 100644
--- a/src/nvim/testdir/setup.vim
+++ b/src/nvim/testdir/setup.vim
@@ -11,6 +11,7 @@ set sidescroll=0
set directory^=.
set undodir^=.
set backspace=
+set nrformats+=octal
set nohidden smarttab noautoindent noautoread complete-=i noruler noshowcmd
set listchars=eol:$
set fillchars=vert:\|,fold:-
diff --git a/src/nvim/testdir/test_increment.vim b/src/nvim/testdir/test_increment.vim
index 8bfd95d810..ab11d943d9 100644
--- a/src/nvim/testdir/test_increment.vim
+++ b/src/nvim/testdir/test_increment.vim
@@ -3,6 +3,7 @@
func SetUp()
new dummy
set nrformats&vim
+ set nrformats+=octal
endfunc
func TearDown()
@@ -364,11 +365,25 @@ endfunc
" Expected:
" 1) Ctrl-a on visually selected zero
" 111
+"
+" Also: 019 with "01" selected increments to "029".
func Test_visual_increment_15()
call setline(1, ["101"])
exec "norm! lv\<C-A>"
call assert_equal(["111"], getline(1, '$'))
call assert_equal([0, 1, 2, 0], getpos('.'))
+
+ call setline(1, ["019"])
+ exec "norm! 0vl\<C-A>"
+ call assert_equal("029", getline(1))
+
+ call setline(1, ["01239"])
+ exec "norm! 0vlll\<C-A>"
+ call assert_equal("01249", getline(1))
+
+ call setline(1, ["01299"])
+ exec "norm! 0vlll\<C-A>"
+ call assert_equal("1309", getline(1))
endfunc
" 16) increment right aligned numbers
@@ -756,5 +771,12 @@ func Test_normal_increment_03()
call assert_equal([0, 3, 25, 0], getpos('.'))
endfunc
+func Test_increment_empty_line()
+ new
+ call setline(1, ['0', '0', '0', '0', '0', '0', ''])
+ exe "normal Gvgg\<C-A>"
+ call assert_equal(['1', '1', '1', '1', '1', '1', ''], getline(1, 7))
+ bwipe!
+endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index 7663c9e283..ecd840d40c 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -480,3 +480,12 @@ func Test_look_behind()
call search(getline("."))
bwipe!
endfunc
+
+func Test_search_sentence()
+ new
+ " this used to cause a crash
+ call assert_fails("/\\%')", 'E486')
+ call assert_fails("/", 'E486')
+ /\%'(
+ /
+endfunc