summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVille Hakulinen <ville.hakulinen@gmail.com>2020-08-16 13:18:14 +0300
committerVille Hakulinen <ville.hakulinen@gmail.com>2020-08-16 15:05:08 +0300
commit230752ba06e2ee354abd58ee20f1599010d988b4 (patch)
treec4f21f98c40c5eaad64d2b82f920a16056a7ee3b
parent1a47380c296c1ae4e9e82f19538cdac051afe1b7 (diff)
Configure ext options through rpc
Allow configuring (enable, disable) ext options (tabline, cmdline and popupmenu) through rpc. Close #61 Fix #59
-rw-r--r--runtime/autoload/gnvim.vim23
-rw-r--r--runtime/doc/gnvim.txt24
-rw-r--r--runtime/doc/tags4
-rw-r--r--src/nvim_bridge/mod.rs28
-rw-r--r--src/ui/state.rs83
5 files changed, 158 insertions, 4 deletions
diff --git a/runtime/autoload/gnvim.vim b/runtime/autoload/gnvim.vim
new file mode 100644
index 0000000..62515fe
--- /dev/null
+++ b/runtime/autoload/gnvim.vim
@@ -0,0 +1,23 @@
+function! gnvim#enable_ext_tabline(enable)
+ return rpcnotify(
+ \ g:gnvim_channel_id,
+ \ 'Gnvim',
+ \ 'EnableExtTabline',
+ \ a:enable)
+endfunction
+
+function! gnvim#enable_ext_cmdline(enable)
+ return rpcnotify(
+ \ g:gnvim_channel_id,
+ \ 'Gnvim',
+ \ 'EnableExtCmdline',
+ \ a:enable)
+endfunction
+
+function! gnvim#enable_ext_popupmenu(enable)
+ return rpcnotify(
+ \ g:gnvim_channel_id,
+ \ 'Gnvim',
+ \ 'EnableExtPopupmenu',
+ \ a:enable)
+endfunction
diff --git a/runtime/doc/gnvim.txt b/runtime/doc/gnvim.txt
index 2e524be..fc21676 100644
--- a/runtime/doc/gnvim.txt
+++ b/runtime/doc/gnvim.txt
@@ -12,7 +12,8 @@ CONTENTS *gnvim-contents*
1. Cursor Tooltip.......................|gnvim-cursor-tooltip|
2. Popupmenu............................|gnvim-popupmenu|
- 2. Cursor...............................|gnvim-cursor|
+ 3. Cursor...............................|gnvim-cursor|
+ 4. Ext options..........................|gnvim-ext-opts|
================================================================================
Cursor Tooltip *gnvim-cursor-tooltip*
@@ -59,6 +60,14 @@ The cursor also has animated position movement, which is on by default. To
disable it, use `GnvimCursorEnableAnimations 0` .
================================================================================
+Ext options *gnvim-ext-options*
+
+Gnvim utilizes many of the externalized UI options nvim offers. Some of these
+changes the visual representation of some nvim features and thus users might
+want to revert back to the "default" (e.g. TUI) functionality. This can be
+done either through cli flags or `gnvim#enable_ext_*` functions.
+
+================================================================================
Commands *gnvim-commands*
CursorTooltipStyle *CursorTooltipStyle*
@@ -68,6 +77,19 @@ CursorTooltipStyle *CursorTooltipStyle*
================================================================================
Functions *gnvim-functions*
+gnvim#enable_ext_tabline *gnvim#enable_ext_tabline*
+gnvim#enable_ext_cmdline *gnvim#enable_ext_cmdline*
+gnvim#enable_ext_popupmenu *gnvim#enable_ext_popupmeu*
+
+ Enable or disable the externalized tabline/cmdline/popupmenu.
+
+ Example: >
+ " disable:
+ call gnivm#enable_ext_tabline(0)
+ " enable:
+ call gnivm#enable_ext_tabline(1)
+<
+
gnvim#cursor_tooltip#load_style *gnvim#cursor_tooltip#load_style*
Loads `.tmTheme` file to be used in the cursor tooltip.
diff --git a/runtime/doc/tags b/runtime/doc/tags
index c9e3998..d4dc370 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -4,6 +4,9 @@ gnvim#cursor_tooltip#get_styles gnvim.txt /*gnvim#cursor_tooltip#get_styles*
gnvim#cursor_tooltip#hide gnvim.txt /*gnvim#cursor_tooltip#hide*
gnvim#cursor_tooltip#load_style gnvim.txt /*gnvim#cursor_tooltip#load_style*
gnvim#cursor_tooltip#show gnvim.txt /*gnvim#cursor_tooltip#show*
+gnvim#enable_ext_cmdline gnvim.txt /*gnvim#enable_ext_cmdline*
+gnvim#enable_ext_popupmeu gnvim.txt /*gnvim#enable_ext_popupmeu*
+gnvim#enable_ext_tabline gnvim.txt /*gnvim#enable_ext_tabline*
gnvim#popupmenu#set_width gnvim.txt /*gnvim#popupmenu#set_width*
gnvim#popupmenu#set_width_details gnvim.txt /*gnvim#popupmenu#set_width_details*
gnvim#popupmenu#show_menu_on_all_items gnvim.txt /*gnvim#popupmenu#show_menu_on_all_items*
@@ -14,5 +17,6 @@ gnvim-contents gnvim.txt /*gnvim-contents*
gnvim-cursor gnvim.txt /*gnvim-cursor*
gnvim-cursor-blinking gnvim.txt /*gnvim-cursor-blinking*
gnvim-cursor-tooltip gnvim.txt /*gnvim-cursor-tooltip*
+gnvim-ext-options gnvim.txt /*gnvim-ext-options*
gnvim-functions gnvim.txt /*gnvim-functions*
gnvim-popupmenu gnvim.txt /*gnvim-popupmenu*
diff --git a/src/nvim_bridge/mod.rs b/src/nvim_bridge/mod.rs
index c6d4bf6..d5c1c07 100644
--- a/src/nvim_bridge/mod.rs
+++ b/src/nvim_bridge/mod.rs
@@ -212,6 +212,9 @@ pub enum OptionSet {
GuiFont(String),
/// Space between lines.
LineSpace(i64),
+ ExtTabline(bool),
+ ExtCmdline(bool),
+ ExtPopupmenu(bool),
/// Event name.
NotSupported(String),
}
@@ -229,6 +232,9 @@ impl From<Value> for OptionSet {
let val = unwrap_i64!(args[1]);
OptionSet::LineSpace(val)
}
+ "ext_tabline" => OptionSet::ExtTabline(unwrap_bool!(args[1])),
+ "ext_cmdline" => OptionSet::ExtCmdline(unwrap_bool!(args[1])),
+ "ext_popupmenu" => OptionSet::ExtPopupmenu(unwrap_bool!(args[1])),
_ => OptionSet::NotSupported(String::from(name)),
}
}
@@ -977,6 +983,10 @@ pub enum GnvimEvent {
EnableCursorAnimations(bool),
+ EnableExtTabline(bool),
+ EnableExtCmdline(bool),
+ EnableExtPopupmenu(bool),
+
Unknown(String),
}
@@ -1266,6 +1276,24 @@ pub(crate) fn parse_gnvim_event(
"failed to parse enable cursor animations argument"
) == 1,
),
+ "EnableExtTabline" => GnvimEvent::EnableExtTabline(
+ try_u64!(
+ args.get(1).ok_or("argument missing")?,
+ "failed to parse enable ext tabline argument"
+ ) == 1,
+ ),
+ "EnableExtCmdline" => GnvimEvent::EnableExtCmdline(
+ try_u64!(
+ args.get(1).ok_or("argument missing")?,
+ "failed to parse enable ext cmdline argument"
+ ) == 1,
+ ),
+ "EnableExtPopupmenu" => GnvimEvent::EnableExtPopupmenu(
+ try_u64!(
+ args.get(1).ok_or("argument missing")?,
+ "failed to parse enable ext popupmenu argument"
+ ) == 1,
+ ),
_ => GnvimEvent::Unknown(String::from(cmd)),
};
diff --git a/src/ui/state.rs b/src/ui/state.rs
index c4801c9..d2b9908 100644
--- a/src/ui/state.rs
+++ b/src/ui/state.rs
@@ -326,6 +326,27 @@ impl UIState {
self.resize_on_flush = Some(opts);
}
+ OptionSet::ExtTabline(enable) => {
+ let widget = self.tabline.get_widget();
+ widget_show(&widget, enable);
+ }
+ OptionSet::ExtCmdline(enable) => {
+ if !enable {
+ self.cmdline.hide();
+ }
+
+ // NOTE(ville): If the wildmenu is active at this point,
+ // nvim will not "resend" the original wildmenu (popupmenu)
+ // events, this gnvim will incorrectly try to show the cmdline's
+ // custom wildmenu. To "fix" this, the user needs to reopen the
+ // wildmenu/cmdline.
+ }
+ OptionSet::ExtPopupmenu(_enable) => {
+ // Nothing to do... If the popupmenu is active at this point,
+ // nvim seems continue send the ext popupmenu messages until
+ // the popupmenu is closed. At least this is the case at the
+ // time of writing this feature.
+ }
OptionSet::NotSupported(name) => {
debug!("Not supported option set: {}", name);
}
@@ -448,9 +469,12 @@ impl UIState {
let grid = self.grids.get(&self.current_grid).unwrap();
let mut rect = grid.get_rect_for_cell(popupmenu.row, popupmenu.col);
- let window = self.windows.get(&popupmenu.grid).unwrap();
- rect.x += window.x as i32;
- rect.y += window.y as i32;
+ if let Some(window) = self.windows.get(&popupmenu.grid) {
+ rect.x += window.x as i32;
+ rect.y += window.y as i32;
+ } else if popupmenu.grid != 1 {
+ error!("No window for non-default grid ({})", popupmenu.grid);
+ }
self.popupmenu.set_anchor(rect);
self.popupmenu
@@ -851,6 +875,51 @@ impl UIState {
GnvimEvent::EnableCursorAnimations(enable) => {
self.enable_cursor_animations(*enable);
}
+ GnvimEvent::EnableExtTabline(enable) => {
+ let nvim = nvim.clone();
+ let enable = *enable;
+ spawn_local(async move {
+ if let Err(err) = nvim
+ .ui_set_option(
+ "ext_tabline",
+ rmpv::Value::Boolean(enable),
+ )
+ .await
+ {
+ error!("Failed to set ext_tabline option: {}", err);
+ }
+ });
+ }
+ GnvimEvent::EnableExtCmdline(enable) => {
+ let nvim = nvim.clone();
+ let enable = *enable;
+ spawn_local(async move {
+ if let Err(err) = nvim
+ .ui_set_option(
+ "ext_cmdline",
+ rmpv::Value::Boolean(enable),
+ )
+ .await
+ {
+ error!("Failed to set ext_cmdline option: {}", err);
+ }
+ });
+ }
+ GnvimEvent::EnableExtPopupmenu(enable) => {
+ let nvim = nvim.clone();
+ let enable = *enable;
+ spawn_local(async move {
+ if let Err(err) = nvim
+ .ui_set_option(
+ "ext_popupmenu",
+ rmpv::Value::Boolean(enable),
+ )
+ .await
+ {
+ error!("Failed to set ext_popupmenu option: {}", err);
+ }
+ });
+ }
GnvimEvent::Unknown(msg) => {
debug!("Received unknown GnvimEvent: {}", msg);
}
@@ -961,6 +1030,14 @@ pub fn attach_grid_events(grid: &Grid, nvim: GioNeovim) {
}));
}
+fn widget_show(widget: &gtk::Widget, show: bool) {
+ if show {
+ widget.show();
+ } else {
+ widget.hide();
+ }
+}
+
fn win_float_anchor_pos(
evt: &WindowFloatPos,
anchor_metrics: &GridMetrics,