mrob95 / Breathe

High-level API for creating dragonfly grammars
GNU Lesser General Public License v3.0
13 stars 8 forks source link

When does enabling or disabling CommandContext take effect? #4

Closed droundy closed 4 years ago

droundy commented 4 years ago

I'm wondering whether within a CCR it is effective to disable/enable a CommandContext? I'm thinking of using this to enable changes between text and math modes for latex, but am unsure of the implications of such a trick. If there is a better approach for such a "mode switching" grammar I'd love to hear about it.

mrob95 commented 4 years ago

If you have CommandContext("test") then the contact will be activated and deactivated by the "enable test" and "disable test" commands IIRC

droundy commented 4 years ago

I was thinking to set

test_context = CommandContext("test")

and then have a Function(lambda: test_context.disable()) attached to a rule.

mrob95 commented 4 years ago

Yes, that should work and is almost exactly what the enable and disable commands do.

One thing to note with this though is that the object you call disable on must be the exact same object you pass to context=. It's not enough to call CommandContext in two places with the same argument. (If you're familiar with pointers in other languages then this will make sense)