I didn't find such a feature request/enhancement, but if it was already requested (or feature already exists), feel free to close this issue.
It would be nice if Geany can highlight syntax for files without extensions. Let's say I open a new tab and copy/paste some PHP snippet to it. Some other editors will automatically highlight syntax as PHP in this tab if content starts with **<?php** (even if tan wasn't saved as some file with *.php extension extension).
Now, it's needed to save tab as a file with corresponding extension just to enable syntax highlight. Sometimes it's a pain in the a** because I often create a new tab, copy/paste some PHP snippet for temporary purposes, and close this tab in minutes. But if I need syntax highlight (which I need, of course), I have to manually save every tab as PHP file.
I realize some languages might not have starting words, but if it has, maybe Geany can auto-recognize and highlight syntax?
For example, these starting words surely indicate which language should be highlighted:
``` <?php <html <?xml ``` ...and I'm sure the list will go on
Try `menu->Document->Set Filetype->Scripting Languages->PHP Source File`.
Because users can set the filetype, Geany will only recognise filetypes at the time a file is first opened, and then remembers the filetype whilst ever a file remains open, and even if Geany is quit and re-started with the file open it will retain the previous filetype.
Thanks. It's a bit faster solution than saving files, but I'm wondering if there's way to automate it. Like in Notepad++ for example, which is also Scintilla based (IIRC).
@toxpal somehow missed your response, filetype detections have nothing to do with Scintilla, the app tells it which highlighting to use.
Note that Geany does in fact detect the prefixes you suggested:
``` <!DOCTYPE html <html <?xml <?php ``` and a whole bunch of `#!` names. It also allows the filetype to be extracted by regular expression (see `various` prefs).
The order is the list above, then regex then extension.
Note that Geany does in fact detect the prefixes you suggested:
Yes, but it only works for existing files. If file is not saved, Geany doesn't detect any of prefixes, and the only way to get syntax highlighting to work is to:
1. Manually save file; 2. Manually set file type using your previous suggestion (_menu->Document->Set Filetype->Scripting Languages->PHP Source File_)
See what I mean - https://i.postimg.cc/MHh2RNhQ/geany.png
As you see, file is not saved yet, so Geany doesn't detect PHP filetype for some reason.
As I said above, Geany only detects a filetype the first time a file is opened, it will not change the filetype of a file once its open because:
1. that would prevent the user from choosing a filetype manually, and 2. could result in unwanted changes of filetype if a user accidently modified the string that identified the filetype.
So it is not searching for identifying strings whilst editing is in progress, so typing one won't set a filetype.
Closed #1899.
Works as intended
github-comments@lists.geany.org