on master help sign in
adds --vsplit and --hsplit arguments (#2773)
f10b6f6plexom
contrib/completion/hx.bash+1−1
@@ -16,7 +16,7 @@ _hx() {
16 COMPREPLY=($(compgen -W "$languages" -- $2))
16 COMPREPLY=($(compgen -W "$languages" -- $2))
17 ;;
17 ;;
18 *)
18 *)
19− COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar" -- $2))
19+ COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit" -- $2))
20 ;;
20 ;;
21 esac
21 esac
22} && complete -F _hx hx
22} && complete -F _hx hx
contrib/completion/hx.fish+2−1
@@ -9,4 +9,5 @@ complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup"
9complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
9complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
10complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
10complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
11complete -c hx -s V -l version -d "Prints version information"
11complete -c hx -s V -l version -d "Prints version information"
12−
12+complete -c hx -l vsplit -d "Splits all given files vertically into different windows"
13+complete -c hx -l hsplit -d "Splits all given files horizontally into different windows"
contrib/completion/hx.zsh+2
@@ -14,6 +14,8 @@ _hx() {
14 "--health[Checks for errors in editor setup]:language:->health" \
14 "--health[Checks for errors in editor setup]:language:->health" \
15 "-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
15 "-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
16 "--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
16 "--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
17+ "--vsplit[Splits all given files vertically into different windows]" \
18+ "--hsplit[Splits all given files horizontally into different windows]" \
17 "*:file:_files"
19 "*:file:_files"
18
20
19 case "$state" in
21 case "$state" in
helix-term/src/application.rs+18−3
@@ -5,7 +5,7 @@ use helix_core::{
5 pos_at_coords, syntax, Selection,
5 pos_at_coords, syntax, Selection,
6};
6};
7use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
7use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
8−use helix_view::{align_view, editor::ConfigEvent, theme, Align, Editor};
8+use helix_view::{align_view, editor::ConfigEvent, theme, tree::Layout, Align, Editor};
9use serde_json::json;
9use serde_json::json;
10
10
11use crate::{
11use crate::{
@@ -158,16 +158,31 @@ impl Application {
158 } else {
158 } else {
159 let nr_of_files = args.files.len();
159 let nr_of_files = args.files.len();
160 editor.open(first, Action::VerticalSplit)?;
160 editor.open(first, Action::VerticalSplit)?;
161+ // Because the line above already opens the first file, we can
162+ // simply skip opening it a second time by using .skip(1) here.
161− for (file, pos) in args.files {
163+ for (file, pos) in args.files.into_iter().skip(1) {
162 if file.is_dir() {
164 if file.is_dir() {
163 return Err(anyhow::anyhow!(
165 return Err(anyhow::anyhow!(
164 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
166 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
165 ));
167 ));
166 } else {
168 } else {
169+ // If the user passes in either `--vsplit` or
170+ // `--hsplit` as a command line argument, all the given
171+ // files will be opened according to the selected
172+ // option. If neither of those two arguments are passed
173+ // in, just load the files normally.
174+ let action = match args.split {
175+ Some(Layout::Vertical) => Action::VerticalSplit,
176+ Some(Layout::Horizontal) => Action::HorizontalSplit,
177+ None => Action::Load,
178+ };
167 let doc_id = editor
179 let doc_id = editor
168− .open(&file, Action::Load)
180+ .open(&file, action)
169 .context(format!("open '{}'", file.to_string_lossy()))?;
181 .context(format!("open '{}'", file.to_string_lossy()))?;
170 // with Action::Load all documents have the same view
182 // with Action::Load all documents have the same view
183+ // NOTE: this isn't necessarily true anymore. If
184+ // `--vsplit` or `--hsplit` are used, the file which is
185+ // opened last is focused on.
171 let view_id = editor.tree.focus;
186 let view_id = editor.tree.focus;
172 let doc = editor.document_mut(doc_id).unwrap();
187 let doc = editor.document_mut(doc_id).unwrap();
173 let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
188 let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
helix-term/src/args.rs+4
@@ -1,5 +1,6 @@
1use anyhow::Result;
1use anyhow::Result;
2use helix_core::Position;
2use helix_core::Position;
3+use helix_view::tree::Layout;
3use std::path::{Path, PathBuf};
4use std::path::{Path, PathBuf};
4
5
5#[derive(Default)]
6#[derive(Default)]
@@ -11,6 +12,7 @@ pub struct Args {
11 pub load_tutor: bool,
12 pub load_tutor: bool,
12 pub fetch_grammars: bool,
13 pub fetch_grammars: bool,
13 pub build_grammars: bool,
14 pub build_grammars: bool,
15+ pub split: Option<Layout>,
14 pub verbosity: u64,
16 pub verbosity: u64,
15 pub files: Vec<(PathBuf, Position)>,
17 pub files: Vec<(PathBuf, Position)>,
16}
18}
@@ -28,6 +30,8 @@ impl Args {
28 "--version" => args.display_version = true,
30 "--version" => args.display_version = true,
29 "--help" => args.display_help = true,
31 "--help" => args.display_help = true,
30 "--tutor" => args.load_tutor = true,
32 "--tutor" => args.load_tutor = true,
33+ "--vsplit" => args.split = Some(Layout::Vertical),
34+ "--hsplit" => args.split = Some(Layout::Horizontal),
31 "--health" => {
35 "--health" => {
32 args.health = true;
36 args.health = true;
33 args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
37 args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
helix-term/src/main.rs+2
@@ -67,6 +67,8 @@ FLAGS:
67 -v Increases logging verbosity each use for up to 3 times
67 -v Increases logging verbosity each use for up to 3 times
68 (default file: {})
68 (default file: {})
69 -V, --version Prints version information
69 -V, --version Prints version information
70+ --vsplit Splits all given files vertically into different windows
71+ --hsplit Splits all given files horizontally into different windows
70",
72",
71 env!("CARGO_PKG_NAME"),
73 env!("CARGO_PKG_NAME"),
72 env!("VERSION_AND_GIT_HASH"),
74 env!("VERSION_AND_GIT_HASH"),