diff --git a/geanylua/docs/geanylua-ref.html b/geanylua/docs/geanylua-ref.html index 6ae5d2a7b3..96fd7c3ff4 100644 --- a/geanylua/docs/geanylua-ref.html +++ b/geanylua/docs/geanylua-ref.html @@ -150,63 +150,67 @@ -- Paste text from the clipboard. - +   function range ( start, stop [, multi] )
+ -- Get the text in the specified range. + + +   function rowcol ( [pos]|[row,col] )
-- Translate between linear and rectangular locations. - +   function save ( [filename]|[index] )
-- Save an open document to a disk file. - +   function scintilla ( msg_id, wparam, lparam )
-- Send a message directly to the Scintilla widget. - +   function select ( [[start,] stop] )
-- Get or set the selection endpoints and caret. - +   function selection ( [content] )
-- Get or set the contents of the document's selection. - +   function settype ( filetype )
-- Change the current file type. - +   function signal ( widget, signal )
-- Send a GTK signal to a Geany interface widget. - +   function status ( message )
-- Send a string to display in the status tab of the messages window. - +   function text ( [content] )
-- Get or set the contents of the entire document. - +   function word ( [position] )
-- Get the word at the specified location. - +   function xsel ( [text] )
-- Get or set the contents of the primary X selection. - +   function yield ()
-- Refreshes the user interface. @@ -825,6 +829,19 @@

+

geany.range ( start, stop [, multi] )

+

Returns the text from position start to position stop.
+multi is an optional boolean parameter +(true or false, false used by default): +if the position lands inside a multi-byte sequence, geany.range +will use the position at the beginning (start) or +at the end (stop) of that multi-byte character. This is usually +not necessary because GeanyLua functions (geany.caret, +geany.find and so on) and Lua functions (string.find and so on) +use positions in bytes.

+

+ +

geany.reloadconf ()

This function will cause Geany to reload most of it's configuration files without restarting (as menu item Tools->Reload Configuration).

diff --git a/geanylua/glspi_sci.c b/geanylua/glspi_sci.c index fc3d698355..830f2fb653 100644 --- a/geanylua/glspi_sci.c +++ b/geanylua/glspi_sci.c @@ -975,6 +975,41 @@ struct Sci_TextToFind { +static gint glspi_range(lua_State* L) +{ + gint argc = lua_gettop(L); + gboolean multi = FALSE; + gint start, stop, x, y; + gchar *text; + DOC_REQUIRED + gint len = sci_get_length(doc->editor->sci); + if ( (len == 0) || (argc < 2) || (argc > 3) ) { + lua_pushnil(L); + return 1; + } + if (!lua_isnumber(L, 1)) { return FAIL_NUMERIC_ARG(1); } + start = lua_tonumber(L, 1); + if (!lua_isnumber(L, 2)) { return FAIL_NUMERIC_ARG(2); } + stop = lua_tonumber(L, 2); + if (start < 0) { return FAIL_UNSIGNED_ARG(1); } + if (stop < 0) { return FAIL_UNSIGNED_ARG(2); } + if (start > stop) { swap(&start, &stop); } + if (stop > len) { stop = len; } + if (lua_isboolean(L, 3)) { multi = lua_toboolean(L, 3); } + if (multi) { + x = scintilla_send_message(doc->editor->sci, SCI_POSITIONBEFORE, start, 0); + y = scintilla_send_message(doc->editor->sci, SCI_POSITIONAFTER, stop, 0); + text = sci_get_contents_range(doc->editor->sci, x, y); + } else { + text = sci_get_contents_range(doc->editor->sci, start, stop); + } + lua_pushstring(L, text); + g_free(text); + return 1; +} + + + static const struct luaL_Reg glspi_sci_funcs[] = { {"text", glspi_text}, {"selection", glspi_selection}, @@ -994,6 +1029,7 @@ static const struct luaL_Reg glspi_sci_funcs[] = { {"byte", glspi_byte}, {"scintilla", glspi_scintilla}, {"find", glspi_find}, + {"range", glspi_range}, {NULL,NULL} };