aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/.buffer.lua10
-rw-r--r--core/.find.lua5
-rw-r--r--core/ext/find.lua5
-rw-r--r--modules/textadept/editing.lua15
-rw-r--r--modules/textadept/lsnippets.lua25
-rw-r--r--modules/textadept/snippets.lua14
-rw-r--r--src/lua_interface.c20
7 files changed, 50 insertions, 44 deletions
diff --git a/core/.buffer.lua b/core/.buffer.lua
index 7d721ee1..2c2e88d2 100644
--- a/core/.buffer.lua
+++ b/core/.buffer.lua
@@ -365,16 +365,6 @@ buffer = {
}
---
--- Finds text in the current buffer.
--- The indexed buffer must be the currently focused one.
--- @param text The text to find.
--- @param flags SCI_FIND flags used.
--- @param start_pos The position to start the search.
--- @param end_pos The position to end the search.
--- @return start and end positions in the text or nothing.
-function buffer:find(text, flags, start_pos, end_pos)
-
----
-- Gets a range of text from the current buffer.
-- The indexed buffer must be the currently focused one.
-- @param start_pos The beginning position of the range of text to get.
diff --git a/core/.find.lua b/core/.find.lua
index 7d016cae..3f415928 100644
--- a/core/.find.lua
+++ b/core/.find.lua
@@ -52,8 +52,9 @@ local escapes = {}
---
-- Finds and selects text in the current buffer.
--- This is used by the find dialog. It is recommended to use the buffer:find()
--- function for scripting.
+-- This is used by the find dialog. It is recommended to use the
+-- buffer:search_in_target() or buffer:search_next() and buffer:search_prev()
+-- functions for scripting.
-- @param text The text to find.
-- @param next Flag indicating whether or not the search direction is forward.
-- @param flags Search flags. This is a number mask of 4 flags: match case (2),
diff --git a/core/ext/find.lua b/core/ext/find.lua
index 2608e862..5aea4a35 100644
--- a/core/ext/find.lua
+++ b/core/ext/find.lua
@@ -17,8 +17,9 @@ local escapes = {
---
-- Finds and selects text in the current buffer.
--- This is used by the find dialog. It is recommended to use the buffer:find()
--- function for scripting.
+-- This is used by the find dialog. It is recommended to use the
+-- buffer:search_in_target() or buffer:search_next() and buffer:search_prev()
+-- functions for scripting.
-- @param text The text to find.
-- @param next Flag indicating whether or not the search direction is forward.
-- @param flags Search flags. This is a number mask of 4 flags: match case (2),
diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua
index e7cc684b..1631ca59 100644
--- a/modules/textadept/editing.lua
+++ b/modules/textadept/editing.lua
@@ -154,15 +154,18 @@ function autocomplete_word(word_chars)
local buffer_text = buffer:get_text(length)
local root = buffer_text:sub(1, caret):match('['..word_chars..']+$')
if not root or #root == 0 then return end
- local match_pos = buffer:find(root, 1048580) -- word start and match case
- while match_pos do
+ buffer.target_start, buffer.target_end = 0, buffer.length
+ buffer.search_flags = 1048580 -- word start and match case
+ local match_pos = buffer:search_in_target(root)
+ while match_pos ~= -1 do
local s, e = buffer_text:find('^['..word_chars..']+', match_pos + 1)
local match = buffer_text:sub(s, e)
if not completions[match] and #match > #root then
c_list[#c_list + 1] = match
completions[match] = true
end
- match_pos = buffer:find(root, 1048580, match_pos + 1)
+ buffer.target_start, buffer.target_end = match_pos + 1, buffer.length
+ match_pos = buffer:search_in_target(root)
end
if #c_list > 0 then buffer:auto_c_show(#root, table.concat(c_list, ' ')) end
end
@@ -498,7 +501,11 @@ function select_enclosed(str)
while s >= 0 do
char = string.char(buffer.char_at[s])
if char_matches[char] then
- local _, e = buffer:find(char_matches[char], 0, e)
+ buffer.target_start, buffer.target_end = e, buffer.length
+ buffer.search_flags = 0
+ if buffer:search_in_target(char_matches[char]) ~= -1 then
+ e = buffer.target_end
+ end
if e then buffer:set_sel(s + 1, e - 1) break end
end
s = s - 1
diff --git a/modules/textadept/lsnippets.lua b/modules/textadept/lsnippets.lua
index ee7a394b..c0cfab20 100644
--- a/modules/textadept/lsnippets.lua
+++ b/modules/textadept/lsnippets.lua
@@ -227,17 +227,29 @@ function next()
if index <= snippet.max_index then
local s, e, next_item = s_text:find('%%'..index..'(%b())')
if next_item and not next_item:find('|') then -- placeholder
- s, e = buffer:find('%'..index..next_item, 0, s_start)
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ buffer.search_flags = 0
+ s = buffer:search_in_target('%'..index..next_item)
+ e = buffer.target_end
next_item = next_item:gsub('#(%b())', run_lua_code)
next_item = unhandle_escapes(next_item:sub(2, -2))
buffer:set_sel(s, e)
buffer:replace_sel(next_item)
buffer:set_sel(s, s + #next_item)
else -- use the first mirror as a placeholder
- s, e = buffer:find('%'..index..'[^(]', 2097152, s_start) -- regexp
+ s, e = nil, nil
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ buffer.search_flags = 2097152 -- regexp
+ if buffer:search_in_target('%'..index..'[^(]') ~= -1 then
+ s, e = buffer.target_start, buffer.target_end
+ end
if not s and not e then
+ s, e = nil, nil
-- Scintilla cannot match [\r\n\f] in regexp mode; use '$' instead
- s, e = buffer:find('%'..index..'$', 2097152, s_start) -- regexp
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ if buffer:search_in_target('%'..index..'$') ~= -1 then
+ s, e = buffer.target_start, buffer.target_end
+ end
if e then e = e + 1 end
end
if not s then snippet.index = index + 1 return next() end
@@ -255,7 +267,12 @@ function next()
buffer:goto_pos(s_end + 1)
buffer:delete_back()
end
- local s, e = buffer:find('%__caret', 4, s_start)
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ buffer.search_flags = 4
+ local s, e
+ if buffer:search_in_target('%__caret') ~= -1 then
+ s, e = buffer.target_start, buffer.target_end
+ end
if s and s <= s_end then
buffer:set_sel(s, e)
buffer:replace_sel('')
diff --git a/modules/textadept/snippets.lua b/modules/textadept/snippets.lua
index 8d46610e..d9d40f71 100644
--- a/modules/textadept/snippets.lua
+++ b/modules/textadept/snippets.lua
@@ -251,7 +251,12 @@ next_snippet_item = function()
if s and next_item then
next_item = unescape(next_item)
_DEBUG('next_item:\n'..next_item)
- local s, e = buffer:find(next_item, 0, s_start)
+ local s, e
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ buffer.search_flags = 0
+ if buffer:search_in_target(next_item) ~= -1 then
+ s, e = buffer.target_start, buffer.target_end
+ end
if s and e then
buffer:set_sel(s, e)
snippet.cursor = s
@@ -283,7 +288,12 @@ next_snippet_item = function()
join_lines()
end
- local s, e = buffer:find('$CURSOR', 4, s_start)
+ local s, e
+ buffer.target_start, buffer.target_end = s_start, buffer.length
+ buffer.search_flags = 4
+ if buffer:search_in_target('$CURSOR') ~= -1 then
+ s, e = buffer.target_start, buffer.target_end
+ end
if s and e then
buffer:set_sel(s, e)
buffer:replace_sel('')
diff --git a/src/lua_interface.c b/src/lua_interface.c
index 64deb259..e50784dc 100644
--- a/src/lua_interface.c
+++ b/src/lua_interface.c
@@ -60,7 +60,6 @@ static int l_buffer_mt_index(lua_State *lua),
static int l_cf_ta_buffer_new(lua_State *lua),
l_cf_buffer_delete(lua_State *lua),
- l_cf_buffer_find(lua_State *lua),
l_cf_buffer_text_range(lua_State *lua),
l_cf_view_focus(lua_State *lua),
l_cf_view_split(lua_State *lua),
@@ -316,7 +315,6 @@ int l_add_scintilla_buffer(sptr_t doc) {
lua_newtable(lua);
lua_pushnumber(lua, doc);
lua_setfield(lua, -2, "doc_pointer");
- l_cfunc(lua, l_cf_buffer_find, "find");
l_cfunc(lua, l_cf_buffer_text_range, "text_range");
l_cfunc(lua, l_cf_buffer_delete, "delete");
l_mt(lua, "_buffer_mt", l_buffer_mt_index, l_buffer_mt_newindex);
@@ -1343,24 +1341,6 @@ static int l_cf_buffer_delete(lua_State *lua) {
return 0;
}
-static int l_cf_buffer_find(lua_State *lua) {
- l_check_focused_buffer(lua, 1);
- TextToFind ttf = {{0, 0}, 0, {0, 0}};
- ttf.lpstrText = const_cast<char*>(luaL_checkstring(lua, 2));
- int args = lua_gettop(lua), flags = 0;
- if (args > 2) flags = luaL_checkinteger(lua, 3);
- if (args > 3) ttf.chrg.cpMin = luaL_checkinteger(lua, 4);
- ttf.chrg.cpMax = (args > 4) ? luaL_checkinteger(lua, 5)
- : SS(SCINTILLA(focused_editor), SCI_GETLENGTH);
- int pos = SS(SCINTILLA(focused_editor), SCI_FINDTEXT, flags,
- reinterpret_cast<sptr_t>(&ttf));
- if (pos > -1) {
- lua_pushinteger(lua, ttf.chrgText.cpMin);
- lua_pushinteger(lua, ttf.chrgText.cpMax);
- return 2;
- } else return 0;
-}
-
static int l_cf_buffer_text_range(lua_State *lua) {
l_check_focused_buffer(lua, 1);
#ifndef MAC