Add neovim-qt compatible layer (#5)

Add shim to rtp, add gtk gui flag
This commit is contained in:
daa 2017-05-24 14:00:23 +03:00
parent c16f70ac1d
commit 64c5fb1147
3 changed files with 61 additions and 0 deletions

View File

@ -10,6 +10,8 @@ install: install-resources
cargo install --root $(PREFIX) cargo install --root $(PREFIX)
install-resources: install-resources:
mkdir -p $(PREFIX)/share/nvim-gtk/
cp -r runtime $(PREFIX)/share/nvim-gtk/
mkdir -p $(PREFIX)/share/applications/ mkdir -p $(PREFIX)/share/applications/
cp desktop/nvim-gtk.desktop $(PREFIX)/share/applications/ cp desktop/nvim-gtk.desktop $(PREFIX)/share/applications/
mkdir -p $(PREFIX)/share/icons/hicolor/128x128/apps/ mkdir -p $(PREFIX)/share/icons/hicolor/128x128/apps/

View File

@ -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("<args>", "<bang>")
command! -nargs=? -bang GuiFont call s:GuiFontCommand("<args>", "<bang>")

View File

@ -1,4 +1,5 @@
use std::io::{Result, Error, ErrorKind}; use std::io::{Result, Error, ErrorKind};
use std::env;
use std::process::{Stdio, Command}; use std::process::{Stdio, Command};
use std::result; use std::result;
use std::sync::Arc; use std::sync::Arc;
@ -82,8 +83,21 @@ pub fn initialize(shell: Arc<UiMutex<shell::State>>,
.arg("--headless") .arg("--headless")
.arg("--cmd") .arg("--cmd")
.arg("set termguicolors") .arg("set termguicolors")
.arg("--cmd")
.arg("let g:GtkGuiLoaded = 1")
.stderr(Stdio::inherit()); .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 = Session::new_child_cmd(&mut cmd);
let session = match session { let session = match session {