Search code examples
keyboardkeymankeyman-developer

How do I efficiently control normalisation in a keyman keyboard using groups?


I am in the process of refactoring and redesigning the code in a few keyboards. The keyboards use options to control whether Unicode Normalisation Form C (NFC) or Normalisation Form D (NFD) is used.

An example of how I currently implement this is :

if(nfc = "1") + any(diaeresisKeys) > U+0308 use(nfc_processing)
if(nfc = "0") + any(diaeresisKeys) > U+0308 use(nfd_processing)

I will be adding support for marking tones, and this will multiply the number of rules requiring redirection to another group.

This there a more efficient mechanism for flow control?


Solution

  • The way you are doing it is good for single rules. If you have multiple places where you want to do normalisation, you may find it better to move the if() statement to a separate context-only group, for example:

    + any(diaeresisKey) > U+0308 use(normalise)
    
    group(normalise)
    
    if(nfc = "1") > use(nfc_group)
    if(nfc = "0") > use(nfd_group)
    

    That means that you are doing the test in only one place, halving the number of rules.

    To simplify even further, you can use the match rule which is processed once after any rule in its group is matched. This DRYs out the use statements:

    + any(diaeresisKey) > U+0308
    
    match > use(normalise) 
    
    group(normalise)
    
    if(nfc = "1") > use(nfc_group)
    if(nfc = "0") > use(nfd_group)