1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
extern crate neovim_lib; extern crate nvimpam_lib; use std::alloc::System; #[global_allocator] static GLOBAL: System = System; use std::{path::Path, process::Command, sync::mpsc}; use nvimpam_lib::{ card::keyword::Keywords, event::Event::*, folds::FoldList, handler::NeovimHandler, lines::Lines, }; use neovim_lib::{neovim::Neovim, neovim_api::NeovimApi, session::Session}; fn main() { let (sender, receiver) = mpsc::channel(); let nvimpath = Path::new("neovim").join("build").join("bin").join("nvim"); let mut session = Session::new_child_cmd( Command::new(nvimpath) .args(&["-u", "NONE", "--embed"]) .env("VIMRUNTIME", "neovim/runtime"), ) .unwrap(); session.start_event_loop_handler(NeovimHandler(sender)); let mut nvim = Neovim::new(session); nvim.command("set noswapfile").expect("0"); nvim.command("execute 'set rtp +='.getcwd()").expect("1"); nvim.command("silent e! files/example.pc").expect("2"); let curbuf = nvim.get_current_buf().expect("3"); let mut foldlist = FoldList::new(); let origlines = Lines::read_file("files/example.pc").expect("3.1"); let lines = Lines::from_slice(&origlines); let keywords = Keywords::from_lines(&lines); curbuf.attach(&mut nvim, false, vec![]).expect("4"); while let Ok(ChangedTickEvent { .. }) = receiver.recv() { foldlist.recreate_all(&keywords, &lines).expect("5"); foldlist.resend_all(&mut nvim).expect("6"); curbuf.detach(&mut nvim).expect("7"); nvim.command("call rpcnotify(1, 'quit')").unwrap(); } }