To: vim_dev@googlegroups.com Subject: Patch 8.2.3233 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3233 Problem: prop_list() and prop_find() do not indicate the buffer for the used type. Solution: Add "type_bufnr" to the results. (closes #8647) Files: runtime/doc/textprop.txt, src/testdir/test_textprop.vim, src/textprop.c *** ../vim-8.2.3232/runtime/doc/textprop.txt 2021-03-27 22:07:21.529728904 +0100 --- runtime/doc/textprop.txt 2021-07-28 12:11:09.298032541 +0200 *************** *** 211,216 **** --- 211,218 ---- id property ID type name of the property type, omitted if 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 end when TRUE property ends in this line *** ../vim-8.2.3232/src/testdir/test_textprop.vim 2021-07-10 13:15:35.295053013 +0200 --- src/testdir/test_textprop.vim 2021-07-28 12:11:09.298032541 +0200 *************** *** 39,45 **** func Test_proptype_buf() let bufnr = bufnr('') ! call prop_type_add('comment', {'bufnr': bufnr, 'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1}) let proptypes = prop_type_list({'bufnr': bufnr}) call assert_equal(1, len(proptypes)) call assert_equal('comment', proptypes[0]) --- 39,45 ---- func Test_proptype_buf() let bufnr = bufnr('') ! call prop_type_add('comment', #{bufnr: bufnr, highlight: 'Directory', priority: 123, start_incl: 1, end_incl: 1}) let proptypes = prop_type_list({'bufnr': bufnr}) call assert_equal(1, len(proptypes)) call assert_equal('comment', proptypes[0]) *************** *** 70,75 **** --- 70,105 ---- call assert_fails("call prop_type_add('one', {'bufnr': 98764})", "E158:") 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() call prop_type_add('one', {}) call prop_type_add('two', {}) *************** *** 94,120 **** func Get_expected_props() return [ ! \ {'col': 1, 'length': 13, 'id': 14, 'type': 'whole', 'start': 1, 'end': 1}, ! \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, ! \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, ! \ {'col': 9, 'length': 5, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, \ ] endfunc func Test_prop_find() new call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) ! ! " Add two text props on lines 1 and 5, and one spanning lines 2 to 4. call prop_type_add('prop_name', {'highlight': 'Directory'}) call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) let expected = [ ! \ {'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}, ! \ {'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. --- 124,150 ---- func Get_expected_props() return [ ! \ #{type_bufnr: 0, col: 1, length: 13, id: 14, type: 'whole', start: 1, end: 1}, ! \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, ! \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', start: 1, end: 1}, ! \ #{type_bufnr: 0, col: 9, length: 5, id: 13, type: 'three', start: 1, end: 1}, \ ] endfunc func Test_prop_find() new call setline(1, ['one one one', 'twotwo', 'three', 'fourfour', 'five', 'sixsix']) ! ! " Add two text props on lines 1 and 5, and one spanning lines 2 to 4. call prop_type_add('prop_name', {'highlight': 'Directory'}) call prop_add(1, 5, {'type': 'prop_name', 'id': 10, 'length': 3}) call prop_add(2, 4, {'type': 'prop_name', 'id': 11, 'end_lnum': 4, 'end_col': 9}) call prop_add(5, 4, {'type': 'prop_name', 'id': 12, 'length': 1}) let expected = [ ! \ #{type_bufnr: 0, lnum: 1, col: 5, length: 3, id: 10, type: 'prop_name', start: 1, end: 1}, ! \ #{type_bufnr: 0, lnum: 2, col: 4, id: 11, type: 'prop_name', start: 1, end: 0}, ! \ #{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. *************** *** 184,190 **** let lnum = result.lnum let col = result.col let i = i - 1 ! endwhile " Starting from line 6 col 1 search backwards for prop with id 10. call cursor(6,1) --- 214,220 ---- let lnum = result.lnum let col = result.col let i = i - 1 ! endwhile " Starting from line 6 col 1 search backwards for prop with id 10. call cursor(6,1) *************** *** 226,232 **** endfor endfor cursor(1, 8) ! var expected = {lnum: 1, id: 0, col: 14, end: 1, type: 'misspell', length: 2, start: 1} var result = prop_find({type: 'misspell', skipstart: true}, 'f') assert_equal(expected, result) --- 256,262 ---- endfor endfor cursor(1, 8) ! 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') assert_equal(expected, result) *************** *** 239,245 **** call prop_type_add('test', {'highlight': 'ErrorMsg'}) call setline(1, ['xxxx', 'x']) call prop_add(1, 4, {'type': 'test'}) ! call assert_equal({'id': 0, 'lnum': 1, 'col': 4, 'type': 'test', 'length': 0, 'start': 1, 'end': 1}, \ prop_find({'type': 'test', 'lnum': 2, 'col': 1}, 'b')) bwipe! call prop_type_delete('test') --- 269,276 ---- call prop_type_add('test', {'highlight': 'ErrorMsg'}) call setline(1, ['xxxx', 'x']) call prop_add(1, 4, {'type': 'test'}) ! 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')) bwipe! call prop_type_delete('test') *************** *** 272,278 **** call assert_equal(expected_props, prop_list(1)) call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') ! " Insert a line above, text props must still be there. call append(0, 'empty') call assert_equal(expected_props, prop_list(2)) --- 303,309 ---- call assert_equal(expected_props, prop_list(1)) call assert_fails("call prop_add(10, 1, {'length': 1, 'id': 14, 'type': 'whole'})", 'E966:') call assert_fails("call prop_add(1, 22, {'length': 1, 'id': 14, 'type': 'whole'})", 'E964:') ! " Insert a line above, text props must still be there. call append(0, 'empty') call assert_equal(expected_props, prop_list(2)) *************** *** 284,295 **** call prop_clear(1) call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) call prop_add(1, 5, #{type: 'included'}) ! let expected = [#{col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}] call assert_equal(expected, prop_list(1)) " Inserting text makes the prop bigger. exe "normal 5|ixx\" ! let expected = [#{col: 5, length: 2, type: 'included', id: 0, start: 1, end: 1}] call assert_equal(expected, prop_list(1)) call assert_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') --- 315,326 ---- call prop_clear(1) call prop_type_add('included', {'start_incl': 1, 'end_incl': 1}) call prop_add(1, 5, #{type: 'included'}) ! let expected = [#{type_bufnr: 0, col: 5, length: 0, type: 'included', id: 0, start: 1, end: 1}] call assert_equal(expected, prop_list(1)) " Inserting text makes the prop bigger. exe "normal 5|ixx\" ! 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_fails("call prop_add(1, 5, {'type': 'two', 'bufnr': 234343})", 'E158:') *************** *** 327,333 **** call SetupPropsInFirstLine() call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) let props = Get_expected_props() ! call insert(props, {'col': 6, 'length': 2, 'id': 11, 'type': 'three', 'start': 1, 'end': 1}, 3) call assert_equal(props, prop_list(1)) call assert_equal(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) unlet props[3] --- 358,364 ---- call SetupPropsInFirstLine() call prop_add(1, 6, {'length': 2, 'id': 11, 'type': 'three'}) let props = Get_expected_props() ! 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(1, prop_remove({'type': 'three', 'id': 11, 'both': 1, 'all': 1}, 1)) unlet props[3] *************** *** 367,374 **** call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) let expected = [ ! \ {'col': 2, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, ! \ {'col': 8, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, \] call assert_equal(expected, prop_list(1)) return expected --- 398,405 ---- call prop_add(1, 2, {'length': 3, 'id': 11, 'type': 'one'}) call prop_add(1, 8, {'length': 3, 'id': 12, 'type': 'two'}) let expected = [ ! \ #{type_bufnr: 0, col: 2, length: 3, id: 11, type: 'one', 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)) return expected *************** *** 389,397 **** endfor let props = [ ! \ {'col': 1, 'length': 3, 'id': 11, 'type': 'one', 'start': 1, 'end': 1}, ! \ {'col': 5, 'length': 3, 'id': 12, 'type': 'two', 'start': 1, 'end': 1}, ! \ {'col': 11, 'length': 3, 'id': 13, 'type': 'three', 'start': 1, 'end': 1}, \] call assert_equal(props, prop_list(1, {'bufnr': bufnr})) --- 420,428 ---- endfor let props = [ ! \ #{type_bufnr: 0, col: 1, length: 3, id: 11, type: 'one', start: 1, end: 1}, ! \ #{type_bufnr: 0, col: 5, length: 3, id: 12, type: 'two', 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})) *************** *** 658,664 **** new call setline(1, [' xxx', 'yyyyy']) call prop_add(2, 2, {'length': 2, 'type': 'comment'}) ! let expect = {'col': 2, 'length': 2, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} call assert_equal([expect], prop_list(2)) set shiftwidth=3 --- 689,695 ---- new call setline(1, [' xxx', 'yyyyy']) call prop_add(2, 2, {'length': 2, 'type': 'comment'}) ! let expect = #{type_bufnr: 0, col: 2, length: 2, type: 'comment', start: 1, end: 1, id: 0} call assert_equal([expect], prop_list(2)) set shiftwidth=3 *************** *** 704,714 **** " start halfway line 1, end halfway line 3 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} call assert_equal([expect1], prop_list(1)) ! let expect2 = {'col': 1, 'length': 10, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} call assert_equal([expect2], prop_list(2)) ! let expect3 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} call assert_equal([expect3], prop_list(3)) call prop_clear(1, 3) --- 735,745 ---- " start halfway line 1, end halfway line 3 call prop_add(1, 3, {'end_lnum': 3, 'end_col': 5, 'type': 'comment'}) ! let expect1 = #{type_bufnr: 0, col: 3, length: 6, type: 'comment', start: 1, end: 0, id: 0} call assert_equal([expect1], prop_list(1)) ! let expect2 = #{type_bufnr: 0, col: 1, length: 10, type: 'comment', start: 0, end: 0, id: 0} call assert_equal([expect2], prop_list(2)) ! 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 prop_clear(1, 3) *************** *** 726,746 **** " Test deleting the first line of a multi-line prop. call Setup_three_line_prop() ! let expect_short = {'col': 2, 'length': 1, 'type': 'comment', 'start': 1, 'end': 1, 'id': 0} call assert_equal([expect_short], prop_list(1)) ! let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} call assert_equal([expect2], prop_list(2)) 2del call assert_equal([expect_short], prop_list(1)) ! let expect2 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} call assert_equal([expect2], prop_list(2)) bwipe! " Test deleting the last line of a multi-line prop. call Setup_three_line_prop() ! let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} call assert_equal([expect3], prop_list(3)) ! let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0} call assert_equal([expect4], prop_list(4)) 4del let expect3.end = 1 --- 757,777 ---- " Test deleting the first line of a multi-line prop. call Setup_three_line_prop() ! 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)) ! let expect2 = #{type_bufnr: 0, col: 4, length: 4, type: 'comment', start: 1, end: 0, id: 0} call assert_equal([expect2], prop_list(2)) 2del call assert_equal([expect_short], prop_list(1)) ! let expect2 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 1, end: 0, id: 0} call assert_equal([expect2], prop_list(2)) bwipe! " Test deleting the last line of a multi-line prop. call Setup_three_line_prop() ! let expect3 = #{type_bufnr: 0, col: 1, length: 6, type: 'comment', start: 0, end: 0, id: 0} call assert_equal([expect3], prop_list(3)) ! let expect4 = #{type_bufnr: 0, col: 1, length: 4, type: 'comment', start: 0, end: 1, id: 0} call assert_equal([expect4], prop_list(4)) 4del let expect3.end = 1 *************** *** 750,760 **** " Test appending a line below the multi-line text prop start. call Setup_three_line_prop() ! let expect2 = {'col': 4, 'length': 4, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0} call assert_equal([expect2], prop_list(2)) call append(2, "new line") call assert_equal([expect2], prop_list(2)) ! let expect3 = {'col': 1, 'length': 9, 'type': 'comment', 'start': 0, 'end': 0, 'id': 0} call assert_equal([expect3], prop_list(3)) bwipe! --- 781,791 ---- " Test appending a line below the multi-line text prop start. call Setup_three_line_prop() ! 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 append(2, "new line") call assert_equal([expect2], prop_list(2)) ! let expect3 = #{type_bufnr: 0, col: 1, length: 9, type: 'comment', start: 0, end: 0, id: 0} call assert_equal([expect3], prop_list(3)) bwipe! *************** *** 828,834 **** set ul& call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) ! let expected = [{'col': 3, 'length': 2, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) " Insert a character, then undo. --- 859,865 ---- set ul& call prop_add(1, 3, {'end_col': 5, 'type': 'comment'}) ! let expected = [#{type_bufnr: 0, col: 3, length: 2, id: 0, type: 'comment', start: 1, end: 1}] call assert_equal(expected, prop_list(1)) " Insert a character, then undo. *************** *** 872,878 **** " substitute a word, then undo call setline(1, 'the number 123 is highlighted.') call prop_add(1, 12, {'length': 3, 'type': 'comment'}) ! let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) set ul& 1s/number/foo --- 903,909 ---- " substitute a word, then undo call setline(1, 'the number 123 is highlighted.') call prop_add(1, 12, {'length': 3, 'type': 'comment'}) ! let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) set ul& 1s/number/foo *************** *** 886,892 **** " substitute with backslash call setline(1, 'the number 123 is highlighted.') call prop_add(1, 12, {'length': 3, 'type': 'comment'}) ! let expected = [{'col': 12, 'length': 3, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) 1s/the/\The call assert_equal(expected, prop_list(1)) --- 917,923 ---- " substitute with backslash call setline(1, 'the number 123 is highlighted.') call prop_add(1, 12, {'length': 3, 'type': 'comment'}) ! let expected = [#{type_bufnr: 0, col: 12, length: 3, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) 1s/the/\The call assert_equal(expected, prop_list(1)) *************** *** 912,933 **** " zero length property call prop_add(1, 3, {'type': 'comment'}) ! let expected = [{'col': 3, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) " delete one char moves the property normal! x ! let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) " delete char of the property has no effect normal! lx ! let expected = [{'col': 2, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) " delete more chars moves property to first column, is not deleted normal! 0xxxx ! let expected = [{'col': 1, 'length': 0, 'id': 0, 'type': 'comment', 'start': 1, 'end': 1} ] call assert_equal(expected, prop_list(1)) bwipe! --- 943,964 ---- " zero length property call prop_add(1, 3, {'type': 'comment'}) ! let expected = [#{type_bufnr: 0, col: 3, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) " delete one char moves the property normal! x ! let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) " delete char of the property has no effect normal! lx ! let expected = [#{type_bufnr: 0, col: 2, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) " delete more chars moves property to first column, is not deleted normal! 0xxxx ! let expected = [#{type_bufnr: 0, col: 1, length: 0, id: 0, type: 'comment', start: 1, end: 1} ] call assert_equal(expected, prop_list(1)) bwipe! *************** *** 1191,1202 **** call prop_add(2, 1, {'length': 3, 'type': 'number'}) call prop_add(3, 36, {'length': 4, 'type': 'number'}) set ul& ! let expected = [{'id': 0, 'col': 13, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, ! \ {'id': 0, 'col': 1, 'end': 1, 'type': 'number', 'length': 3, 'start': 1}, ! \ {'id': 0, 'col': 50, 'end': 1, 'type': 'number', 'length': 4, 'start': 1}] " Add some text in between %s/\s\+/ /g ! call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) " remove some text :1s/[a-z]\{3\}//g --- 1222,1237 ---- call prop_add(2, 1, {'length': 3, 'type': 'number'}) call prop_add(3, 36, {'length': 4, 'type': 'number'}) set ul& ! let expected = [ ! \ #{type_bufnr: 0, id: 0, col: 13, end: 1, type: 'number', length: 3, 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 %s/\s\+/ /g ! call assert_equal(expected, prop_list(1) + prop_list(2) + prop_list(3)) " remove some text :1s/[a-z]\{3\}//g *************** *** 1298,1308 **** call setline(1, 'just some text') call prop_type_add('test', {'highlight': 'ErrorMsg'}) 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 feedkeys("foi\\", "tx") call assert_equal('just some text', getline(1)) ! call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 1, 'start': 1}], prop_list(1)) bwipe! call prop_remove({'type': 'test'}) --- 1333,1343 ---- call setline(1, 'just some text') call prop_type_add('test', {'highlight': 'ErrorMsg'}) call prop_add(1, 1, {'end_col': 2, 'type': 'test'}) ! call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1)) call feedkeys("foi\\", "tx") call assert_equal('just some text', getline(1)) ! call assert_equal([#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 1, start: 1}], prop_list(1)) bwipe! call prop_remove({'type': 'test'}) *************** *** 1316,1323 **** call prop_add(1, 1, {'length': 4, '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}, ! \ prop_find(#{type: 'test', lnum: 1, col: 6})) bwipe! call prop_type_delete('test') --- 1351,1359 ---- call prop_add(1, 1, {'length': 4, 'type': 'test'}) call prop_add(1, 10, {'length': 3, 'type': 'test'}) ! 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})) bwipe! call prop_type_delete('test') *************** *** 1329,1336 **** call setline(1, 'just some text') 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}, ! \ prop_find(#{type: 'test', lnum: 1})) bwipe! call prop_type_delete('test') --- 1365,1373 ---- call setline(1, 'just some text') call prop_add(1, 1, {'length': 0, 'type': 'test'}) ! 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})) bwipe! call prop_type_delete('test') *************** *** 1386,1399 **** " Split in middle of "some" execute "normal! 8|i\" ! call assert_equal([{'id': 0, 'col': 6, 'end': 0, 'type': 'test', 'length': 2, 'start': 1}], ! \ prop_list(1)) ! call assert_equal([{'id': 0, 'col': 1, 'end': 1, 'type': 'test', 'length': 2, 'start': 0}], ! \ prop_list(2)) " Join the two lines back together normal! 1GJ ! call assert_equal([{'id': 0, 'col': 6, 'end': 1, 'type': 'test', 'length': 5, 'start': 1}], prop_list(1)) bwipe! call prop_type_delete('test') --- 1423,1438 ---- " Split in middle of "some" execute "normal! 8|i\" ! call assert_equal( ! \ [#{type_bufnr: 0, id: 0, col: 6, end: 0, type: 'test', length: 2, start: 1}], ! \ prop_list(1)) ! call assert_equal( ! \ [#{type_bufnr: 0, id: 0, col: 1, end: 1, type: 'test', length: 2, start: 0}], ! \ prop_list(2)) " Join the two lines back together normal! 1GJ ! call assert_equal([#{type_bufnr: 0, id: 0, col: 6, end: 1, type: 'test', length: 5, start: 1}], prop_list(1)) bwipe! call prop_type_delete('test') *************** *** 1408,1419 **** exe "normal! 0f9\" eval getline(1)->assert_equal('its 999 times') eval prop_list(1)->assert_equal([ ! \ #{id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}]) exe "normal! 0f9\" eval getline(1)->assert_equal('its 1000 times') eval prop_list(1)->assert_equal([ ! \ #{id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}]) bwipe! call prop_type_delete('test') --- 1447,1458 ---- exe "normal! 0f9\" eval getline(1)->assert_equal('its 999 times') eval prop_list(1)->assert_equal([ ! \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 3, start: 1}]) exe "normal! 0f9\" eval getline(1)->assert_equal('its 1000 times') eval prop_list(1)->assert_equal([ ! \ #{type_bufnr: 0, id: 0, col: 5, end: 1, type: 'test', length: 4, start: 1}]) bwipe! call prop_type_delete('test') *************** *** 1429,1435 **** " insert "xx" in the first column of both lines exe "normal! gg0\jIxx\" eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) ! let expected = [#{id: 0, col: 3, end: 1, type: 'test', length: 3, start: 1}] eval prop_list(1)->assert_equal(expected) eval prop_list(2)->assert_equal(expected) --- 1468,1474 ---- " insert "xx" in the first column of both lines exe "normal! gg0\jIxx\" eval getline(1, 2)->assert_equal(['xxone ', 'xxtwo ']) ! 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(2)->assert_equal(expected) *************** *** 1510,1514 **** --- 1549,1585 ---- bwipe! 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-8.2.3232/src/textprop.c 2021-07-27 22:00:39.753712380 +0200 --- src/textprop.c 2021-07-28 13:26:30.933334738 +0200 *************** *** 140,146 **** if (arg->vval.v_dict == NULL) return OK; // NULL dict is like an empty dict di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); ! if (di != NULL) { *buf = get_buf_arg(&di->di_tv); if (*buf == NULL) --- 140,147 ---- if (arg->vval.v_dict == NULL) return OK; // NULL dict is like an empty dict di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); ! if (di != NULL && (di->di_tv.v_type != VAR_NUMBER ! || di->di_tv.vval.v_number != 0)) { *buf = get_buf_arg(&di->di_tv); if (*buf == NULL) *************** *** 506,520 **** prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf) { proptype_T *pt; dict_add_number(dict, "col", prop->tp_col); dict_add_number(dict, "length", prop->tp_len); dict_add_number(dict, "id", prop->tp_id); dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV)); dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT)); ! pt = text_prop_type_by_id(buf, prop->tp_type); if (pt != NULL) dict_add_string(dict, "type", pt->pt_name); } /* --- 507,533 ---- prop_fill_dict(dict_T *dict, textprop_T *prop, buf_T *buf) { proptype_T *pt; + int buflocal = TRUE; dict_add_number(dict, "col", prop->tp_col); dict_add_number(dict, "length", prop->tp_len); dict_add_number(dict, "id", prop->tp_id); dict_add_number(dict, "start", !(prop->tp_flags & TP_FLAG_CONT_PREV)); dict_add_number(dict, "end", !(prop->tp_flags & TP_FLAG_CONT_NEXT)); ! ! 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) 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,1165 **** } /* ! * prop_type_get({name} [, {bufnr}]) */ void f_prop_type_get(typval_T *argvars, typval_T *rettv) --- 1172,1178 ---- } /* ! * prop_type_get({name} [, {props}]) */ void f_prop_type_get(typval_T *argvars, typval_T *rettv) *** ../vim-8.2.3232/src/version.c 2021-07-28 11:51:44.321061719 +0200 --- src/version.c 2021-07-28 13:22:53.357729236 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3233, /**/ -- hundred-and-one symptoms of being an internet addict: 262. Your computer has it's own phone line - but your daughter doesn't. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///