@frlan
But ... I prefer PR with an updated MAINTAINERS file too ;)
Sorry, it's too cool for me :) And I found a workaround: ```lua local t = geany.fileinfo(); geany.newfile("UNTITLED" .. t.ext); ``` (but untitled document would be more convenient because it's obvious).
Well, I do not want to lose, maybe will useful :), patch (like ```document.new_file``` in [GeanyPy](https://geanypy.readthedocs.io/en/latest/document.html#document.new_file), + fix two build warnings & upd ```geanylua-ref.html```): ```diff diff -Naur 01/glspi_app.c 02/glspi_app.c --- glspi_app.c +++ glspi_app.c @@ -5,6 +5,7 @@ */
#define _BSD_SOURCE /* for stat() and lstat() */ +#define _DEFAULT_SOURCE /* fix warning if glibc >= 2.20 */ #include <sys/stat.h> #include <stdlib.h> #include <unistd.h> @@ -422,7 +423,7 @@ for (i=1;i<=argc;i++) { if (!lua_isstring(L,i)) { return FAIL_STRING_ARG(i); } } - argv=g_malloc0(sizeof(gchar *)*argc+1); + argv=g_malloc0(sizeof(gchar *)*(argc+1)); for (i=0;i<argc;i++) { argv[i]=(g_strdup(lua_tostring(L,i+1))); } diff -Naur 01/glspi_doc.c 02/glspi_doc.c --- glspi_doc.c +++ glspi_doc.c @@ -32,12 +32,20 @@ static gint glspi_newfile(lua_State* L) { const gchar *fn=NULL; + const gchar *tf=NULL; + GeanyFiletype *ft=NULL; if (lua_gettop(L)>0) { 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; } + tf=lua_tostring(L, 2); + if ( '\0' == tf[0] ) { + ft=NULL; + } else { + ft=filetypes_lookup_by_name(tf); + } } - document_new_file(fn, NULL, NULL); + document_new_file(fn, ft, NULL); return 0; }
diff -Naur 01/docs/geanylua-ref.html 02/docs/geanylua-ref.html --- docs/geanylua-ref.html +++ docs/geanylua-ref.html @@ -756,11 +756,23 @@ <br><br>
-<a name="newfile"></a><hr><h3><tt>geany.newfile ( [filename] )</tt></h3><p> -When called with one argument, creates a new document with the specified -<tt>filename</tt>. </p><p>When called with no arguments, creates a new, untitled document. -</p><br><br> +<a name="newfile"></a><hr><h3><tt>geany.newfile ( [filename [, filetype] )</tt></h3><p> +<p>When called with no arguments, creates a new, untitled document.</p> +<p>When called with one argument, creates a new document with the specified +<tt>filename</tt>.</p> +<p>When called with two argument, creates a new document with the specified +<tt>filename</tt> and <tt>filetype</tt> (a one-word description of the filetype, +e.g. "C" or "Python".). If you want untitled document then set <tt>filename</tt> as <tt>""</tt>.</p> +<p>So you can use it like this:</p> +<pre>local s = geany.selection();
+if (s ~= "") and (s ~= nil) then + local t = geany.fileinfo(); + geany.newfile("", t.type); + geany.selection(s); +end</pre> +<p>(create a new, untitled document, with selected text and autoset filetype).</p> +<br><br>
<a name="open"></a><hr><h3><tt>geany.open ( [filename]|[index] )</tt></h3><p>
```