@@ -32,39 +32,41 @@ var commands map[string]Command
3232
3333func InitCommands () {
3434 commands = map [string ]Command {
35- "set" : {(* BufPane ).SetCmd , OptionValueComplete },
36- "reset" : {(* BufPane ).ResetCmd , OptionValueComplete },
37- "setlocal" : {(* BufPane ).SetLocalCmd , OptionValueComplete },
38- "show" : {(* BufPane ).ShowCmd , OptionComplete },
39- "showkey" : {(* BufPane ).ShowKeyCmd , nil },
40- "run" : {(* BufPane ).RunCmd , nil },
41- "bind" : {(* BufPane ).BindCmd , nil },
42- "unbind" : {(* BufPane ).UnbindCmd , nil },
43- "quit" : {(* BufPane ).QuitCmd , nil },
44- "goto" : {(* BufPane ).GotoCmd , nil },
45- "jump" : {(* BufPane ).JumpCmd , nil },
46- "save" : {(* BufPane ).SaveCmd , nil },
47- "replace" : {(* BufPane ).ReplaceCmd , nil },
48- "replaceall" : {(* BufPane ).ReplaceAllCmd , nil },
49- "vsplit" : {(* BufPane ).VSplitCmd , buffer .FileComplete },
50- "hsplit" : {(* BufPane ).HSplitCmd , buffer .FileComplete },
51- "tab" : {(* BufPane ).NewTabCmd , buffer .FileComplete },
52- "help" : {(* BufPane ).HelpCmd , HelpComplete },
53- "eval" : {(* BufPane ).EvalCmd , nil },
54- "log" : {(* BufPane ).ToggleLogCmd , nil },
55- "plugin" : {(* BufPane ).PluginCmd , PluginComplete },
56- "reload" : {(* BufPane ).ReloadCmd , nil },
57- "reopen" : {(* BufPane ).ReopenCmd , nil },
58- "cd" : {(* BufPane ).CdCmd , buffer .FileComplete },
59- "pwd" : {(* BufPane ).PwdCmd , nil },
60- "open" : {(* BufPane ).OpenCmd , buffer .FileComplete },
61- "tabmove" : {(* BufPane ).TabMoveCmd , nil },
62- "tabswitch" : {(* BufPane ).TabSwitchCmd , nil },
63- "term" : {(* BufPane ).TermCmd , nil },
64- "memusage" : {(* BufPane ).MemUsageCmd , nil },
65- "retab" : {(* BufPane ).RetabCmd , nil },
66- "raw" : {(* BufPane ).RawCmd , nil },
67- "textfilter" : {(* BufPane ).TextFilterCmd , nil },
35+ "set" : {(* BufPane ).SetCmd , OptionValueComplete },
36+ "setlocal" : {(* BufPane ).SetLocalCmd , OptionValueComplete },
37+ "toggle" : {(* BufPane ).ToggleCmd , OptionValueComplete },
38+ "togglelocal" : {(* BufPane ).ToggleLocalCmd , OptionValueComplete },
39+ "reset" : {(* BufPane ).ResetCmd , OptionValueComplete },
40+ "show" : {(* BufPane ).ShowCmd , OptionComplete },
41+ "showkey" : {(* BufPane ).ShowKeyCmd , nil },
42+ "run" : {(* BufPane ).RunCmd , nil },
43+ "bind" : {(* BufPane ).BindCmd , nil },
44+ "unbind" : {(* BufPane ).UnbindCmd , nil },
45+ "quit" : {(* BufPane ).QuitCmd , nil },
46+ "goto" : {(* BufPane ).GotoCmd , nil },
47+ "jump" : {(* BufPane ).JumpCmd , nil },
48+ "save" : {(* BufPane ).SaveCmd , nil },
49+ "replace" : {(* BufPane ).ReplaceCmd , nil },
50+ "replaceall" : {(* BufPane ).ReplaceAllCmd , nil },
51+ "vsplit" : {(* BufPane ).VSplitCmd , buffer .FileComplete },
52+ "hsplit" : {(* BufPane ).HSplitCmd , buffer .FileComplete },
53+ "tab" : {(* BufPane ).NewTabCmd , buffer .FileComplete },
54+ "help" : {(* BufPane ).HelpCmd , HelpComplete },
55+ "eval" : {(* BufPane ).EvalCmd , nil },
56+ "log" : {(* BufPane ).ToggleLogCmd , nil },
57+ "plugin" : {(* BufPane ).PluginCmd , PluginComplete },
58+ "reload" : {(* BufPane ).ReloadCmd , nil },
59+ "reopen" : {(* BufPane ).ReopenCmd , nil },
60+ "cd" : {(* BufPane ).CdCmd , buffer .FileComplete },
61+ "pwd" : {(* BufPane ).PwdCmd , nil },
62+ "open" : {(* BufPane ).OpenCmd , buffer .FileComplete },
63+ "tabmove" : {(* BufPane ).TabMoveCmd , nil },
64+ "tabswitch" : {(* BufPane ).TabSwitchCmd , nil },
65+ "term" : {(* BufPane ).TermCmd , nil },
66+ "memusage" : {(* BufPane ).MemUsageCmd , nil },
67+ "retab" : {(* BufPane ).RetabCmd , nil },
68+ "raw" : {(* BufPane ).RawCmd , nil },
69+ "textfilter" : {(* BufPane ).TextFilterCmd , nil },
6870 }
6971}
7072
@@ -730,6 +732,65 @@ func (h *BufPane) SetLocalCmd(args []string) {
730732 }
731733}
732734
735+ func (h * BufPane ) toggleOption (option string , local bool ) error {
736+ var curVal , newVal any
737+
738+ if local {
739+ curVal = h .Buf .Settings [option ]
740+ } else {
741+ curVal = config .GetGlobalOption (option )
742+ }
743+ if curVal == nil {
744+ return config .ErrInvalidOption
745+ }
746+
747+ if choices , ok := config .OptionChoices [option ]; ok && len (choices ) == 2 {
748+ if curVal == choices [0 ] {
749+ newVal = choices [1 ]
750+ } else {
751+ newVal = choices [0 ]
752+ }
753+ } else if curValBool , ok := curVal .(bool ); ok {
754+ newVal = ! curValBool
755+ } else {
756+ return config .ErrOptNotToggleable
757+ }
758+
759+ if local {
760+ if err := h .Buf .SetOptionNative (option , newVal ); err != nil {
761+ return err
762+ }
763+ } else {
764+ if err := SetGlobalOptionNative (option , newVal ); err != nil {
765+ return err
766+ }
767+ }
768+
769+ return nil
770+ }
771+
772+ // ToggleCmd toggles a toggleable option
773+ func (h * BufPane ) ToggleCmd (args []string ) {
774+ if len (args ) < 1 {
775+ InfoBar .Error ("Not enough arguments: provide a toggleable option" )
776+ return
777+ }
778+ if err := h .toggleOption (args [0 ], false ); err != nil {
779+ InfoBar .Error (err )
780+ }
781+ }
782+
783+ // ToggleCmd toggles a toggleable option local to the buffer
784+ func (h * BufPane ) ToggleLocalCmd (args []string ) {
785+ if len (args ) < 1 {
786+ InfoBar .Error ("Not enough arguments: provide a toggleable option" )
787+ return
788+ }
789+ if err := h .toggleOption (args [0 ], true ); err != nil {
790+ InfoBar .Error (err )
791+ }
792+ }
793+
733794// ShowCmd shows the value of the given option
734795func (h * BufPane ) ShowCmd (args []string ) {
735796 if len (args ) < 1 {
0 commit comments