aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2012-07-21 14:12:27 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2012-07-21 14:12:27 -0400
commit7db3af04cffe78db907d90330adf9929fa4cab32 (patch)
tree2b21d3be0700ab26e3efb1c9ba9ceee64e86db52
parent03f166897801c29e9357bce3214f02502eb7f252 (diff)
downloadtextadept-7db3af04cffe78db907d90330adf9929fa4cab32.tar.gz
textadept-7db3af04cffe78db907d90330adf9929fa4cab32.zip
More Lua code cleanup and API changes.
-rw-r--r--doc/14_Appendix.md20
-rw-r--r--modules/textadept/adeptsense.lua59
-rw-r--r--modules/textadept/keys.lua4
3 files changed, 42 insertions, 41 deletions
diff --git a/doc/14_Appendix.md b/doc/14_Appendix.md
index f577b0e6..3f86a43f 100644
--- a/doc/14_Appendix.md
+++ b/doc/14_Appendix.md
@@ -355,13 +355,31 @@ projects re-define or define their own search paths.
`_M.textadept.editing.prepare_for_save()` moved directly into an event handler
and cannot be called separately anymore.
-##### `session`
+##### Sessions
`_M.textadept.session.prompt_load()` and `_M.textadept.session.prompt_save()`
functionality has been moved into [`_M.textadept.session.load()`][] and
[`_M.textadept.session.save()`][]. Therefore, replace all instances of
`prompt_load` and `prompt_save` with `load` and `save` respectively.
+[`_M.textadept.session.load()`]: api/_M.textadept.session.html#load
+[`_M.textadept.session.save()`]: api/_M.textadept.session.html#save
+
+##### Adeptsense
+
+`_M.textadept.adeptsense.complete_symbol()` and
+`_M.textadept.adeptsense.show_documentation()` functionality has been moved into
+[`_M.textadept.adeptsense.complete()`][] and
+[`_M.textadept.adeptsense.show_apidoc()`][]. Therefore, replace all instances
+of `complete_symbol` and `show_documentation` with `complete` and `show_apidoc`.
+
+[`_M.textadept.adeptsense.complete()`]: api/_M.textadept.adeptsense.html#complete
+[`_M.textadept.adeptsense.show_apidoc()`]: api/_M.textadept.adeptsense.html#show_apidoc
+
+##### `user_dofile`
+
+`_G.user_dofile()` was removed. Use `dofile(_USERHOME..'/file.lua')` instead.
+
##### `gtkmenu`
`gui.gtkmenu()` was renamed to `gui.menu()`. Therefore, replace all instances of
diff --git a/modules/textadept/adeptsense.lua b/modules/textadept/adeptsense.lua
index 4979163c..627d885e 100644
--- a/modules/textadept/adeptsense.lua
+++ b/modules/textadept/adeptsense.lua
@@ -552,7 +552,8 @@ end
---
-- Shows an autocompletion list for the symbol behind the caret.
--- @param sense The Adeptsense returned by `adeptsense.new()`.
+-- @param sense The Adeptsense returned by `adeptsense.new()`. If `nil`, uses
+-- the current language's Adeptsense (if it exists).
-- @param only_fields If `true`, returns list of only fields. The default value
-- is `false`.
-- @param only_functions If `true`, returns list of only functions. The default
@@ -563,6 +564,8 @@ end
-- @name complete
function M.complete(sense, only_fields, only_functions)
local buffer = buffer
+ sense = sense or (_M[buffer:get_lexer(true)] or {}).sense
+ if not sense then return end
local symbol, part = sense:get_symbol()
local completions = sense:get_completions(symbol, only_fields, only_functions)
if not completions then return false end
@@ -642,15 +645,21 @@ function M.get_apidoc(sense, symbol)
return apidocs
end
+local apidocs = nil
---
-- Shows a calltip with API documentation for the symbol behind the caret.
--- @param sense The Adeptsense returned by `adeptsense.new()`.
+-- If documentation is already being shown, cycles through multiple definitions.
+-- @param sense The Adeptsense returned by `adeptsense.new()`. If `nil`, uses
+-- the current language's Adeptsense (if it exists).
-- @return list of api docs on success or `nil`.
-- @see get_symbol
-- @see get_apidoc
-- @name show_apidoc
function M.show_apidoc(sense)
local buffer = buffer
+ if buffer:call_tip_active() then events.emit(events.CALL_TIP_CLICK) return end
+ sense = sense or (_M[buffer:get_lexer(true)] or {}).sense
+ if not sense then return end
local symbol
local s, e = buffer.selection_start, buffer.selection_end
if s == e then
@@ -663,7 +672,7 @@ function M.show_apidoc(sense)
else
symbol = buffer:text_range(s, e)
end
- local apidocs = sense:get_apidoc(symbol)
+ apidocs = sense:get_apidoc(symbol)
if not apidocs then return nil end
for i, doc in ipairs(apidocs) do
doc = doc:gsub('\\\\', '%%esc%%'):gsub('\\n', '\n'):gsub('%%esc%%', '\\')
@@ -677,6 +686,15 @@ function M.show_apidoc(sense)
return apidocs
end
+-- Cycle through apidoc calltips.
+events.connect(events.CALL_TIP_CLICK, function(position)
+ if not apidocs then return end
+ apidocs.pos = apidocs.pos + (position == 1 and -1 or 1)
+ if apidocs.pos > #apidocs then apidocs.pos = 1 end
+ if apidocs.pos < 1 then apidocs.pos = #apidocs end
+ buffer:call_tip_show(buffer.current_pos, apidocs[apidocs.pos])
+end)
+
---
-- Loads the given ctags file for autocompletion.
-- It is recommended to pass `-n` to ctags in order to use line numbers instead
@@ -954,39 +972,4 @@ syntax = {
return sense
end
----
--- Completes the symbol at the current position based on the current lexer's
--- Adeptsense.
--- This should be called by key commands and menus instead of `complete()`.
--- @name complete_symbol
-function M.complete_symbol()
- local m = _M[buffer:get_lexer(true)]
- if m and m.sense then m.sense:complete() end
-end
-
-local shown_apidocs = nil
----
--- Shows API documentation for the symbol at the current position based on the
--- current lexer's Adeptsense.
--- If documentation is already being shown, cycles through multiple definitions.
--- This should be called by key commands and menus instead of `show_apidoc()`.
--- @name show_documentation
-function M.show_documentation()
- if not buffer:call_tip_active() then
- local m = _M[buffer:get_lexer(true)]
- if m and m.sense then shown_apidocs = m.sense:show_apidoc() end
- else
- events.emit(events.CALL_TIP_CLICK, 1)
- end
-end
-
--- Cycle through apidoc calltips.
-events.connect(events.CALL_TIP_CLICK, function(position)
- if not shown_apidocs then return end
- shown_apidocs.pos = shown_apidocs.pos + (position == 1 and -1 or 1)
- if shown_apidocs.pos > #shown_apidocs then shown_apidocs.pos = 1 end
- if shown_apidocs.pos < 1 then shown_apidocs.pos = #shown_apidocs end
- buffer:call_tip_show(buffer.current_pos, shown_apidocs[shown_apidocs.pos])
-end)
-
return M
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index f38de109..6ec061e0 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -279,8 +279,8 @@ keys[not OSX and (not NCURSES and 'c|' or 'c\\')
or 'm|'] = m_textadept.filter_through.filter_through
-- Adeptsense.
keys[not OSX and (not NCURSES and 'c ' or 'c@')
- or 'aesc'] = m_textadept.adeptsense.complete_symbol
-keys[not NCURSES and 'ch' or 'mh'] = m_textadept.adeptsense.show_documentation
+ or 'aesc'] = m_textadept.adeptsense.complete
+keys[not NCURSES and 'ch' or 'mh'] = m_textadept.adeptsense.show_apidoc
if NCURSES then keys.mH = keys.mh end -- in case mh is used by GUI terminals
-- Snippets.
keys[not OSX and (not NCURSES and 'ck' or 'mk') or 'a\t'] = m_snippets._select