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

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany-plugins/issues/646#issuecomment-345538243">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABDrJ2-yJ6kJGtkD5yzDt0fQvj79d15bks5s4HKbgaJpZM4Qi3Uc">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/ABDrJ7bqGbDtQDPWcIdRobBcfyimEm2Wks5s4HKbgaJpZM4Qi3Uc.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany-plugins/issues/646#issuecomment-345538243"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/geany/geany-plugins","title":"geany/geany-plugins","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/geany/geany-plugins"}},"updates":{"snippets":[{"icon":"PERSON","message":"@Skif-off in #646: @frlan \r\n\u003eBut ... I prefer PR with an updated MAINTAINERS file too ;)\r\n\r\nSorry, it's too cool for me :) And I found a workaround:\r\n```lua\r\n  local t = geany.fileinfo();\r\n  geany.newfile(\"UNTITLED\" .. t.ext);\r\n```\r\n(but untitled document would be more convenient because it's obvious).\r\n\r\n\r\nWell, 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 \u0026 upd ```geanylua-ref.html```):\r\n```diff\r\ndiff -Naur 01/glspi_app.c 02/glspi_app.c\r\n--- glspi_app.c\r\n+++ glspi_app.c\r\n@@ -5,6 +5,7 @@\r\n  */\r\n \r\n #define _BSD_SOURCE /* for stat() and lstat() */\r\n+#define _DEFAULT_SOURCE /* fix warning if glibc \u003e= 2.20 */\r\n #include \u003csys/stat.h\u003e\r\n #include \u003cstdlib.h\u003e\r\n #include \u003cunistd.h\u003e\r\n@@ -422,7 +423,7 @@\r\n \tfor (i=1;i\u003c=argc;i++) {\r\n \t\tif (!lua_isstring(L,i)) { return FAIL_STRING_ARG(i); }\r\n \t}\r\n-\targv=g_malloc0(sizeof(gchar *)*argc+1);\r\n+\targv=g_malloc0(sizeof(gchar *)*(argc+1));\r\n \tfor (i=0;i\u003cargc;i++) {\r\n \t\targv[i]=(g_strdup(lua_tostring(L,i+1)));\r\n \t}\r\ndiff -Naur 01/glspi_doc.c 02/glspi_doc.c\r\n--- glspi_doc.c\r\n+++ glspi_doc.c\r\n@@ -32,12 +32,20 @@\r\n static gint glspi_newfile(lua_State* L)\r\n {\r\n \tconst gchar *fn=NULL;\r\n+        const gchar *tf=NULL;\r\n+\tGeanyFiletype *ft=NULL;\r\n \tif (lua_gettop(L)\u003e0) {\r\n \t\tif (!lua_isstring(L, 1))\t{ return FAIL_STRING_ARG(1); }\r\n \t\tfn=lua_tostring(L, 1);\r\n-\t\tif ( '\\0' == fn[0] ) { fn = NULL; }\r\n+\t\tif ( '\\0' == fn[0] ) { fn=NULL; }\r\n+\t\ttf=lua_tostring(L, 2);\r\n+\t\tif ( '\\0' == tf[0] ) {\r\n+\t\t\tft=NULL;\r\n+\t\t} else {\r\n+\t\t\tft=filetypes_lookup_by_name(tf);\r\n+\t\t}\r\n \t}\r\n-\tdocument_new_file(fn, NULL, NULL);\r\n+\tdocument_new_file(fn, ft, NULL);\r\n \treturn 0;\r\n }\r\n \r\ndiff -Naur 01/docs/geanylua-ref.html 02/docs/geanylua-ref.html\r\n--- docs/geanylua-ref.html\r\n+++ docs/geanylua-ref.html\r\n@@ -756,11 +756,23 @@\r\n \u003cbr\u003e\u003cbr\u003e\r\n \r\n \r\n-\u003ca name=\"newfile\"\u003e\u003c/a\u003e\u003chr\u003e\u003ch3\u003e\u003ctt\u003egeany.newfile ( [filename] )\u003c/tt\u003e\u003c/h3\u003e\u003cp\u003e\r\n-When called with one argument, creates a new document with the specified\r\n-\u003ctt\u003efilename\u003c/tt\u003e. \u003c/p\u003e\u003cp\u003eWhen called with no arguments, creates a new, untitled document.\r\n-\u003c/p\u003e\u003cbr\u003e\u003cbr\u003e\r\n+\u003ca name=\"newfile\"\u003e\u003c/a\u003e\u003chr\u003e\u003ch3\u003e\u003ctt\u003egeany.newfile ( [filename [, filetype] )\u003c/tt\u003e\u003c/h3\u003e\u003cp\u003e\r\n+\u003cp\u003eWhen called with no arguments, creates a new, untitled document.\u003c/p\u003e\r\n+\u003cp\u003eWhen called with one argument, creates a new document with the specified\r\n+\u003ctt\u003efilename\u003c/tt\u003e.\u003c/p\u003e\r\n+\u003cp\u003eWhen called with two argument, creates a new document with the specified\r\n+\u003ctt\u003efilename\u003c/tt\u003e and \u003ctt\u003efiletype\u003c/tt\u003e (a one-word description of the filetype,\r\n+e.g. \"C\" or \"Python\".). If you want untitled document then set \u003ctt\u003efilename\u003c/tt\u003e as \u003ctt\u003e\"\"\u003c/tt\u003e.\u003c/p\u003e\r\n+\u003cp\u003eSo you can use it like this:\u003c/p\u003e\r\n+\u003cpre\u003elocal s = geany.selection();\r\n \r\n+if (s ~= \"\") and (s ~= nil) then\r\n+  local t = geany.fileinfo();\r\n+  geany.newfile(\"\", t.type);\r\n+  geany.selection(s);\r\n+end\u003c/pre\u003e\r\n+\u003cp\u003e(create a new, untitled document, with selected text and autoset filetype).\u003c/p\u003e\r\n+\u003cbr\u003e\u003cbr\u003e\r\n \r\n \r\n \u003ca name=\"open\"\u003e\u003c/a\u003e\u003chr\u003e\u003ch3\u003e\u003ctt\u003egeany.open ( [filename]|[index] )\u003c/tt\u003e\u003c/h3\u003e\u003cp\u003e\r\n\r\n```"}],"action":{"name":"View Issue","url":"https://github.com/geany/geany-plugins/issues/646#issuecomment-345538243"}}}</script>