Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

Commit

Permalink
Add keyword_pattern to helper.datemine's option
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed Dec 26, 2020
1 parent feec0ae commit 184ecc4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
7 changes: 6 additions & 1 deletion lua/compe/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ Helper.datermine = function(context, option)
end
end

local keyword_pattern_offset
if option.keyword_pattern then
keyword_pattern_offset = Pattern.get_pattern_offset(context.before_line, option.keyword_pattern)
end

return {
keyword_pattern_offset = Pattern.get_keyword_offset(context);
keyword_pattern_offset = keyword_pattern_offset or Pattern.get_keyword_offset(context);
trigger_character_offset = trigger_character_offset;
}
end
Expand Down
28 changes: 18 additions & 10 deletions lua/compe/pattern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,33 @@ Pattern.get_keyword_offset = function(context)

local s1, s2
if keyword_pattern == default_pattern then
s1 = Pattern.regex(keyword_pattern):match_str(context.before_line)
s1 = Pattern.get_pattern_offset(context.before_line, keyword_pattern)
s2 = s1
else
s1 = Pattern.regex(keyword_pattern):match_str(context.before_line)
s2 = Pattern.regex(default_pattern):match_str(context.before_line)
s1 = Pattern.get_pattern_offset(context.before_line, keyword_pattern)
s2 = Pattern.get_pattern_offset(context.before_line, default_pattern)
end

if s1 == nil and s2 == nil then
return 0
if s2 == 0 then
return s1
end
if s2 == nil then
return s1 + 1
if s1 == 0 then
return s2
end
if s1 == nil then
return s2 + 1
return math.min(s1, s2)
end

--- get_pattern_offset
Pattern.get_pattern_offset = function(before_line, pattern)
local regex = Pattern.regex(pattern)
local s = regex:match_str(before_line)
if s == nil then
return 0
end
return math.min(s1, s2) + 1
return s + 1
end


--- regex
Pattern.regex = function(pattern)
if not Pattern._regexes[pattern] then
Expand Down

0 comments on commit 184ecc4

Please sign in to comment.