From e0b7533c39a02af6b54ad15425e67798ca1db5dc Mon Sep 17 00:00:00 2001 From: bakpakin Date: Thu, 12 May 2022 15:36:29 -0500 Subject: [PATCH] Add toggle macro. --- src/boot/boot.janet | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index d7113da5..546a7461 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -75,6 +75,11 @@ [name & more] ~(var ,name :private ,;more)) +(defmacro toggle + "Set a value to its boolean inverse. Same as `(set value (not value))`." + [value] + ~(set ,value (,not ,value))) + (defn defglobal "Dynamically create a global def." [name value] @@ -2950,7 +2955,7 @@ :italics ["*" "*"] :bold ["**" "**"]})) (def modes @{}) - (defn toggle [mode] + (defn toggle-mode [mode] (def active (get modes mode)) (def delims (get delimiters mode)) (put modes mode (not active)) @@ -3060,7 +3065,7 @@ (def token @"") (var token-length 0) (defn delim [mode] - (def d (toggle mode)) + (def d (toggle-mode mode)) (if-not has-color (+= token-length (length d))) (buffer/push token d)) (defn endtoken []