diff options
author | 2015-09-14 21:01:20 -0400 | |
---|---|---|
committer | 2015-09-14 21:01:20 -0400 | |
commit | 617fd954819465fcc7182473be1e93abf8473122 (patch) | |
tree | 05575e58fc1fae38c6f50821e37d1a3fa3e2d695 /modules/textadept/editing.lua | |
parent | abbef02c055aa60fd3a3425fef61c32e9d4c1135 (diff) | |
download | textadept-617fd954819465fcc7182473be1e93abf8473122.tar.gz textadept-617fd954819465fcc7182473be1e93abf8473122.zip |
Improved apidoc lookup behind the caret; modules/textadept/editing.lua
Documentation for open functions is shown.
Diffstat (limited to 'modules/textadept/editing.lua')
-rw-r--r-- | modules/textadept/editing.lua | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index ac2ffe8a..7eb0b355 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -602,18 +602,32 @@ function M.show_documentation() local s = buffer:word_start_position(buffer.current_pos, true) local e = buffer:word_end_position(buffer.current_pos, true) local symbol = buffer:text_range(s, e) - if symbol == '' then return nil end + api_docs = {} - local symbol_patt = '^'..symbol:gsub('(%p)', '%%%1') - for i = 1, #M.api_files[lang] do - if lfs.attributes(M.api_files[lang][i]) then - for line in io.lines(M.api_files[lang][i]) do - if line:find(symbol_patt) then - api_docs[#api_docs + 1] = line:match(symbol_patt..'%s+(.+)$') + ::lookup:: + if symbol ~= '' then + local symbol_patt = '^'..symbol:gsub('(%p)', '%%%1') + for i = 1, #M.api_files[lang] do + if lfs.attributes(M.api_files[lang][i]) then + for line in io.lines(M.api_files[lang][i]) do + if line:find(symbol_patt) then + api_docs[#api_docs + 1] = line:match(symbol_patt..'%s+(.+)$') + end end end end end + -- Search backwards for an open function call and show API documentation for + -- that function as well. + local char_at = buffer.char_at + while s >= 0 and char_at[s] ~= 40 do s = s - 1 end + e = buffer:brace_match(s) + if s > 0 and (e == -1 or e >= buffer.current_pos) then + s, e = buffer:word_start_position(s - 1, true), s - 1 + symbol = buffer:text_range(s, e + 1) + goto lookup + end + if #api_docs == 0 then return end for i = 1, #api_docs do local doc = api_docs[i]:gsub('%f[\\]\\n', '\n'):gsub('\\\\', '\\') |