Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dimitrik-fr opened this issue Feb 15, 2023 · 3 comments
Labels
request feature requests from users
Milestone

Comments

@dimitrik-fr
Copy link

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 dimitrik-fr added the request feature requests from users label Feb 15, 2023
@dimitrik-fr
Copy link
Author

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 !

What fo you think ?

@1024jp
Copy link
Member

1024jp commented Mar 14, 2023

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
Copy link
Author

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

@1024jp 1024jp added this to the To Do milestone Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request feature requests from users
Development

No branches or pull requests

2 participants