diff options
Diffstat (limited to 'lua/lexers/lexer.lua')
| -rw-r--r-- | lua/lexers/lexer.lua | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lua/lexers/lexer.lua b/lua/lexers/lexer.lua index b896344..d159f70 100644 --- a/lua/lexers/lexer.lua +++ b/lua/lexers/lexer.lua @@ -1,4 +1,4 @@ --- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE. +-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE. local M = {} @@ -566,13 +566,14 @@ local M = {} -- `_foldsymbols` table must have a `_patterns` field that contains a list of -- [Lua patterns][] that match fold points. If the lexer encounters text that -- matches one of those patterns, the lexer looks up the matched text in its --- token's table to determine whether or not the text is a fold point. In the --- example above, the first Lua pattern matches any '{' or '}' characters. When --- the lexer comes across one of those characters, it checks if the match is an --- `lexer.OPERATOR` token. If so, the lexer identifies the match as a fold --- point. The same idea applies for the other patterns. (The '%' is in the other --- patterns because '\*' is a special character in Lua patterns that needs --- escaping.) How do you specify fold keywords? Here is an example for Lua: +-- token's table in order to determine whether or not the text is a fold point. +-- In the example above, the first Lua pattern matches any '{' or '}' +-- characters. When the lexer comes across one of those characters, it checks if +-- the match is an `lexer.OPERATOR` token. If so, the lexer identifies the match +-- as a fold point. The same idea applies for the other patterns. (The '%' is in +-- the other patterns because '\*' is a special character in Lua patterns that +-- needs escaping.) How do you specify fold keywords? Here is an example for +-- Lua: -- -- M._foldsymbols = { -- [l.KEYWORD] = { @@ -586,6 +587,10 @@ local M = {} -- `lexer.KEYWORD` token and in the associated list of fold points, the lexer -- identifies the word as a fold point. -- +-- If your lexer has case-insensitive keywords as fold points, simply add a +-- `_case_insensitive = true` option to the `_foldsymbols` table and specify +-- keywords in lower case. +-- -- If your lexer needs to do some additional processing to determine if a match -- is a fold point, assign a function that returns an integer. Returning `1` or -- `-1` indicates the match is a fold point. Returning `0` indicates it is not. @@ -785,6 +790,8 @@ local M = {} -- @field STYLE_CALLTIP (string) -- The style used by call tips if [`buffer.call_tip_use_style`]() is set. -- Only the font name, size, and color attributes are used. +-- @field STYLE_FOLDDISPLAYTEXT (string) +-- The style used for fold display text. -- @field any (pattern) -- A pattern that matches any single character. -- @field ascii (pattern) @@ -1002,7 +1009,7 @@ end -- Predefined styles. local predefined = { 'default', 'linenumber', 'bracelight', 'bracebad', 'controlchar', - 'indentguide', 'calltip' + 'indentguide', 'calltip', 'folddisplaytext' } for i = 1, #predefined do local name, upper_name = predefined[i], string_upper(predefined[i]) @@ -1182,12 +1189,14 @@ function M.fold(lexer, text, start_pos, start_line, start_level) local fold_zero_sum_lines = M.property_int['fold.on.zero.sum.lines'] > 0 local fold_symbols = lexer._foldsymbols local fold_symbols_patterns = fold_symbols._patterns + local fold_symbols_case_insensitive = fold_symbols._case_insensitive local style_at, fold_level = M.style_at, M.fold_level local line_num, prev_level = start_line, start_level local current_level = prev_level for i = 1, #lines do local pos, line = lines[i][1], lines[i][2] if line ~= '' then + if fold_symbols_case_insensitive then line = line:lower() end local level_decreased = false for j = 1, #fold_symbols_patterns do for s, match in line:gmatch(fold_symbols_patterns[j]) do @@ -1605,11 +1614,14 @@ local function line_from_position(pos) end -- point and a value of `-1` indicates an ending fold point. Values can also -- be functions that return `1`, `-1`, or `0` (indicating no fold point) for -- keys which need additional processing. --- There is also a required `_pattern` key whose value is a table containing +-- There is also a required `_patterns` key whose value is a table containing -- Lua pattern strings that match all fold points (the string keys contained -- in token name table values). When the lexer encounters text that matches -- one of those patterns, the matched text is looked up in its token's table -- to determine whether or not it is a fold point. +-- There is also an optional `_case_insensitive` option that indicates whether +-- or not fold point keys are case-insensitive. If `true`, fold point keys +-- should be in lower case. -- @field _fold If this function exists in the lexer, it is called for folding -- the document instead of using `_foldsymbols` or indentation. -- @field _lexer The parent lexer object whose rules should be used. This field |
