From be8b82665922ea08d4584e1e7ed7a5779cd6b4d5 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 16 Apr 2022 02:02:58 -0400 Subject: [PATCH 1/8] feat: add the files into a settings parameter --- src/cmd_line.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index adee7be..510d341 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -22,6 +22,8 @@ pub struct CmdLineSettings { pub neovim_bin: Option, pub wayland_app_id: String, pub x11_wm_class: String, + // Command-line arguments with multiple files + pub files: Vec, } impl Default for CmdLineSettings { @@ -45,6 +47,8 @@ impl Default for CmdLineSettings { neovim_bin: None, wayland_app_id: String::new(), x11_wm_class: String::new(), + // Command-line arguments with multiple files + files: vec![], } } } @@ -197,6 +201,11 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .map(|v| v.to_owned()) .or_else(|| std::env::var("NEOVIDE_X11_WM_CLASS").ok()) .unwrap_or_else(|| "neovide".to_owned()), + // Command-line arguments with multiple files + files: matches + .values_of("files_to_open") + .map(|opt| opt.map(|v| v.to_owned()).collect()) + .unwrap_or_default(), }); Ok(()) } From 4d073ae168675f9c760e51962d2729833c408362 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 16 Apr 2022 02:03:36 -0400 Subject: [PATCH 2/8] feat: open each files a new tab --- src/bridge/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 89afd63..f9ab352 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -85,6 +85,17 @@ async fn start_neovim_runtime() { let nvim = Arc::new(nvim); start_ui_command_handler(nvim.clone()); + + // Verify if the files to open is more than one + if settings.files.len() > 1 { + // Open the first file into a first window + let first_file = settings.files.first().unwrap(); + nvim.command(format!("e {}", first_file).as_str()).await.unwrap_or_explained_panic("Could not create new tab"); + // Open the rest of the files into new tabs + for file in settings.files.iter().skip(1) { + nvim.command(format!("tabnew {}", file).as_str()).await.unwrap_or_explained_panic("Could not create new tab"); + } + } SETTINGS.read_initial_values(&nvim).await; SETTINGS.setup_changed_listeners(&nvim).await; From f125f054ff2ff9a9284e2fc875b5c78f3b78bf08 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 16 Apr 2022 02:13:58 -0400 Subject: [PATCH 3/8] fix: bad format of code --- src/bridge/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index f9ab352..411fae3 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -85,15 +85,14 @@ async fn start_neovim_runtime() { let nvim = Arc::new(nvim); start_ui_command_handler(nvim.clone()); - + // Verify if the files to open is more than one if settings.files.len() > 1 { - // Open the first file into a first window - let first_file = settings.files.first().unwrap(); - nvim.command(format!("e {}", first_file).as_str()).await.unwrap_or_explained_panic("Could not create new tab"); // Open the rest of the files into new tabs for file in settings.files.iter().skip(1) { - nvim.command(format!("tabnew {}", file).as_str()).await.unwrap_or_explained_panic("Could not create new tab"); + nvim.command(format!("tabnew {}", file).as_str()) + .await + .unwrap_or_explained_panic("Could not create new tab"); } } SETTINGS.read_initial_values(&nvim).await; From c3533897ac6fd25f016a485ce8bbfe417a84dca0 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 16 Apr 2022 11:00:28 -0400 Subject: [PATCH 4/8] refactor: change the name of the variable --- src/bridge/mod.rs | 4 ++-- src/cmd_line.rs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 411fae3..c381b31 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -87,9 +87,9 @@ async fn start_neovim_runtime() { start_ui_command_handler(nvim.clone()); // Verify if the files to open is more than one - if settings.files.len() > 1 { + if settings.target_files.len() > 1 { // Open the rest of the files into new tabs - for file in settings.files.iter().skip(1) { + for file in settings.target_files.iter().skip(1) { nvim.command(format!("tabnew {}", file).as_str()) .await .unwrap_or_explained_panic("Could not create new tab"); diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 510d341..7cfd79d 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -23,7 +23,7 @@ pub struct CmdLineSettings { pub wayland_app_id: String, pub x11_wm_class: String, // Command-line arguments with multiple files - pub files: Vec, + pub target_files: Vec, } impl Default for CmdLineSettings { @@ -48,7 +48,7 @@ impl Default for CmdLineSettings { wayland_app_id: String::new(), x11_wm_class: String::new(), // Command-line arguments with multiple files - files: vec![], + target_files: vec![], } } } @@ -201,8 +201,7 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .map(|v| v.to_owned()) .or_else(|| std::env::var("NEOVIDE_X11_WM_CLASS").ok()) .unwrap_or_else(|| "neovide".to_owned()), - // Command-line arguments with multiple files - files: matches + target_files: matches .values_of("files_to_open") .map(|opt| opt.map(|v| v.to_owned()).collect()) .unwrap_or_default(), From ed7dcf077dae3c4cf7c30c5403dfeb9c9815a328 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 16 Apr 2022 11:44:36 -0400 Subject: [PATCH 5/8] refactor: remove unnecesary if --- src/bridge/mod.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index c381b31..7c2cfca 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -86,14 +86,11 @@ async fn start_neovim_runtime() { start_ui_command_handler(nvim.clone()); - // Verify if the files to open is more than one - if settings.target_files.len() > 1 { - // Open the rest of the files into new tabs - for file in settings.target_files.iter().skip(1) { - nvim.command(format!("tabnew {}", file).as_str()) - .await - .unwrap_or_explained_panic("Could not create new tab"); - } + // Open the files into new tabs + for file in settings.target_files.iter().skip(1) { + nvim.command(format!("tabnew {}", file).as_str()) + .await + .unwrap_or_explained_panic("Could not create new tab"); } SETTINGS.read_initial_values(&nvim).await; SETTINGS.setup_changed_listeners(&nvim).await; From 30efb09f933b9c71b82807fd8cde2620894698d2 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 24 Apr 2022 22:09:26 -0400 Subject: [PATCH 6/8] automatic add -p parametter to nvim args if tabs enabled --- src/bridge/mod.rs | 6 ------ src/cmd_line.rs | 39 +++++++++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 7c2cfca..2944479 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -86,12 +86,6 @@ async fn start_neovim_runtime() { start_ui_command_handler(nvim.clone()); - // Open the files into new tabs - for file in settings.target_files.iter().skip(1) { - nvim.command(format!("tabnew {}", file).as_str()) - .await - .unwrap_or_explained_panic("Could not create new tab"); - } SETTINGS.read_initial_values(&nvim).await; SETTINGS.setup_changed_listeners(&nvim).await; diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 7cfd79d..211d9aa 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -22,8 +22,8 @@ pub struct CmdLineSettings { pub neovim_bin: Option, pub wayland_app_id: String, pub x11_wm_class: String, - // Command-line arguments with multiple files - pub target_files: Vec, + // Disable open multiple files as tabs + pub no_tabs: bool, } impl Default for CmdLineSettings { @@ -47,8 +47,8 @@ impl Default for CmdLineSettings { neovim_bin: None, wayland_app_id: String::new(), x11_wm_class: String::new(), - // Command-line arguments with multiple files - target_files: vec![], + // Disable open multiple files as tabs + no_tabs: false, } } } @@ -89,6 +89,11 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .long("nofork") .help("Do not detach process from terminal"), ) + .arg( + Arg::with_name("no_tabs") + .long("notabs") + .help("Disable open multiple files as tabs"), + ) .arg( Arg::with_name("remote_tcp") .long("remote-tcp") @@ -152,12 +157,20 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .values_of("neovim_args") .map(|opt| opt.map(|v| v.to_owned()).collect()) .unwrap_or_default(); - neovim_args.extend::>( - matches - .values_of("files_to_open") - .map(|opt| opt.map(|v| v.to_owned()).collect()) - .unwrap_or_default(), - ); + + let files_to_open: Vec = matches + .values_of("files_to_open") + .map(|opt| opt.map(|v| v.to_owned()).collect()) + .unwrap_or_default(); + + if files_to_open.len() > 1 + && !files_to_open.contains(&String::from("-p")) + && !matches.is_present("no_tabs") + { + neovim_args.push("-p".to_owned()); + } + + neovim_args.extend::>(files_to_open); /* * Integrate Environment Variables as Defaults to the command-line ones. @@ -201,10 +214,8 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .map(|v| v.to_owned()) .or_else(|| std::env::var("NEOVIDE_X11_WM_CLASS").ok()) .unwrap_or_else(|| "neovide".to_owned()), - target_files: matches - .values_of("files_to_open") - .map(|opt| opt.map(|v| v.to_owned()).collect()) - .unwrap_or_default(), + // Disable open multiple files as tabs + no_tabs: matches.is_present("no_tabs") || std::env::var("NEOVIDE_NO_TABS").is_ok(), }); Ok(()) } From 092fb87e8d5932634afa9c723f63bb2749a3e173 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sun, 24 Apr 2022 22:15:52 -0400 Subject: [PATCH 7/8] fix bad conditional --- src/cmd_line.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd_line.rs b/src/cmd_line.rs index 211d9aa..6a4b6e6 100644 --- a/src/cmd_line.rs +++ b/src/cmd_line.rs @@ -164,7 +164,7 @@ pub fn handle_command_line_arguments(args: Vec) -> Result<(), String> { .unwrap_or_default(); if files_to_open.len() > 1 - && !files_to_open.contains(&String::from("-p")) + && !neovim_args.contains(&String::from("-p")) && !matches.is_present("no_tabs") { neovim_args.push("-p".to_owned()); From 09940c4f87c4bab3c1a4f7c499b9ff03c6224d24 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Mon, 25 Apr 2022 09:25:52 -0400 Subject: [PATCH 8/8] remove unnecesary empty line --- src/bridge/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 2944479..89afd63 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -85,7 +85,6 @@ async fn start_neovim_runtime() { let nvim = Arc::new(nvim); start_ui_command_handler(nvim.clone()); - SETTINGS.read_initial_values(&nvim).await; SETTINGS.setup_changed_listeners(&nvim).await;