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

syntax-highlight of hotkey #18

Closed
CoffeeChaton opened this issue Apr 12, 2023 · 4 comments
Closed

syntax-highlight of hotkey #18

CoffeeChaton opened this issue Apr 12, 2023 · 4 comments

Comments

@CoffeeChaton
Copy link

"hotkey_raw": {
    "name": "meta.hotkey.line.ahk",
    "begin": "^([#!^+&<>*~$]+|(?:<\\^>!))?([!-/]|[:-@]|[\\[-`]|[\\{-~]|[a-zA-Z0-9]+)(\\s&\\s([!-/]|[:-@]|[\\[-`]|[\\{-~]|[a-zA-Z0-9]+))?(?=::)",
    "beginCaptures": {
        "1": { "name": "storage.modifier.hotkey.ahk" },
        "2": { "patterns": [ { "include": "#keylist" } ] },
        "4": { "patterns": [ { "include": "#keylist" } ] }
    },
    "end": "::",
    "endCaptures": { "0": { "name": "punctuation.definition.end.hotkey.ahk" } },
    "patterns": [ { "include": "#comment" } ]
},
"hotkey": {
    "name": "meta.hotkey.line.ahk",
    "begin": "^([#!^+&<>*~$]+|(?:<\\^[<>]!))?([!-/]|[:-@]|[\\[-`]|[\\{-~]|[a-zA-Z0-9]+)([ \\t]&[ \\t]([!-/]|[:-@]|[\\[-`]|[\\{-~]|[a-zA-Z0-9]+))?([ \\t]+(?i:UP))?(?=::)",
    //                                                                                                                                          ^1 support of "UP" suffix
    "beginCaptures": {
        "1": { "name": "storage.modifier.hotkey.ahk" },
        "2": {
            "name": "meta.2.hotkey.line.ahk",
            "patterns": [
                { "include": "#keylist" },
                {
                    "match": "[!-/]|[:-@]|[\\[-`]|[\\{-~]",
                    "name": "string.2.storage.modifier.hotkey.ahk"
                    //       ^2 string avoid user open "editor.matchBrackets", then {} () [] <> may be out of control
                },
                {
                    "match": "(?<![a-zA-Z0-9])[a-zA-Z0-9](?![a-zA-Z0-9])",
                    //       ^3 Highlight single-character keywords, which can hint the user to accidentally enter an invalid key
                    "name": "markup.bold.hotkey.ahk"
                }
            ]
        },
        "4": {
            "name": "meta.4.hotkey.line.ahk",
            "patterns": [
                { "include": "#keylist" },
                {
                    "match": "[!-/]|[:-@]|[\\[-`]|[\\{-~]",
                    "name": "string.2.storage.modifier.hotkey.ahk"
                },
                {
                    "match": "(?<![a-zA-Z0-9])[a-zA-Z0-9](?![a-zA-Z0-9])",
                    "name": "markup.bold.hotkey.ahk"
                }
            ]
        },
        "5": { "name": "storage.modifier.up.hotkey.ahk" }
    },
    "end": "::",
    "patterns": [ { "include": "#comment" } ]
},

^1 support of "UP" suffix

At the end of the hotkey, using up as the suffix is valid and can be run.

F10 & F11 Up::
    MsgBox, % A_ThisHotkey
return

^2 avoid "editor.matchBrackets" out of control

string avoid user open "editor.matchBrackets", then {} () [] <> may be out of control

2

^3 Highlight single-character keywords

If all valid keys are highlighted, the invalid keys will be very obvious,
So I suggest highlighting [a-zA-Z0-9]{1}

3


I am not good at yaml, so I can only provide jsonc for your reference

@CzarOfScripts
Copy link

Have you tried the vk** code?

@CoffeeChaton
Copy link
Author

Have you tried the code?vk**

keylist is cover.

{ "include": "#keylist" },

"match": "\\b(?i:shift|lshift|rshift|alt|lalt|ralt|control|lcontrol|rcontrol|ctrl|lctrl|rctrl|lwin|rwin|appskey|lbutton|rbutton|mbutton|WheelUp|WheelDown|wheelleft|wheelright|xbutton1|xbutton2|joy1|joy2|joy3|joy4|joy5|joy6|joy7|joy8|joy9|joy10|joy11|joy12|joy13|joy14|joy15|joy16|joy17|joy18|joy19|joy20|joy21|joy22|joy23|joy24|joy25|joy26|joy27|joy28|joy29|joy30|joy31|joy32|joyx|joyy|joyz|joyr|joyu|joyv|joypov|joyname|joybuttons|joyaxes|joyinfo|space|tab|enter|escape|esc|backspace|bs|delete|del|insert|ins|pgdn|pgup|home|end|up|down|left|right|printscreen|ctrlbreak|pause|scrolllock|capslock|numlock|numpad0|numpad1|numpad2|numpad3|numpad4|numpad5|numpad6|numpad7|numpad8|numpad9|numpadmult|numpadadd|numpadsub|numpaddiv|numpaddot|numpaddel|numpadins|numpadclear|numpadleft|numpadright|numpaddown|numpadup|numpadhome|numpadend|numpadpgdn|numpadpgup|numpadenter|f1|f2|f3|f4|f5|f6|f7|f8|f9|f10|f11|f12|f13|f14|f15|f16|f17|f18|f19|f20|f21|f22|f23|f24|browser_back|browser_forward|browser_refresh|browser_stop|browser_search|browser_favorites|browser_home|volume_mute|volume_down|volume_up|media_next|media_prev|media_stop|media_play_pause|launch_mail|launch_media|launch_app1|launch_app2|vk[a-f\\d]{1,2}(sc[a-f\\d]+)?|sc[a-f\\d]+)\\b",

@helsmy
Copy link
Owner

helsmy commented Apr 15, 2023

Thank for your suggestion. It is excellent.

UP match.

Great.let's merge it
图片

Additional patterns for single chararcter keys.

Great, let's merge it, too.
图片

Name of brackets.

The color of string is not always the same with markup. It depends on themes.
图片
Some themes also provide bold effect for bold name section and I think it is better for hotkey. But, In the theme I used (Dark+), string.bold is not effective. We may need try some other options.
Here is some available name: naming-conventions

helsmy added a commit that referenced this issue Apr 15, 2023
@helsmy
Copy link
Owner

helsmy commented Apr 15, 2023

string and markup section can take effect at the same time. So, it can be fixed #19. New highlighting will be added in the next version.

helsmy added a commit that referenced this issue Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants