21096b8

Pinchord · pinchord.git · Tickets · Changelog

Branches > pre-release-31-4 > 21096b8 > files / setup.cfg

Extend affixes to all entries, including user-defined ones

Grahp, 2026-10-24

Commit: 21096b8a01a6d12e848fc04f6e0d284d9fc84cd1
Parent: afd7d11

4 changed files:

plover-description.md modified (view file)

@@ -1,5 +1,7 @@ Pinchord is a chorded keyboard layout, you can read more about it at https://grahp.dev/pinchord :) +Make sure to enable the "Pinchord" plugin in the `Plugins` tab as well as the system! (the plugin does nothing when the system isn't being used)+ It's still in pre-release, so keep that in mind.  Thanks to Kate (https://codeberg.org/StrawberryTurtle, https://github.com/StrawberryTurtle), Harri (https://github.com/StenoHarri), Zak (https://zakventer.com), and @novachromatic for help and influence!

plover_pinchord_31/dictionaries/pinchord-31-1.py modified (view file)

@@ -5,7 +5,7 @@ ## Longest valid outline, Pinchord only needs one stroke outlines :) LONGEST_KEY = 1 -BANKS = ["prefixes", "initials", "vowels", "finals", "suffixes"]+BANKS = ["initials", "vowels", "finals"]  ## Unlike Shrimple, Pinchord enumerates all bank chords! DICT = {"initials": {"WH&": "hw",@@ -326,25 +326,15 @@                    "RPKFST": "rcy",                    "LPFS": "lz",                    "LRPKFT*": "ncky",-                   "LFST": "lth"},-        "suffixes": {"e": "{^}e",-                     "s": "{^}s",-                     "es": "{^}es"},-        "prefixes": {"+": "{^}",-                     "#": "{-|}",-                     "#+": "{^}{-|}",-                     "": "{}"}}+                   "LFST": "lth"}} -BANK_SPLITTING_REGEX = r"(#?\+?)(T?S?P?W?H?R?&?)(A?O?I?U?\^?\-?)(L?R?P?K?F?S?T?\*?)(e?s?)"--EMPTY_TRANSLATION = ""+BANK_SPLITTING_REGEX = r"(T?S?P?W?H?R?&?)(A?O?I?U?\^?\-?)(L?R?P?K?F?S?T?\*?)"  def banks(stroke):-    match = re.match(BANK_SPLITTING_REGEX, stroke)+    match = re.fullmatch(BANK_SPLITTING_REGEX, stroke)     if match:-        ## These should really be extensible!-        prefix, initials, vowels, finals, suffixes = match.groups()-        return {"prefixes": prefix, "initials": initials, "vowels": vowels, "finals": finals, "suffixes": suffixes}+        initials, vowels, finals = match.groups()+        return {"initials": initials, "vowels": vowels, "finals": finals}     else:         return None @@ -360,11 +350,11 @@     if stroke_banks:         return build_translation(stroke_banks)     else:-        return EMPTY_TRANSLATION+        raise KeyError(stroke)  def lookup(outline):     if len(outline) > LONGEST_KEY:-        return EMPTY_TRANSLATION+        raise KeyError(outline)     else:         stroke = outline[0]         return lookup_stroke(stroke)

plover_pinchord_31/extension.py added (view file)

@@ -0,0 +1,52 @@+## Makes the affix keys work on every entry, even user-defined ones+from plover import system+from plover.steno import Stroke++PREFIXES = {(): "{}",+            ("#-",): "{}{-|}",+            ("+-",): "{^}",+            ("#-", "+-"): "{^}{-|}"}++SUFFIXES = {(): "",+            ("-e",): "{^}e",+            ("-s",): "{^}s",+            ("-e", "-s"): "{^}es"}++# Wraps the given translation in its affix translations+# e.g. with_affixes(Stroke("#"), "test", Stroke("-s")) -> "{}{-|}test{^}s"+def with_affixes(prefixes, translation, suffixes):+  if translation is None:+    return None+  else:+    return PREFIXES[prefixes.keys()] + translation + SUFFIXES[suffixes.keys()]++# Looks up the stroke in the dictionary stack after splitting the affix keys,+# returns the translation joined with the affix key translations+def affixed_lookup(lookup, stroke):+  prefixes = stroke & Stroke("#+")+  suffixes = stroke & Stroke("-es")+  stroke_without_affixes = stroke - prefixes - suffixes+  stroke_entry = lookup((stroke.rtfcre,))++  if stroke_entry is not None and stroke != stroke_without_affixes:+    return stroke_entry+  else:+    return with_affixes(prefixes, lookup((stroke_without_affixes.rtfcre,)), suffixes)++class Extension:+  def __init__(self, engine):+    self.dictionaries = engine.dictionaries+    self.original_lookup = self.dictionaries.lookup++  def start(self):+    self.dictionaries.lookup = self.lookup++  def stop(self):+    self.dictionaries.lookup = self.original_lookup++  def lookup(self, outline):+      # inlines the system name, be aware!+    if system.NAME == "Pinchord" and len(outline) == 1:+      return affixed_lookup(self.original_lookup, Stroke.from_steno(outline[0]))+    else:+      return self.original_lookup(outline)

setup.cfg modified (view file)

@@ -27,3 +27,5 @@ [options.entry_points] plover.system =   Pinchord = plover_pinchord_31.system+plover.extension =+  Pinchord = plover_pinchord_31.extension:Extension