Now that there is syntax highlighting and color themes support, a little more sofisticated type inference would be pretty useful and easy to implement. A lot of scripts haven't any extension at all. Maybe the file command could be used. It would be a oneliner and it's not a heavy dependency.
https://developer.gnome.org/gtksourceview/stable/GtkSourceLanguageManager.html#gtk-source-language-manager-guess-language
Matt, gEdit(3.14.1) is inferring the filetype from shebang. I thought that compiling Mousepad with GTK3 support(thus GtkSourceView3) would "fix" this. I might be wrong, but the gEdit source[1] related to guessing filetype isn't that different from Mousepad[2], so what is preventing Mousepad from guessing just like gEdit? 1 - https://git.gnome.org/browse/gedit/tree/gedit/gedit-document.c#n595 2 - http://git.xfce.org/apps/mousepad/tree/mousepad/mousepad-file.c#n450
Hello Guys, I started using mousepad soma days ago, and I like it :) Simple fast low resources.. It has a draw back, which is on this Bug Report. I am using mousepad v0.4.0 I tried to clone repo, and build, it, first to test first master branch..and see if I could solve this bug, but unfortunately I am on aarch64, and have some conflicts trying to install libgtk2.0-dev, because of my mitgard graphic card.. package manager got corrupted and was a lot of trouble to revert...it conflict with some X11 packages.. It doesn't detect files with shebang. I need to assign file type to have syntax highlighting each time I save the file, its like crazy. Does this Bug had already been solved? Thanks in Advance. tux
@tuxd3v you could use `./configure --enable-gtk3` to build against GTK+ 3, but I don't think it will work still. I guess if it's not done by GtkSourceView or GContentType, it would have to be done in Mousepad code. It seems easy to actually find and parse the shebang, but there would need to be a mechanism to match up the arbitrary shell commands to a language type, which seems like it would be more appropriate in GtkSourceView since it provides those or GContentType since it knows about mime/file types. Maybe the correct solution would be to add a `<shebangs>` element to the GSV XML language[0] files and related code to the library? Or maybe even a more generic regex rather like `<globs>` that looks in the first or last N bytes of the file to detect also emacs/vim style special comments telling the language in addition to shebangs? It's possible this already exists and I just didn't see it in the docs. [0]: https://developer.gnome.org/gtksourceview/stable/lang-reference.html
Hi, Is there any news on this? shared-mime-info and gtksourceview are properly configured on my system: a file starting by "#!/bin/bash" is recognized as a shell script, regardless to its extension, opened by mousepad, but not automatically highlighted if its extension is different from ".sh". Is there a way to make automatic highlighting being based on files content? Thanks!
I created a patch based on gedit: https://github.com/jaseemabid/gedit/blob/master/gedit/gedit-document.c#L1032 I've been using mousepad with the patch for a couple weeks and it's been working OK for me so far. --- a/mousepad/mousepad-file.c +++ b/mousepad/mousepad-file.c @@ -462,15 +462,24 @@ gchar *basename; gboolean result_uncertain; GtkSourceLanguage *language; + gchar *data; + GtkTextIter start; + GtkTextIter end; g_return_val_if_fail ((file->filename != NULL), NULL); - content_type = g_content_type_guess (file->filename, NULL, 0, &result_uncertain); + gtk_text_buffer_get_start_iter (file->buffer, &start); + end = start; + gtk_text_iter_forward_chars (&end, 255); + data = gtk_text_buffer_get_text (file->buffer, &start, &end, TRUE); + + content_type = g_content_type_guess (file->filename, (const guchar *)data, strlen (data), &result_uncertain); basename = g_path_get_basename (file->filename); language = gtk_source_language_manager_guess_language (gtk_source_language_manager_get_default (), basename, result_uncertain ? NULL : content_type); + g_free (data); g_free (basename); g_free (content_type);
This patch worked for me on Arch Linux. This is very nice to have shell scripts (among others) recognized regardless to files extensions! Thanks @jmcamp, I hope this patch will be merged soon!
The patch looks good to me, can you please attach it commit info (git format-patch)? Thanks.
(In reply to Andre Miranda from comment #8) > The patch looks good to me, can you please attach it commit info (git > format-patch)? Thanks. Sorry I don't know git and don't have any free time now to look into it. The last time I used a version control system was SVN about 10 years ago!
(In reply to jmcamp from comment #9) > Sorry I don't know git and don't have any free time now to look into it. > The last time I used a version control system was SVN about 10 years ago! Can I make you the author of the commit (name+email) or you don't mind about authorship?
> (In reply to jmcamp from comment #9) > > Sorry I don't know git and don't have any free time now to look into it. > > The last time I used a version control system was SVN about 10 years ago! > > Can I make you the author of the commit (name+email) or you don't mind about > authorship? I don't mind about authorship, so feel free to commit however you see fit. (In reply to Andre Miranda from comment #10)
Andre Miranda referenced this bugreport in commit f41614cc3ecd1032de632d21a89024ccafae209b Infer filetype from shebang line (Bug #10514) https://git.xfce.org/apps/mousepad/commit?id=f41614cc3ecd1032de632d21a89024ccafae209b