diff --git a/geanylua/docs/geanylua-ref.html b/geanylua/docs/geanylua-ref.html index 9795c165e..e1c4f3e35 100644 --- a/geanylua/docs/geanylua-ref.html +++ b/geanylua/docs/geanylua-ref.html @@ -136,7 +136,7 @@ -   function newfile ( [filename] )
+   function newfile ( [filename [, filetype] )
-- Create a new document. @@ -181,27 +181,27 @@ -- 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. @@ -756,11 +756,22 @@

-

geany.newfile ( [filename] )

-When called with one argument, creates a new document with the specified -filename.

When called with no arguments, creates a new, untitled document. -



- +

geany.newfile ( [filename [, filetype] )

+

When called with no arguments, creates a new, untitled document.

+

When called with one argument, creates a new document with the specified filename.

+

When called with two argument, creates a new document with the specified +filename and filetype (a one-word description of the filetype, +e.g. "C" or "Python".). If you want untitled document then set filename as "".

+

So you can use it like this:

+
local s = geany.selection();
+
+if (s ~= "") and (s ~= nil) then
+  local t = geany.fileinfo();
+  geany.newfile("", t.type);
+  geany.selection(s);
+end
+

(create a new, untitled document, with selected text and auto set filetype).

+


geany.open ( [filename]|[index] )

diff --git a/geanylua/glspi_doc.c b/geanylua/glspi_doc.c index 888ce8d55..b536033e8 100644 --- a/geanylua/glspi_doc.c +++ b/geanylua/glspi_doc.c @@ -32,12 +32,23 @@ static gint glspi_filename(lua_State* L) static gint glspi_newfile(lua_State* L) { const gchar *fn=NULL; - if (lua_gettop(L)>0) { + GeanyFiletype *ft=NULL; + switch (lua_gettop(L)) { + case 0: break; + case 2: + if (!lua_isstring(L, 2)) { return FAIL_STRING_ARG(2); } + const gchar *tmp=lua_tostring(L, 2); + if ( '\0' == tmp[0] ) { + ft=NULL; + } else { + ft=filetypes_lookup_by_name(tmp); + } + default: if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); } fn=lua_tostring(L, 1); - if ( '\0' == fn[0] ) { fn = NULL; } + if ( '\0' == fn[0] ) { fn=NULL; } } - document_new_file(fn, NULL, NULL); + document_new_file(fn, ft, NULL); return 0; }