[geany/geany-plugins] 0b6b83: GeanyLua: Add filetype to set in geany.newfile()
Skif-off
git-noreply at xxxxx
Thu Jan 25 20:18:03 UTC 2018
Branch: refs/heads/master
Author: Skif-off <Skif-off at users.noreply.github.com>
Committer: Skif-off <Skif-off at users.noreply.github.com>
Date: Thu, 30 Nov 2017 07:07:48 UTC
Commit: 0b6b83f5a87dd63242cd414eabc45e48f5a907f5
https://github.com/geany/geany-plugins/commit/0b6b83f5a87dd63242cd414eabc45e48f5a907f5
Log Message:
-----------
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
24 lines changed, 18 insertions(+), 6 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>
@@ -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 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).
More information about the Plugins-Commits
mailing list