You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently CotEditor is able to auto-detect file type by file extension, shebang interpreter or explicit file name. However, sometimes no one of them could be matched due whatever reasons (auto-renamed email attachment, files are saved as Blobs and just having long hex numbers in the name, etc). To help such cases many code editors introduced an option to auto-detect the file type by the checking the pattern for the first line in the file (generally regex) which works really well.
For ex. for HTML detecting "<!-- " in the first line is enough, for Lua "-- " and so on.
Would be great to add the same feature to CotEditor.
Rgds,
-Dimitri
The text was updated successfully, but these errors were encountered:
A simple "workaround" implementation could be to extend File Mapping Interpreters option:
currently it's checking for #!... pattern in the first line of the file with the following Interpreter name
while it can be extended to check if the first line is not starting with #!.. pattern, then check if the first word on the given first line is not matching of any provided "interpreters"
this way we can provide <!-- pattern as "interpreter" to auto-detect HTML file
and -- for ex. for Lua, if none of other criteria were not matching (like file extension)
since you're checking the content of the first line in the file anyway, this should not give a big overhead, but will greatly improve overall CotEditor usability !
I understood your need.
However, I always have little motivation to change setting formats.
The only way to implement this feature is adding a new file mapping option list. And I currently feel it isn't worth to change. I don't close this ticket immediately, but just let me think.
(It often takes several years to implement / reject a user request. This is the way I develop. Please accept it.)
A simple "workaround" implementation could be to extend File Mapping Interpreters option:
<!-- is defenetly not an interpreter. I don't accept this workaround anyway.
For ex. for HTML detecting "<!-- " in the first line is enough, for Lua "-- " and so on.
I feel those examples both are not good idea. <!-- can be used rather than in HTML. It's just a opening comment delimiter in SGML/XML. Similar with -- .
Agree that -- and <!-- comments can be used in other syntaxes as well, but to avoid confusion, people can be more explicit, for ex. I could use <!-- HTML in my files to avoid confusion, and "-- SQL" or "-- Lua" in the first line to explicitly tag SQL or Lua file.
Then what about a special "tag" in Interpreter name to mark it as a "first line pattern" -- for example "^" ?
(and if ^Name is used, then Name should be used as line pattern)
then :
^<!-- HTML => first line pattern for HTML file
^-- Lua => Lua
^-- SQL => SQL
e.g. I can change the context of the file, but cannot give it any extension (since it's a Blob file) -- the only question if CotEditor can match something from the file context to auto-discover its syntax.
Of course adding a dedicated option for the first line pattern could be much more clean solution, but I understand it'll take time, so just looking for something more simple to add..
Currently CotEditor is able to auto-detect file type by file extension, shebang interpreter or explicit file name. However, sometimes no one of them could be matched due whatever reasons (auto-renamed email attachment, files are saved as Blobs and just having long hex numbers in the name, etc). To help such cases many code editors introduced an option to auto-detect the file type by the checking the pattern for the first line in the file (generally regex) which works really well.
For ex. for HTML detecting "<!-- " in the first line is enough, for Lua "-- " and so on.
Would be great to add the same feature to CotEditor.
Rgds,
-Dimitri
The text was updated successfully, but these errors were encountered: