koekeishiya / skhd

Simple hotkey daemon for macOS
MIT License
6.07k stars 204 forks source link

Allow modes to use keywords #39

Closed chrishoage closed 6 years ago

chrishoage commented 6 years ago

I want to preface with if this is not possible please feel free to just close this GHI.

I noticed when converting my khdrc to my skhdrc I could no longer use my insert mode name.

My Previous khdrc

khd mode prefix prefix on
khd mode prefix timeout 0.5

# set border color for different modes
khd mode default on_enter chunkc border::color 0xFF6699CC
khd mode prefix on_enter chunkc border::color 0xFFFAC863
khd mode manage on_enter chunkc border::color 0xFFC594C5
khd mode insert on_enter chunkc border::color 0xFFF99157

ctrl - k                  : khd -e "mode activate prefix"
prefix - i                : khd -e "mode activate insert" ; khd -e "void_unlisted_bind off"
prefix - m                : khd -e "mode activate manage"
manage - 0x35             : khd -e "mode activate default"
insert - 0x35             : khd -e "mode activate default" ; khd -e "void_unlisted_bind on"

My desired skhdrc

:: default    : chunkc border::color 0xFF6699CC
:: prefix @   : chunkc border::color 0xFFFAC863
:: insert     : chunkc border::color 0xFFF99157
:: manage @   : chunkc border::color 0xFFC594C5

prefix, insert, manage  < escape    ; default
ctrl - k                            ; prefix
prefix                  < i         ; insert
prefix                  < m         ; manage

However I noticed that skhd would fail with this error

#66:4 expected identifier, but got 'insert'

I changed insert to nobind and it worked, but the error was unexpected, since the syntax for modes mean that it shouldn't care about what the mode is called

This is no huge deal, and basically my only issue converting aside from lack of prefix timeout, which I proposed a solution for here https://github.com/koekeishiya/skhd/issues/37#issuecomment-395995098

koekeishiya commented 6 years ago

This is probably because the mode has the same name as a literal. This isn't really a problem, but is just a consequence of how the tokenizer works right now.

chrishoage commented 6 years ago

This is probably because the mode has the same name as a literal. This isn't really a problem, but is just a consequence of how the tokenizer works right now.

Yeah, that's what I figured. If you don't feel like this should be fixed please do feel free to close this. Just figured I'd report it 😄

koekeishiya commented 6 years ago

Probably not gonna bother changing anything here as it is not really obvious how to avoid ambiguous situations, as a hotkey can start with both a mode or a literal, and if the same keyword is valid for both types, we don't really know where in the parsing process we are at.