From c3d30177b192ae8e4795a1f8c34a37a164527e8b Mon Sep 17 00:00:00 2001 From: daa Date: Wed, 8 Mar 2017 22:22:58 +0300 Subject: [PATCH] paste command improvement --- src/nvim.rs | 14 ++++++++++++++ src/ui.rs | 26 +++++++++++++++----------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/nvim.rs b/src/nvim.rs index 3a1627f..c9534cf 100644 --- a/src/nvim.rs +++ b/src/nvim.rs @@ -188,3 +188,17 @@ fn safe_call(cb: F) glib::Continue(false) }); } + +pub trait ErrorReport { + fn report_err(&self, nvim: &mut NeovimApi, ctx_msg: &str); +} + +impl ErrorReport for result::Result { + fn report_err(&self, _: &mut NeovimApi, ctx_msg: &str) { + if let &Err(ref msg) = self { + let err_msg = format!("{} {}", ctx_msg, msg); + println!("{}", err_msg); + //nvim.report_error(&err_msg).expect("Error report error :)"); + } + } +} diff --git a/src/ui.rs b/src/ui.rs index 9daec5f..8e3575e 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -16,7 +16,7 @@ use glib; use neovim_lib::{Neovim, NeovimApi, Value, Integer}; use ui_model::{UiModel, Attrs, Color, COLOR_BLACK, COLOR_WHITE}; -use nvim::{RedrawEvents, GuiApi}; +use nvim::{RedrawEvents, GuiApi, ErrorReport}; use input::{convert_key, keyval_to_input_string}; @@ -189,12 +189,17 @@ fn gtk_motion_notify(_: &DrawingArea, ev: &EventMotion) -> Inhibit { } fn edit_paste() { - UI.with(|ui_cell| { + UI.with(|ui_cell| { let mut ui = ui_cell.borrow_mut(); - if let Err(e) = ui.nvim().input("\"*p") { - println!("Error paste from clipboard {}", e); - } + let paste_command = if ui.mode == NvimMode::Normal { + "\"*p" + } else { + "\"*p" + }; + + let mut nvim = ui.nvim(); + nvim.input(paste_command).report_err(nvim, "Error paste from clipboard"); }); } @@ -202,9 +207,8 @@ fn edit_save_all() { UI.with(|ui_cell| { let mut ui = ui_cell.borrow_mut(); - if let Err(e) = ui.nvim().command(":wa") { - println!("Error save all files {}", e); - } + let mut nvim = ui.nvim(); + nvim.command(":wa").report_err(nvim, "Error save all files"); }); } @@ -396,9 +400,9 @@ fn request_width(ui: &Ui) { } impl GuiApi for Ui { - fn set_font(&mut self, font_desc: &str) { - self.set_font_desc(font_desc); - } + fn set_font(&mut self, font_desc: &str) { + self.set_font_desc(font_desc); + } } impl RedrawEvents for Ui {