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

Do not apply syntax highlight to files without extensions #1353

Open
2 of 3 tasks
KES777 opened this issue Sep 10, 2016 · 13 comments
Open
2 of 3 tasks

Do not apply syntax highlight to files without extensions #1353

KES777 opened this issue Sep 10, 2016 · 13 comments

Comments

@KES777
Copy link

KES777 commented Sep 10, 2016

Summary

When save files with names such as: 'r', 'pl' syntax is changed

Expected behavior

Syntax is not changed

Steps to reproduce

  1. Save file with name 'r'
  2. The 'R' syntax is applied to file

Environment

  • Operating system and version:
    • Windows ...
    • Mac OS ...
    • Linux Mint 17.3
  • Sublime Text:
    • Build 3114
@evandrocoan
Copy link

evandrocoan commented Sep 12, 2016

I like this behavior, so a new setting to turn it on and off is good.

@keith-hall keith-hall changed the title Do not apply syntax highlight to files without extentions Do not apply syntax highlight to files without extensions Sep 13, 2016
@keith-hall
Copy link
Collaborator

This doesn't only affect saving files, it also affects opening files with no extension. There was a short discussion about this on the Default Packages repo which arose from some confusion about the sublime-syntax file specifying file_extensions - when in fact it can also be used for the full name of the file.

@wbond
Copy link
Member

wbond commented Sep 14, 2016

A number of the default packages use this functionality, especially Ruby

@keith-hall
Copy link
Collaborator

I think it would be better to use a separate key in the sublime-syntax YAML for it, instead of file_extensions - thus the syntax definitions can be explicit about which are extensions and which are full file names, and not lose any functionality.

@keith-hall
Copy link
Collaborator

I think it would be useful, if/when this gets implemented, if specific filename matching occurred before file extension matching, so that sublimehq/Packages#611 would be possible.

@wbond
Copy link
Member

wbond commented Sep 16, 2016

Making a change such as this would be kind of a big backwards compatibility break.

@keith-hall
Copy link
Collaborator

It would be possible to keep the current behavior in file_extensions and use 2 new YAML keys to prevent backwards compatibility problems. However, it would probably just make it even more confusing...

@FichteFoll
Copy link
Collaborator

FichteFoll commented Dec 9, 2016

Another way would be to use the new behavior if the second key exists.

I'm still in favor of separating the two though, despite backwards incompatibility. Cluttering the "save as" window with loads of filenames that happen to use this syntax is kinda bad. However, after the change files still need to be able to be saved with these specific names.

@melomac
Copy link

melomac commented May 26, 2021

I have a related issue with both ST4 and SM2 where a Python script with filename cs, no file extension, and a shebang #!/usr/bin/python3 is ending up with an unexpected (at least to me) syntax.

@jfcherng came with this great work around for ST on Discord's #support :

import sublime
import sublime_plugin


class PreferShebangSyntax(sublime_plugin.EventListener):
    def on_load(self, view: sublime.View) -> None:
        first_line = view.substr(sublime.Region(0, 80))

        if first_line.startswith("#!/"):
            current_syntax = view.syntax()
            target_syntax = sublime.find_syntax_for_file("", first_line)

            if target_syntax.path != current_syntax.path and target_syntax.name != "Plain Text":
                view.assign_syntax(target_syntax.path)

While it's not exactly what is asked here, this seems like the expected behavior for such cases.

@jfcherng
Copy link

jfcherng commented Aug 8, 2021

I have a related issue with both ST4 and SM2 where a Python script with filename cs, no file extension, and a shebang #!/usr/bin/python3 is ending up with an unexpected (at least to me) syntax.

@jfcherng came with this great work around for ST on Discord's #support : ...

By the way, I have that as a part of functionalities in https://packagecontrol.io/packages/AutoSetSyntax.

@deathaxe
Copy link
Collaborator

With regards to this request and the one from #4737, issue #4741 illustrates, why limiting things to extensions (after dots) might be too restrictive.

@KES777
Copy link
Author

KES777 commented Aug 10, 2021

I like the behavior by matching end of file. It is required to highlight Makefile itself for example.
But when I save file as php or r which are not belongs to php and they are highlighted - this is wrong.

Probably syntax highlighter should be just configured as .php and .r. So bare names php, r will not be matched

Thus we should not implement new keys, we just need to reconfigure those modules so they will setup .php instead php

@jfcherng
Copy link

jfcherng commented Aug 10, 2021

Thus we should not implement new keys, we just need to reconfigure those modules so they will setup .php instead php

That potentially breaks plugins.

But even with a new key, removing Makefile from file_extensions may be a BC break too for a few existing plugins...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants