[Github-comments] [geany/geany-plugins] GeanyLua: Update glspi_sci.h (PR #1123)

Skif-off notifications at xxxxx
Fri Oct 22 12:48:45 UTC 2021


@elextr I think, all ```SCI_*LEXER*``` are not really needed in this plugin (so they can stay in this list and no more), also you wrote

> You should not set the lexer directly, set the Geany filetype instead.

[here](https://github.com/geany/geany-plugins/issues/646). Now we can get the current filetype
```lua
local finfo = geany.fileinfo()
if finfo ~= nil then
  geany.message('Current filetype is "' .. finfo.type .. '": ' .. finfo.desc)
end
```
and it may be useful to change the current filetype: something like ```geany.settype(".cmake")``` with
```c
/* Change the current file type by the specified file extension */
static gint glspi_set_filetype(lua_State* L)
{
	GeanyDocument *doc=NULL;
	GeanyFiletype *ft=NULL;
	const gchar *ftn=NULL;

	if (lua_gettop(L)==1){
		if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); }
		doc = document_get_current();
		if (!(doc && doc->is_valid)) { return 0; }
		ftn=lua_tostring(L, 1);
		if ('\0' == ftn[0]) { return 0; }
		ft=filetypes_detect_from_extension(ftn);
		if (ft != NULL){
			document_set_filetype(doc, ft);
			return 1;
		}
	}
	return 0;
}
```
in ```glspi_doc.c```. But currently ```filetypes_detect_from_extension``` is not a prt of Geany API.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany-plugins/pull/1123#issuecomment-949600361
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20211022/be54a0da/attachment.htm>


More information about the Github-comments mailing list