Branch: refs/heads/master Author: Frank Lanitz frank@frank.uvena.de Committer: GitHub noreply@github.com Date: Thu, 25 Jan 2018 20:17:56 UTC Commit: f812c6058a69fe26461a35c8ed16aceff2c60132 https://github.com/geany/geany-plugins/commit/f812c6058a69fe26461a35c8ed16ac...
Log Message: ----------- Merge pull request #652 from Skif-off/geanylua-newfile
GeanyLua: Add filetype to set in geany.newfile()
Modified Paths: -------------- geanylua/docs/geanylua-ref.html geanylua/glspi_doc.c
Modified: geanylua/docs/geanylua-ref.html 33 lines changed, 22 insertions(+), 11 deletions(-) =================================================================== @@ -136,7 +136,7 @@ </tr>
<tr class="odd"> - <td> function <a href="#newfile"><b>newfile</b></a> ( [filename] )<br></td> + <td> function <a href="#newfile"><b>newfile</b></a> ( [filename [, filetype] )<br></td> <td class="desc">-- Create a new document.</td> </tr>
@@ -181,27 +181,27 @@ <td class="desc">-- Send a GTK signal to a Geany interface widget.</td> </tr>
-<tr class="odd"> +<tr class="even"> <td> function <a href="#status"><b>status</b></a> ( message )<br></td> <td class="desc">-- Send a string to display in the status tab of the messages window.</td> </tr>
-<tr class="even"> +<tr class="odd"> <td> function <a href="#text"><b>text</b></a> ( [content] )<br></td> <td class="desc">-- Get or set the contents of the entire document.</td> </tr>
-<tr class="odd"> +<tr class="even"> <td> function <a href="#word"><b>word</b></a> ( [position] )<br></td> <td class="desc">-- Get the word at the specified location.</td> </tr>
-<tr class="even"> +<tr class="odd"> <td> function <a href="#xsel"><b>xsel</b></a> ( [text] )<br></td> <td class="desc">-- Get or set the contents of the primary X selection.</td> </tr>
-<tr class="odd"> +<tr class="even"> <td> function <a href="#yield"><b>yield</b></a> ()<br></td> <td class="desc">-- Refreshes the user interface.</td> </tr> @@ -756,11 +756,22 @@ <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 auto set filetype).</p> +<br><br>
<a name="open"></a><hr><h3><tt>geany.open ( [filename]|[index] )</tt></h3><p>
Modified: geanylua/glspi_doc.c 17 lines changed, 14 insertions(+), 3 deletions(-) =================================================================== @@ -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; }
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org