Struct nvim_gtk::subscriptions::Subscriptions [−][src]
A map of all registered subscriptions.
Implementations
impl Subscriptions
[src]
pub fn new() -> Self
[src]
pub fn subscribe<F>(
&mut self,
key: SubscriptionKey,
args: &[&str],
cb: F
) -> SubscriptionHandle where
F: Fn(Vec<String>) + 'static,
[src]
&mut self,
key: SubscriptionKey,
args: &[&str],
cb: F
) -> SubscriptionHandle where
F: Fn(Vec<String>) + 'static,
Subscribe to a Neovim autocmd event.
Subscriptions are not active immediately but only after set_autocmds
is called. At the
moment, all calls to subscribe
must be made before calling set_autocmds
.
This function is wrapped by shell::State
.
Arguments:
-
key
: The subscription key to register. See:help autocmd-events
for a list of supported event names. Event names can be comma-separated. -
args
: A list of expressions to be evaluated when the event triggers. Expressions are evaluated using Vimscript. The results are passed to the callback as a list of Strings. This is especially useful asNeovim::eval
is synchronous and might block if called from the callback function; so always use theargs
mechanism instead. -
cb
: The callback function. This will be called each time the event triggers or whenrun_now
is called. It is passed a vector with the results of the evaluated expressions given withargs
.
Example
Call a function each time a buffer is entered or the current working directory is changed. Pass the current buffer name and directory to the callback.
let my_subscription = shell.state.borrow() .subscribe("BufEnter,DirChanged", &["expand(@%)", "getcwd()"], move |args| { let filename = &args[0]; let dir = &args[1]; // do stuff });
pub fn set_autocmds(&self, nvim: &mut NeovimRef<'_>)
[src]
Register all subscriptions with Neovim.
This function is wrapped by shell::State
.
fn on_notify(&self, key: &SubscriptionKey, index: usize, args: Vec<String>)
[src]
Trigger given event.
pub fn notify(&self, params: Vec<Value>) -> Result<(), String>
[src]
Wrapper around on_notify
for easy calling with a neovim_lib::Handler
implementation.
This function is wrapped by shell::State
.
pub fn run_now(&self, handle: &SubscriptionHandle, nvim: &mut NeovimRef<'_>)
[src]
Manually trigger the given subscription.
The nvim
instance is needed to evaluate the args
expressions.
This function is wrapped by shell::State
.
Auto Trait Implementations
impl !RefUnwindSafe for Subscriptions
impl !Send for Subscriptions
impl !Sync for Subscriptions
impl Unpin for Subscriptions
impl !UnwindSafe for Subscriptions
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,