From 64c5fb114741b83b672a1b89a21006292ff1ec96 Mon Sep 17 00:00:00 2001 From: daa Date: Wed, 24 May 2017 14:00:23 +0300 Subject: [PATCH] Add neovim-qt compatible layer (#5) Add shim to rtp, add gtk gui flag --- Makefile | 2 ++ runtime/plugin/nvim_gui_shim.vim | 45 ++++++++++++++++++++++++++++++++ src/nvim.rs | 14 ++++++++++ 3 files changed, 61 insertions(+) create mode 100644 runtime/plugin/nvim_gui_shim.vim diff --git a/Makefile b/Makefile index 3d2b792..e5b2b56 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ install: install-resources cargo install --root $(PREFIX) install-resources: + mkdir -p $(PREFIX)/share/nvim-gtk/ + cp -r runtime $(PREFIX)/share/nvim-gtk/ mkdir -p $(PREFIX)/share/applications/ cp desktop/nvim-gtk.desktop $(PREFIX)/share/applications/ mkdir -p $(PREFIX)/share/icons/hicolor/128x128/apps/ diff --git a/runtime/plugin/nvim_gui_shim.vim b/runtime/plugin/nvim_gui_shim.vim new file mode 100644 index 0000000..8e48dbe --- /dev/null +++ b/runtime/plugin/nvim_gui_shim.vim @@ -0,0 +1,45 @@ +" A Neovim plugin that implements GUI helper commands +if !has('nvim') || exists('g:GuiLoaded') + finish +endif +let g:GuiLoaded = 1 + +" Set GUI font +function! GuiFont(fname, ...) abort + call rpcnotify(1, 'Gui', 'Font', s:NvimQtToPangoFont(a:fname)) +endfunction + +" Some subset of parse command from neovim-qt +" to support interoperability +function s:NvimQtToPangoFont(fname) + let l:attrs = split(a:fname, ':') + let l:size = -1 + for part in l:attrs + if len(part) >= 2 && part[0] == 'h' + let l:size = strpart(part, 1) + endif + endfor + + if l:size > 0 + return l:attrs[0] . ' ' . l:size + endif + + return l:attrs[0] +endf + + +" The GuiFont command. For compatibility there is also Guifont +function s:GuiFontCommand(fname, bang) abort + if a:fname ==# '' + if exists('g:GuiFont') + echo g:GuiFont + else + echo 'No GuiFont is set' + endif + else + call GuiFont(a:fname, a:bang ==# '!') + endif +endfunction +command! -nargs=? -bang Guifont call s:GuiFontCommand("", "") +command! -nargs=? -bang GuiFont call s:GuiFontCommand("", "") + diff --git a/src/nvim.rs b/src/nvim.rs index acef1d8..ba90e07 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -1,4 +1,5 @@ use std::io::{Result, Error, ErrorKind}; +use std::env; use std::process::{Stdio, Command}; use std::result; use std::sync::Arc; @@ -82,8 +83,21 @@ pub fn initialize(shell: Arc>, .arg("--headless") .arg("--cmd") .arg("set termguicolors") + .arg("--cmd") + .arg("let g:GtkGuiLoaded = 1") .stderr(Stdio::inherit()); + if let Ok(runtime_path) = env::var("NVIM_GTK_RUNTIME_PATH") { + cmd.arg("--cmd") + .arg(format!("let &rtp.=',{}'", runtime_path)); + } + else if let Some(prefix) = option_env!("PREFIX") { + cmd.arg("--cmd") + .arg(format!("let &rtp.=',{}/share/nvim-gtk/runtime'", prefix)); + } else { + cmd.arg("--cmd").arg("let &rtp.=',runtime'"); + } + let session = Session::new_child_cmd(&mut cmd); let session = match session {