Created
February 24, 2025 02:04
-
-
Save agent-kilo/7af50372541f36dac82b79a5e71db575 to your computer and use it in GitHub Desktop.
A simple fix for Jwno 0.9.11, to prevent multiple `:ui-hint` commands from running simultaneously.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # ui-hint-crash-fix.janet | |
| # | |
| # A simple fix for Jwno (https://github.com/agent-kilo/jwno) 0.9.11, to | |
| # prevent multiple :ui-hint commands from running simultaneously, which | |
| # may cause Jwno to crash or leak memory. | |
| # | |
| # To enable the fix, put this file alongside your config file, and | |
| # | |
| # (import ui-hint-crash-fix) | |
| # # ui-hint should be the object returned by (ui-hint/ui-hint jwno/context) | |
| # (ui-hint-crash-fix/patch ui-hint) | |
| # | |
| # To undo the fix, | |
| # | |
| # (ui-hint-crash-fix/unpatch ui-hint) | |
| # | |
| (import jwno/log) | |
| (defn patch [ui-hint] | |
| (def patched-cmd | |
| (fn [self raw-key-list &opt cond-spec action] | |
| (def hook-fn (in self :hook-fn)) | |
| (log/debug "patched-cmd for ui-hint: hook-fn = %n" hook-fn) | |
| (unless hook-fn | |
| (def proto (table/getproto self)) | |
| (def orig-cmd (in proto :cmd)) | |
| (orig-cmd self raw-key-list cond-spec action)))) | |
| (def patched-clean-up | |
| (fn [self] | |
| (log/debug "patched-clean-up for ui-hint") | |
| (def proto (table/getproto self)) | |
| (def orig-clean-up (in proto :clean-up)) | |
| (orig-clean-up self) | |
| (put self :hook-fn nil) | |
| (put self :labeled-elems nil))) | |
| (def patched-disable | |
| (fn [self] | |
| (log/debug "patched-disable for ui-hint") | |
| (def proto (table/getproto self)) | |
| (def orig-disable (in proto :disable)) | |
| (when (in self :hook-fn) | |
| (log/debug "patched ui-hint-disable called when :ui-hint command is in progress") | |
| (:clean-up self)) | |
| (orig-disable self))) | |
| (put ui-hint :cmd patched-cmd) | |
| (put ui-hint :clean-up patched-clean-up) | |
| (put ui-hint :disable patched-disable) | |
| ui-hint) | |
| (defn unpatch [ui-hint] | |
| (put ui-hint :cmd nil) | |
| (put ui-hint :clean-up nil) | |
| (put ui-hint :disable nil) | |
| ui-hint) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment