coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.46k stars 431 forks source link

Feature Request : add an option to the File Mapping for the First Line Pattern #1437

Open dimitrik-fr opened 1 year ago

dimitrik-fr commented 1 year ago

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

dimitrik-fr commented 1 year ago

A simple "workaround" implementation could be to extend File Mapping Interpreters option:

What fo you think ?

1024jp commented 1 year ago

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 --.

dimitrik-fr commented 1 year ago

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 :

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..