inline temps and whitespace, improve update-widget-state
update-widget-state accepts a second parameter which duplicates information available in self.state. This commit gets rid of some not all of it
This commit is contained in:
parent
c1b7c2d777
commit
9775e00545
38
command.fnl
38
command.fnl
@ -24,21 +24,15 @@
|
|||||||
|
|
||||||
(define-command
|
(define-command
|
||||||
"switch-to-buffer"
|
"switch-to-buffer"
|
||||||
[[:buffer
|
[[:buffer Buffer.match #(. (Buffer.next $1.buffer) :name)]]
|
||||||
Buffer.match
|
(fn [{: frame : buffer}]
|
||||||
#(. (Buffer.next $1.buffer) :name)]
|
|
||||||
]
|
|
||||||
(fn [{:frame frame :buffer buffer}]
|
|
||||||
(frame:show-buffer buffer)))
|
(frame:show-buffer buffer)))
|
||||||
|
|
||||||
(define-command
|
(define-command
|
||||||
"visit-location"
|
"visit-location"
|
||||||
[[:buffer
|
[[:buffer Buffer.match #$1.buffer.name]
|
||||||
Buffer.match
|
[:url #{$1 $1} #($1.buffer:location)]]
|
||||||
#$1.buffer.name]
|
(fn [{: url : buffer}]
|
||||||
[:url #{$1 $1} #($1.buffer:location)]
|
|
||||||
]
|
|
||||||
(fn [{:url url :buffer buffer}]
|
|
||||||
(buffer:visit url)))
|
(buffer:visit url)))
|
||||||
|
|
||||||
(define-command
|
(define-command
|
||||||
@ -93,8 +87,7 @@
|
|||||||
|
|
||||||
{:command c :this-param k :collected-params p}
|
{:command c :this-param k :collected-params p}
|
||||||
(let [{ : completer} (. c.params k)
|
(let [{ : completer} (. c.params k)
|
||||||
vals (completer input-string)
|
value (. (completer input-string) input-string)]
|
||||||
value (. vals input-string)]
|
|
||||||
(tset p k value)
|
(tset p k value)
|
||||||
(state-for-next-param c p))
|
(state-for-next-param c p))
|
||||||
|
|
||||||
@ -110,20 +103,20 @@
|
|||||||
param (if s.active (. (. s.command :params) s.this-param))]
|
param (if s.active (. (. s.command :params) s.this-param))]
|
||||||
(set self.state s)
|
(set self.state s)
|
||||||
{
|
{
|
||||||
:active s.active
|
|
||||||
:error s.error
|
:error s.error
|
||||||
:prompt (if s.active (or s.this-param "Command?" "") "")
|
:prompt (if s.active (or s.this-param "Command?" "") "")
|
||||||
:default (and param (param.default self.frame))
|
:default (and param (param.default self.frame))
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(fn update-widget-state [{ : widget : entry : completions-widget : prompt} result]
|
(fn update-widget-state [{ : state : widget : entry : completions-widget : prompt} result]
|
||||||
(set prompt.label (or result.prompt ""))
|
(set prompt.label (or result.prompt ""))
|
||||||
(set entry.sensitive result.active)
|
(set entry.sensitive state.active)
|
||||||
(if (not result.active)
|
(if (not state.active)
|
||||||
(completions-widget:hide))
|
(completions-widget:hide))
|
||||||
(set entry.text (or result.default result.error ""))
|
(set entry.text (or result.default result.error ""))
|
||||||
(widget.parent:set_visible_child_name
|
(match widget.parent
|
||||||
(if result.active "commander" "echo-area")))
|
p (p:set_visible_child_name
|
||||||
|
(if state.active "commander" "echo-area"))))
|
||||||
|
|
||||||
(fn on-input [self str]
|
(fn on-input [self str]
|
||||||
(match self.state
|
(match self.state
|
||||||
@ -146,17 +139,16 @@
|
|||||||
(tset state :active true)
|
(tset state :active true)
|
||||||
(update-widget-state
|
(update-widget-state
|
||||||
self
|
self
|
||||||
{:active true
|
{
|
||||||
:prompt (or state.this-param "Command" "")
|
:prompt (or state.this-param "Command" "")
|
||||||
})
|
})
|
||||||
(entry:grab_focus)
|
(entry:grab_focus))
|
||||||
state)
|
|
||||||
|
|
||||||
(fn deactivate [{: state : entry : prompt &as self}]
|
(fn deactivate [{: state : entry : prompt &as self}]
|
||||||
(doto state
|
(doto state
|
||||||
(lume.clear)
|
(lume.clear)
|
||||||
(tset :active false))
|
(tset :active false))
|
||||||
(update-widget-state self {:active false}))
|
(update-widget-state self {}))
|
||||||
|
|
||||||
(fn invoke-interactively [self name params]
|
(fn invoke-interactively [self name params]
|
||||||
(let [c (find-command name)
|
(let [c (find-command name)
|
||||||
|
Loading…
Reference in New Issue
Block a user