-*eval.txt* For Vim version 8.1. Last change: 2018 Dec 28
+*eval.txt* For Vim version 8.1. Last change: 2019 Jan 01
VIM REFERENCE MANUAL by Bram Moolenaar
<
*prop_add()* *E965*
prop_add({lnum}, {col}, {props})
- Attach a text property at position {lnum}, {col}. Use one for
- the first column.
+ Attach a text property at position {lnum}, {col}. {col} is
+ counted in bytes, use one for the first column.
If {lnum} is invalid an error is given. *E966*
If {col} is invalid an error is given. *E964*
{props} is a dictionary with these fields:
- length length of text in characters, can only be used
+ length length of text in bytes, can only be used
for a property that does not continue in
- another line
- end_lnum line number for end of text
- end_col last column of the text; not used when
- "length" is present
+ another line; can be zero
+ end_lnum line number for the end of text
+ end_col column just after the text; not used when "length"
+ is present; when {col} and "end_col" are equal
+ this is a zero-width text property
bufnr buffer to add the property to; when omitted
the current buffer is used
id user defined ID for the property; when omitted
All fields except "type" are optional.
It is an error when both "length" and "end_lnum" or "end_col"
- are passed. Either use "length" or "end_col" for a property
+ are given. Either use "length" or "end_col" for a property
within one line, or use "end_lnum" and "end_col" for a
property that spans more than one line.
- When neither "length" nor "end_col" are passed the property
- will apply to one character.
+ When neither "length" nor "end_col" are given the property
+ will be zero-width. That means it will not be highlighted but
+ will move with the text, as a kind of mark.
The property can end exactly at the last character of the
text, or just after it. In the last case, if text is appended
to the line, the text property size will increase, also when
source screendump.vim
+" test length zero
+
func Test_proptype_global()
call prop_type_add('comment', {'highlight': 'Directory', 'priority': 123, 'start_incl': 1, 'end_incl': 1})
let proptypes = prop_type_list()
1del
call assert_equal(s:expected_props, prop_list(1))
+ " Prop without length or end column is zero length
+ call prop_clear(1)
+ call prop_add(1, 5, {'type': 'two'})
+ let expected = [{'col': 5, 'length': 0, 'type': 'two', 'id': 0, 'start': 1, 'end': 1}]
+ call assert_equal(expected, prop_list(1))
+
call DeletePropTypes()
bwipe!
endfunc
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': 5, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
+ 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)
bwipe!
- " Test deleting the first line with a prop.
+ " 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
- 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': 1, 'length': 6, 'type': 'comment', 'start': 1, 'end': 0, 'id': 0}
call assert_equal([expect2], prop_list(2))
bwipe!
- " Test deleting the last line with a prop.
+ " 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': 5, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
+ let expect4 = {'col': 1, 'length': 4, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
call assert_equal([expect4], prop_list(4))
4del
- let expect3 = {'col': 1, 'length': 6, 'type': 'comment', 'start': 0, 'end': 1, 'id': 0}
+ let expect3.end = 1
call assert_equal([expect3], prop_list(3))
call assert_equal([expect_short], prop_list(4))
bwipe!
- " Test appending a line below the text prop start.
+ " 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))
" screenshot test with textprop highlighting
funct Test_textprop_screenshots()
- if !CanRunVimInTerminal()
+ if !CanRunVimInTerminal() || &encoding != 'utf-8'
return
endif
call writefile([
- \ "call setline(1, ['One two', 'Number 123 and then 4567.', 'Three'])",
+ \ "call setline(1, ['One two', 'Numbér 123 änd thœn 4¾7.', 'Three'])",
\ "hi NumberProp ctermfg=blue",
\ "hi LongProp ctermbg=yellow",
\ "call prop_type_add('number', {'highlight': 'NumberProp'})",
\ "call prop_type_add('long', {'highlight': 'LongProp'})",
\ "call prop_add(1, 4, {'end_lnum': 3, 'end_col': 3, 'type': 'long'})",
- \ "call prop_add(2, 8, {'length': 3, 'type': 'number'})",
- \ "call prop_add(2, 21, {'length': 4, 'type': 'number'})",
+ \ "call prop_add(2, 9, {'length': 3, 'type': 'number'})",
+ \ "call prop_add(2, 24, {'length': 4, 'type': 'number'})",
\ "set number",
+ \ "hi clear SpellBad",
\ "set spell",
\], 'XtestProp')
- let buf = RunVimInTerminal('-S XtestProp', {})
+ let buf = RunVimInTerminal('-S XtestProp', {'rows': 6})
call VerifyScreenDump(buf, 'Test_textprop_01', {})
" clean up
* Text properties have a type, which can be used to specify highlighting.
*
* TODO:
- * - Perhaps we only need TP_FLAG_CONT_NEXT ?
- * - Adjust text property column and length when text is inserted/deleted
+ * - Adjust text property column and length when text is inserted/deleted.
+ * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV?
* - Add an arrray for global_proptypes, to quickly lookup a prop type by ID
* - Add an arrray for b_proptypes, to quickly lookup a prop type by ID
* - Checking the text length to detect text properties is slow. Use a flag in
{
long length = dict_get_number(dict, (char_u *)"length");
- if (length < 1 || end_lnum > start_lnum)
+ if (length < 0 || end_lnum > start_lnum)
{
EMSG2(_(e_invargval), "length");
return;
}
- end_col = start_col + length - 1;
+ end_col = start_col + length;
}
else if (dict_find(dict, (char_u *)"end_col", -1) != NULL)
{
}
if (lnum == end_lnum)
- length = end_col - col + 1;
+ length = end_col - col;
else
length = textlen - col + 1;
if (length > (long)textlen)
- length = textlen; // can include the end-of-line
- if (length < 1)
- length = 1;
+ length = textlen; // can include the end-of-line
+ if (length < 0)
+ length = 0; // zero-width property
// Allocate the new line with space for the new proprety.
newtext = alloc(buf->b_ml.ml_line_len + sizeof(textprop_T));
buf->b_proptypes = NULL;
}
+/*
+ * Adjust the columns of text properties in line "lnum" after position "col" to
+ * shift by "bytes_added" (can be negative).
+ */
+ void
+adjust_prop_columns(linenr_T lnum UNUSED, colnr_T col UNUSED, int bytes_added UNUSED)
+{
+ // TODO
+}
+
#endif // FEAT_TEXT_PROP