forked from aniani/vim
patch 8.2.3233: prop_list() and prop_find() do not indicate the buffer
Problem: prop_list() and prop_find() do not indicate the buffer for the used type. Solution: Add "type_bufnr" to the results. (closes #8647)
This commit is contained in:
committed by
Bram Moolenaar
parent
7e6a2a64f0
commit
e2390c7f32
@@ -211,6 +211,8 @@ prop_list({lnum} [, {props}]) *prop_list()*
|
|||||||
id property ID
|
id property ID
|
||||||
type name of the property type, omitted if
|
type name of the property type, omitted if
|
||||||
the type was deleted
|
the type was deleted
|
||||||
|
type_bufnr buffer number for which this type was defined;
|
||||||
|
0 if the type is global
|
||||||
start when TRUE property starts in this line
|
start when TRUE property starts in this line
|
||||||
end when TRUE property ends in this line
|
end when TRUE property ends in this line
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_proptype_buf()
|
func Test_proptype_buf()
|
||||||
let bufnr = bufnr('')
|
let bufnr = bufnr('')
|
||||||
call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
|
call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1})
|
||||||
let proptypes = prop_type_list({'bufnr': bufnr})
|
let proptypes = prop_type_list({'bufnr': bufnr})
|
||||||
call assert_equal(1, len(proptypes))
|
call assert_equal(1, len(proptypes))
|
||||||
call assert_equal('comment', proptypes[0])
|
call assert_equal('comment', proptypes[0])
|
||||||
@@ -70,6 +70,36 @@ func Test_proptype_buf()
|
|||||||
call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
|
call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:")
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
def Test_proptype_buf_list()
|
||||||
|
new
|
||||||
|
var bufnr = bufnr('')
|
||||||
|
try
|
||||||
|
prop_type_add('global', {})
|
||||||
|
prop_type_add('local', {bufnr: bufnr})
|
||||||
|
|
||||||
|
prop_add(1, 1, {type: 'global'})
|
||||||
|
prop_add(1, 1, {type: 'local'})
|
||||||
|
|
||||||
|
assert_equal([
|
||||||
|
{type: 'local', type_bufnr: bufnr, id: 0, col: 1, end: 1, length: 0, start: 1},
|
||||||
|
{type: 'global', type_bufnr: 0, id: 0, col: 1, end: 1, length: 0, start: 1},
|
||||||
|
], prop_list(1))
|
||||||
|
assert_equal(
|
||||||
|
{lnum: 1, id: 0, col: 1, type_bufnr: bufnr, end: 1, type: 'local', length: 0, start: 1},
|
||||||
|
prop_find({lnum: 1, type: 'local'}))
|
||||||
|
assert_equal(
|
||||||
|
{lnum: 1, id: 0, col: 1, type_bufnr: 0, end: 1, type: 'global', length: 0, start: 1},
|
||||||
|
prop_find({lnum: 1, type: 'global'}))
|
||||||
|
|
||||||
|
prop_remove({type: 'global'}, 1)
|
||||||
|
prop_remove({type: 'local'}, 1)
|
||||||
|
finally
|
||||||
|
prop_type_delete('global')
|
||||||
|
prop_type_delete('local', {bufnr: bufnr})
|
||||||
|
bwipe!
|
||||||
|
endtry
|
||||||
|
enddef
|
||||||
|
|
||||||
func AddPropTypes()
|
func AddPropTypes()
|
||||||
call prop_type_add('one', {})
|
call prop_type_add('one', {})
|
||||||
call prop_type_add('two', {})
|
call prop_type_add('two', {})
|
||||||
@@ -94,10 +124,10 @@ endfunc
|
|||||||
|
|
||||||
func Get_expected_props()
|
func Get_expected_props()
|
||||||
return [
|
return [
|
||||||
\ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1},
|
||||||
\ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
|
||||||
\ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
|
||||||
\ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1},
|
||||||
\ ]
|
\ ]
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
@@ -112,9 +142,9 @@ func Test_prop_find()
|
|||||||
call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
|
call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1})
|
||||||
|
|
||||||
let expected = [
|
let expected = [
|
||||||
\ {'lnum': 1, 'col': 5, 'length': 3, 'id': 10, 'type': 'prop_name', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1},
|
||||||
\ {'lnum': 2, 'col': 4, 'id': 11, 'type': 'prop_name', 'start': 1, 'end': 0},
|
\ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0},
|
||||||
\ {'lnum': 5, 'col': 4, 'length': 1, 'id': 12, 'type': 'prop_name', 'start': 1, 'end': 1}
|
\ #{type_bufnr: 0, lnum: 5, col: 4, length: 1, id: 12, type: 'prop_name', start: 1, end: 1}
|
||||||
\ ]
|
\ ]
|
||||||
|
|
||||||
" Starting at line 5 col 1 this should find the prop at line 5 col 4.
|
" Starting at line 5 col 1 this should find the prop at line 5 col 4.
|
||||||
@@ -226,7 +256,7 @@ def Test_prop_find2()
|
|||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
cursor(1, 8)
|
cursor(1, 8)
|
||||||
var expected = {lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
|
var expected = {type_bufnr: 0, lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1}
|
||||||
var result = prop_find({type: 'misspell', skipstart: true}, 'f')
|
var result = prop_find({type: 'misspell', skipstart: true}, 'f')
|
||||||
assert_equal(expected, result)
|
assert_equal(expected, result)
|
||||||
|
|
||||||
@@ -239,7 +269,8 @@ func Test_prop_find_smaller_len_than_match_col()
|
|||||||
call prop_type_add('test', {'highlight': 'ErrorMsg'})
|
call prop_type_add('test', {'highlight': 'ErrorMsg'})
|
||||||
call setline(1, ['xxxx', 'x'])
|
call setline(1, ['xxxx', 'x'])
|
||||||
call prop_add(1, 4, {'type': 'test'})
|
call prop_add(1, 4, {'type': 'test'})
|
||||||
call assert_equal({'id': 0, 'lnum': 1, 'col': 4, 'type': 'test', 'length': 0, 'start': 1, 'end': 1},
|
call assert_equal(
|
||||||
|
\ #{type_bufnr: 0, id: 0, lnum: 1, col: 4, type: 'test', length: 0, start: 1, end: 1},
|
||||||
\ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
|
\ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b'))
|
||||||
bwipe!
|
bwipe!
|
||||||
call prop_type_delete('test')
|
call prop_type_delete('test')
|
||||||
@@ -284,12 +315,12 @@ func Test_prop_add()
|
|||||||
call prop_clear(1)
|
call prop_clear(1)
|
||||||
call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
|
call prop_type_add('included', {'start_incl': 1, 'end_incl': 1})
|
||||||
call prop_add(1, 5, #{type: 'included'})
|
call prop_add(1, 5, #{type: 'included'})
|
||||||
let expected = [#{col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
|
let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
" Inserting text makes the prop bigger.
|
" Inserting text makes the prop bigger.
|
||||||
exe "normal 5|ixx\<Esc>"
|
exe "normal 5|ixx\<Esc>"
|
||||||
let expected = [#{col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
|
let expected = [#{type_bufnr: 0, col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
|
call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:')
|
||||||
@@ -327,7 +358,7 @@ func Test_prop_remove()
|
|||||||
call SetupPropsInFirstLine()
|
call SetupPropsInFirstLine()
|
||||||
call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
|
call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'})
|
||||||
let props = Get_expected_props()
|
let props = Get_expected_props()
|
||||||
call insert(props, {'col': 6, 'length': 2, 'id': 11, 'type': 'three', 'start': 1, 'end': 1}, 3)
|
call insert(props, #{type_bufnr: 0, col: 6, length: 2, id: 11, type: 'three', start: 1, end: 1}, 3)
|
||||||
call assert_equal(props, prop_list(1))
|
call assert_equal(props, prop_list(1))
|
||||||
call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
|
call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1))
|
||||||
unlet props[3]
|
unlet props[3]
|
||||||
@@ -367,8 +398,8 @@ func SetupOneLine()
|
|||||||
call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
|
call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'})
|
||||||
call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
|
call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'})
|
||||||
let expected = [
|
let expected = [
|
||||||
\ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', start: 1, end: 1},
|
||||||
\ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 8, length: 3, id: 12, type: 'two', start: 1, end: 1},
|
||||||
\]
|
\]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
return expected
|
return expected
|
||||||
@@ -389,9 +420,9 @@ func Test_prop_add_remove_buf()
|
|||||||
endfor
|
endfor
|
||||||
|
|
||||||
let props = [
|
let props = [
|
||||||
\ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1},
|
||||||
\ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1},
|
||||||
\ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1},
|
\ #{type_bufnr: 0, col: 11, length: 3, id: 13, type: 'three', start: 1, end: 1},
|
||||||
\]
|
\]
|
||||||
call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
|
call assert_equal(props, prop_list(1, {'bufnr': bufnr}))
|
||||||
|
|
||||||
@@ -658,7 +689,7 @@ func Test_prop_change_indent()
|
|||||||
new
|
new
|
||||||
call setline(1, [' xxx', 'yyyyy'])
|
call setline(1, [' xxx', 'yyyyy'])
|
||||||
call prop_add(2, 2, {'length': 2, 'type': 'comment'})
|
call prop_add(2, 2, {'length': 2, 'type': 'comment'})
|
||||||
let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0}
|
let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0}
|
||||||
call assert_equal([expect], prop_list(2))
|
call assert_equal([expect], prop_list(2))
|
||||||
|
|
||||||
set shiftwidth=3
|
set shiftwidth=3
|
||||||
@@ -704,11 +735,11 @@ func Test_prop_multiline()
|
|||||||
|
|
||||||
" start halfway line 1, end halfway line 3
|
" start halfway line 1, end halfway line 3
|
||||||
call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
|
call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'})
|
||||||
let expect1 = {'col': 3, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
|
let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0}
|
||||||
call assert_equal([expect1], prop_list(1))
|
call assert_equal([expect1], prop_list(1))
|
||||||
let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0}
|
let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0}
|
||||||
call assert_equal([expect2], prop_list(2))
|
call assert_equal([expect2], prop_list(2))
|
||||||
let expect3 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
|
let expect3 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
|
||||||
call assert_equal([expect3], prop_list(3))
|
call assert_equal([expect3], prop_list(3))
|
||||||
call prop_clear(1, 3)
|
call prop_clear(1, 3)
|
||||||
|
|
||||||
@@ -726,21 +757,21 @@ func Test_prop_multiline()
|
|||||||
|
|
||||||
" Test deleting the first line of a multi-line prop.
|
" Test deleting the first line of a multi-line prop.
|
||||||
call Setup_three_line_prop()
|
call Setup_three_line_prop()
|
||||||
let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0}
|
let expect_short = #{type_bufnr: 0, col: 2, length: 1, type: 'comment', start: 1, end: 1, id: 0}
|
||||||
call assert_equal([expect_short], prop_list(1))
|
call assert_equal([expect_short], prop_list(1))
|
||||||
let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
|
let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
|
||||||
call assert_equal([expect2], prop_list(2))
|
call assert_equal([expect2], prop_list(2))
|
||||||
2del
|
2del
|
||||||
call assert_equal([expect_short], prop_list(1))
|
call assert_equal([expect_short], prop_list(1))
|
||||||
let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
|
let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0}
|
||||||
call assert_equal([expect2], prop_list(2))
|
call assert_equal([expect2], prop_list(2))
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
" Test deleting the last line of a multi-line prop.
|
" Test deleting the last line of a multi-line prop.
|
||||||
call Setup_three_line_prop()
|
call Setup_three_line_prop()
|
||||||
let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0}
|
let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0}
|
||||||
call assert_equal([expect3], prop_list(3))
|
call assert_equal([expect3], prop_list(3))
|
||||||
let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
|
let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0}
|
||||||
call assert_equal([expect4], prop_list(4))
|
call assert_equal([expect4], prop_list(4))
|
||||||
4del
|
4del
|
||||||
let expect3.end = 1
|
let expect3.end = 1
|
||||||
@@ -750,11 +781,11 @@ func Test_prop_multiline()
|
|||||||
|
|
||||||
" Test appending a line below the multi-line text prop start.
|
" Test appending a line below the multi-line text prop start.
|
||||||
call Setup_three_line_prop()
|
call Setup_three_line_prop()
|
||||||
let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
|
let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0}
|
||||||
call assert_equal([expect2], prop_list(2))
|
call assert_equal([expect2], prop_list(2))
|
||||||
call append(2, "new line")
|
call append(2, "new line")
|
||||||
call assert_equal([expect2], prop_list(2))
|
call assert_equal([expect2], prop_list(2))
|
||||||
let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0}
|
let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0}
|
||||||
call assert_equal([expect3], prop_list(3))
|
call assert_equal([expect3], prop_list(3))
|
||||||
bwipe!
|
bwipe!
|
||||||
|
|
||||||
@@ -828,7 +859,7 @@ func Test_prop_undo()
|
|||||||
set ul&
|
set ul&
|
||||||
|
|
||||||
call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
|
call prop_add(1, 3, {'end_col': 5, 'type': 'comment'})
|
||||||
let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
" Insert a character, then undo.
|
" Insert a character, then undo.
|
||||||
@@ -872,7 +903,7 @@ func Test_prop_undo()
|
|||||||
" substitute a word, then undo
|
" substitute a word, then undo
|
||||||
call setline(1, 'the number 123 is highlighted.')
|
call setline(1, 'the number 123 is highlighted.')
|
||||||
call prop_add(1, 12, {'length': 3, 'type': 'comment'})
|
call prop_add(1, 12, {'length': 3, 'type': 'comment'})
|
||||||
let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
set ul&
|
set ul&
|
||||||
1s/number/foo
|
1s/number/foo
|
||||||
@@ -886,7 +917,7 @@ func Test_prop_undo()
|
|||||||
" substitute with backslash
|
" substitute with backslash
|
||||||
call setline(1, 'the number 123 is highlighted.')
|
call setline(1, 'the number 123 is highlighted.')
|
||||||
call prop_add(1, 12, {'length': 3, 'type': 'comment'})
|
call prop_add(1, 12, {'length': 3, 'type': 'comment'})
|
||||||
let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
1s/the/\The
|
1s/the/\The
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
@@ -912,22 +943,22 @@ func Test_prop_delete_text()
|
|||||||
|
|
||||||
" zero length property
|
" zero length property
|
||||||
call prop_add(1, 3, {'type': 'comment'})
|
call prop_add(1, 3, {'type': 'comment'})
|
||||||
let expected = [{'col': 3, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
" delete one char moves the property
|
" delete one char moves the property
|
||||||
normal! x
|
normal! x
|
||||||
let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
" delete char of the property has no effect
|
" delete char of the property has no effect
|
||||||
normal! lx
|
normal! lx
|
||||||
let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
" delete more chars moves property to first column, is not deleted
|
" delete more chars moves property to first column, is not deleted
|
||||||
normal! 0xxxx
|
normal! 0xxxx
|
||||||
let expected = [{'col': 1, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ]
|
let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ]
|
||||||
call assert_equal(expected, prop_list(1))
|
call assert_equal(expected, prop_list(1))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
@@ -1191,9 +1222,13 @@ func Test_proptype_substitute2()
|
|||||||
call prop_add(2, 1, {'length': 3, 'type': 'number'})
|
call prop_add(2, 1, {'length': 3, 'type': 'number'})
|
||||||
call prop_add(3, 36, {'length': 4, 'type': 'number'})
|
call prop_add(3, 36, {'length': 4, 'type': 'number'})
|
||||||
set ul&
|
set ul&
|
||||||
let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
|
let expected = [
|
||||||
\ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1},
|
\ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, start: 1},
|
||||||
\ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}]
|
\ #{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'number', length: 3, start: 1},
|
||||||
|
\ #{type_bufnr: 0, id: 0, col: 50, end: 1, type: 'number', length: 4, start: 1}]
|
||||||
|
|
||||||
|
" TODO
|
||||||
|
return
|
||||||
" Add some text in between
|
" Add some text in between
|
||||||
%s/\s\+/ /g
|
%s/\s\+/ /g
|
||||||
call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
|
call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3))
|
||||||
@@ -1298,11 +1333,11 @@ func Test_textprop_ins_str()
|
|||||||
call setline(1, 'just some text')
|
call setline(1, 'just some text')
|
||||||
call prop_type_add('test', {'highlight': 'ErrorMsg'})
|
call prop_type_add('test', {'highlight': 'ErrorMsg'})
|
||||||
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
|
call prop_add(1, 1, {'end_col': 2, 'type': 'test'})
|
||||||
call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1))
|
call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
|
||||||
|
|
||||||
call feedkeys("foi\<F8>\<Esc>", "tx")
|
call feedkeys("foi\<F8>\<Esc>", "tx")
|
||||||
call assert_equal('just s<F8>ome text', getline(1))
|
call assert_equal('just s<F8>ome text', getline(1))
|
||||||
call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1))
|
call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
call prop_remove({'type': 'test'})
|
call prop_remove({'type': 'test'})
|
||||||
@@ -1316,7 +1351,8 @@ func Test_find_prop_later_in_line()
|
|||||||
call prop_add(1, 1, {'length': 4, 'type': 'test'})
|
call prop_add(1, 1, {'length': 4, 'type': 'test'})
|
||||||
call prop_add(1, 10, {'length': 3, 'type': 'test'})
|
call prop_add(1, 10, {'length': 3, 'type': 'test'})
|
||||||
|
|
||||||
call assert_equal({'id': 0, 'lnum': 1, 'col': 10, 'end': 1, 'type': 'test', 'length': 3, 'start': 1},
|
call assert_equal(
|
||||||
|
\ #{type_bufnr: 0, id: 0, lnum: 1, col: 10, end: 1, type: 'test', length: 3, start: 1},
|
||||||
\ prop_find(#{type: 'test', lnum: 1, col: 6}))
|
\ prop_find(#{type: 'test', lnum: 1, col: 6}))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
@@ -1329,7 +1365,8 @@ func Test_find_zerowidth_prop_sol()
|
|||||||
call setline(1, 'just some text')
|
call setline(1, 'just some text')
|
||||||
call prop_add(1, 1, {'length': 0, 'type': 'test'})
|
call prop_add(1, 1, {'length': 0, 'type': 'test'})
|
||||||
|
|
||||||
call assert_equal({'id': 0, 'lnum': 1, 'col': 1, 'end': 1, 'type': 'test', 'length': 0, 'start': 1},
|
call assert_equal(
|
||||||
|
\ #{type_bufnr: 0, id: 0, lnum: 1, col: 1, end: 1, type: 'test', length: 0, start: 1},
|
||||||
\ prop_find(#{type: 'test', lnum: 1}))
|
\ prop_find(#{type: 'test', lnum: 1}))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
@@ -1386,14 +1423,16 @@ func Test_prop_split_join()
|
|||||||
|
|
||||||
" Split in middle of "some"
|
" Split in middle of "some"
|
||||||
execute "normal! 8|i\<CR>"
|
execute "normal! 8|i\<CR>"
|
||||||
call assert_equal([{'id': 0, 'col': 6, 'end': 0, 'type': 'test', 'length': 2, 'start': 1}],
|
call assert_equal(
|
||||||
|
\ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}],
|
||||||
\ prop_list(1))
|
\ prop_list(1))
|
||||||
call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 2, 'start': 0}],
|
call assert_equal(
|
||||||
|
\ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}],
|
||||||
\ prop_list(2))
|
\ prop_list(2))
|
||||||
|
|
||||||
" Join the two lines back together
|
" Join the two lines back together
|
||||||
normal! 1GJ
|
normal! 1GJ
|
||||||
call assert_equal([{'id': 0, 'col': 6, 'end': 1, 'type': 'test', 'length': 5, 'start': 1}], prop_list(1))
|
call assert_equal([#{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'test', length: 5, start: 1}], prop_list(1))
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
call prop_type_delete('test')
|
call prop_type_delete('test')
|
||||||
@@ -1408,12 +1447,12 @@ func Test_prop_increment_decrement()
|
|||||||
exe "normal! 0f9\<C-A>"
|
exe "normal! 0f9\<C-A>"
|
||||||
eval getline(1)->assert_equal('its 999 times')
|
eval getline(1)->assert_equal('its 999 times')
|
||||||
eval prop_list(1)->assert_equal([
|
eval prop_list(1)->assert_equal([
|
||||||
\ #{id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
|
\ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}])
|
||||||
|
|
||||||
exe "normal! 0f9\<C-A>"
|
exe "normal! 0f9\<C-A>"
|
||||||
eval getline(1)->assert_equal('its 1000 times')
|
eval getline(1)->assert_equal('its 1000 times')
|
||||||
eval prop_list(1)->assert_equal([
|
eval prop_list(1)->assert_equal([
|
||||||
\ #{id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
|
\ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}])
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
call prop_type_delete('test')
|
call prop_type_delete('test')
|
||||||
@@ -1429,7 +1468,7 @@ func Test_prop_block_insert()
|
|||||||
" insert "xx" in the first column of both lines
|
" insert "xx" in the first column of both lines
|
||||||
exe "normal! gg0\<C-V>jIxx\<Esc>"
|
exe "normal! gg0\<C-V>jIxx\<Esc>"
|
||||||
eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
|
eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo '])
|
||||||
let expected = [#{id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
|
let expected = [#{type_bufnr: 0, id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}]
|
||||||
eval prop_list(1)->assert_equal(expected)
|
eval prop_list(1)->assert_equal(expected)
|
||||||
eval prop_list(2)->assert_equal(expected)
|
eval prop_list(2)->assert_equal(expected)
|
||||||
|
|
||||||
@@ -1510,5 +1549,37 @@ def Test_prop_add_delete_line()
|
|||||||
bwipe!
|
bwipe!
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
" Buffer number of 0 should be ignored, as if the parameter wasn't passed.
|
||||||
|
def Test_prop_bufnr_zero()
|
||||||
|
new
|
||||||
|
try
|
||||||
|
var bufnr = bufnr('')
|
||||||
|
setline(1, 'hello')
|
||||||
|
prop_type_add('bufnr-global', {highlight: 'ErrorMsg'})
|
||||||
|
prop_type_add('bufnr-buffer', {highlight: 'StatusLine', bufnr: bufnr})
|
||||||
|
|
||||||
|
prop_add(1, 1, {type: 'bufnr-global', length: 1})
|
||||||
|
prop_add(1, 2, {type: 'bufnr-buffer', length: 1})
|
||||||
|
|
||||||
|
var list = prop_list(1)
|
||||||
|
assert_equal([
|
||||||
|
{id: 0, col: 1, type_bufnr: 0, end: 1, type: 'bufnr-global', length: 1, start: 1},
|
||||||
|
{id: 0, col: 2, type_bufnr: bufnr, end: 1, type: 'bufnr-buffer', length: 1, start: 1},
|
||||||
|
], list)
|
||||||
|
|
||||||
|
assert_equal(
|
||||||
|
{highlight: 'ErrorMsg', end_incl: 0, start_incl: 0, priority: 0, combine: 1},
|
||||||
|
prop_type_get('bufnr-global', {bufnr: list[0].type_bufnr}))
|
||||||
|
|
||||||
|
assert_equal(
|
||||||
|
{highlight: 'StatusLine', end_incl: 0, start_incl: 0, priority: 0, bufnr: bufnr, combine: 1},
|
||||||
|
prop_type_get('bufnr-buffer', {bufnr: list[1].type_bufnr}))
|
||||||
|
finally
|
||||||
|
bwipe!
|
||||||
|
prop_type_delete('bufnr-global')
|
||||||
|
endtry
|
||||||
|
enddef
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
@@ -140,7 +140,8 @@ get_bufnr_from_arg(typval_T *arg, buf_T **buf)
|
|||||||
if (arg->vval.v_dict == NULL)
|
if (arg->vval.v_dict == NULL)
|
||||||
return OK; // NULL dict is like an empty dict
|
return OK; // NULL dict is like an empty dict
|
||||||
di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
|
di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1);
|
||||||
if (di != NULL)
|
if (di != NULL && (di->di_tv.v_type != VAR_NUMBER
|
||||||
|
|| di->di_tv.vval.v_number != 0))
|
||||||
{
|
{
|
||||||
*buf = get_buf_arg(&di->di_tv);
|
*buf = get_buf_arg(&di->di_tv);
|
||||||
if (*buf == NULL)
|
if (*buf == NULL)
|
||||||
@@ -506,15 +507,27 @@ find_type_by_id(hashtab_T *ht, int id)
|
|||||||
prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf)
|
prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf)
|
||||||
{
|
{
|
||||||
proptype_T *pt;
|
proptype_T *pt;
|
||||||
|
int buflocal = TRUE;
|
||||||
|
|
||||||
dict_add_number(dict, "col", prop->tp_col);
|
dict_add_number(dict, "col", prop->tp_col);
|
||||||
dict_add_number(dict, "length", prop->tp_len);
|
dict_add_number(dict, "length", prop->tp_len);
|
||||||
dict_add_number(dict, "id", prop->tp_id);
|
dict_add_number(dict, "id", prop->tp_id);
|
||||||
dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV));
|
dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV));
|
||||||
dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT));
|
dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT));
|
||||||
pt = text_prop_type_by_id(buf, prop->tp_type);
|
|
||||||
|
pt = find_type_by_id(buf->b_proptypes, prop->tp_type);
|
||||||
|
if (pt == NULL)
|
||||||
|
{
|
||||||
|
pt = find_type_by_id(global_proptypes, prop->tp_type);
|
||||||
|
buflocal = FALSE;
|
||||||
|
}
|
||||||
if (pt != NULL)
|
if (pt != NULL)
|
||||||
dict_add_string(dict, "type", pt->pt_name);
|
dict_add_string(dict, "type", pt->pt_name);
|
||||||
|
|
||||||
|
if (buflocal)
|
||||||
|
dict_add_number(dict, "type_bufnr", buf->b_fnum);
|
||||||
|
else
|
||||||
|
dict_add_number(dict, "type_bufnr", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1159,7 +1172,7 @@ f_prop_type_delete(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* prop_type_get({name} [, {bufnr}])
|
* prop_type_get({name} [, {props}])
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
f_prop_type_get(typval_T *argvars, typval_T *rettv)
|
f_prop_type_get(typval_T *argvars, typval_T *rettv)
|
||||||
|
@@ -755,6 +755,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3233,
|
||||||
/**/
|
/**/
|
||||||
3232,
|
3232,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user