FS#74 - generic toggle command
Attached to Project:
Uzbl
Opened by Dieter Plaetinck (Dieter_be) - 2009-07-19 06:55:47 PM
Last edited by Brendan Taylor (bct) - 2011-10-05 04:34:03 AM
Opened by Dieter Plaetinck (Dieter_be) - 2009-07-19 06:55:47 PM
Last edited by Brendan Taylor (bct) - 2011-10-05 04:34:03 AM
|
Detailsinstead of specific functions like "toggle_insert_mode" and such I think it would be better to have a generic "toggle" function that would work on various variables (similar to "set")
|
This task depends upon
Closed by Brendan Taylor (bct)
2011-10-05 04:34:03 AM
Reason for closing: Implemented
Additional comments about closing: i've implemented this (including cycling between multiple values) on the experimental branch. it only took 2 years :)
2011-10-05 04:34:03 AM
Reason for closing: Implemented
Additional comments about closing: i've implemented this (including cycling between multiple values) on the experimental branch. it only took 2 years :)
The reason this is so easy to do with modes is that they don't contain any spaces or other special characters so I can easily iterate through a space-split set of arguments and 'toggle the mode'. This changes when I'm toggling through variables that have spaces in them.
So do we:
# @set_toggle <name> <key> = <value>
set set_toggle = request SET_TOGGLE
# @toggle <name>
set toggle = event TRIGGER_TOGGLE
# @clear_toggle <name>
set clear_toggle = event CLEAR_TOGGLE
Then:
@set_toggle mode_toggle mode = insert
@set_toggle mode_toggle mode = command
@set_toggle mode_toggle mode = visual
Using the brace_expansion plugin this isn't so cumbersome:
@expand @set_toggle mode_toggle mode = {insert,command,visual}
Then to trigger it:
@bind <Ctrl>i = @toggle mode_toggle
What do you think?
The problem with this approach is when a user:
@set_toggle my_toggle mode = insert
@set_toggle my_toggle set_status = 0
@set_toggle my_toggle mode = command
What happens then?
The original "toggle_insert_mode" example doesn't apply anymore but we still have this in uzbl core:
- toggle_zoom_type
- toggle_status
which should be replaced by a toggle command so we can do 'toggle zoom_type'
Now, for your EM implementation:
Are you suggesting to write a plugin so that users can define a list of possible values, which can then be iterated? [no need to define them all separately, right?]
why not use a python dictionary for that?
something like:
set values = request VALUES_DEFINE
set next = request VALUES_NEXT
set prev = request VALUES_PREV
@values mode = {'insert','command','visual'} # your plugin will keep a data structure with for each key (here 'mode'), a list of options
@prev mode # your plugin picks the previous thing in the dictionary.