1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 14:44:48 +00:00

Add toggle macro.

This commit is contained in:
bakpakin 2022-05-12 15:36:29 -05:00
parent 5b2a402930
commit e0b7533c39

View File

@ -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 []