Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds --vsplit and --hsplit arguments #2773

Merged
merged 5 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
adds --vsplit and --hsplit arguments
  • Loading branch information
sven-hluchy committed Jun 14, 2022
commit f9e40316f41a2fb7488d465a29af5413127c85f4
2 changes: 1 addition & 1 deletion contrib/completion/hx.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ _hx() {
COMPREPLY=($(compgen -W "$languages" -- $2))
;;
*)
COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar" -- $2))
COMPREPLY=($(compgen -fd -W "-h --help --tutor -V --version -v -vv -vvv --health -g --grammar --vsplit --hsplit" -- $2))
;;
esac
} && complete -F _hx hx
Expand Down
3 changes: 2 additions & 1 deletion contrib/completion/hx.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ complete -c hx -l health -x -a "$langs" -d "Checks for errors in editor setup"
complete -c hx -s g -l grammar -x -a "fetch build" -d "Fetches or builds tree-sitter grammars"
complete -c hx -s v -o vv -o vvv -d "Increases logging verbosity"
complete -c hx -s V -l version -d "Prints version information"

complete -c hx -l vsplit -d "Splits all given files vertically into different windows"
complete -c hx -l hsplit -d "Splits all given files horizontally into different windows"
2 changes: 2 additions & 0 deletions contrib/completion/hx.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ _hx() {
"--health[Checks for errors in editor setup]:language:->health" \
"-g[Fetches or builds tree-sitter grammars]:action:->grammar" \
"--grammar[Fetches or builds tree-sitter grammars]:action:->grammar" \
"--vsplit[Splits all given files vertically into different windows]" \
"--hsplit[Splits all given files horizontally into different windows]" \
"*:file:_files"

case "$state" in
Expand Down
21 changes: 19 additions & 2 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,31 @@ impl Application {
} else {
let nr_of_files = args.files.len();
editor.open(first.to_path_buf(), Action::VerticalSplit)?;
for (file, pos) in args.files {
// Because the line above already opens the first file, we can
// simply skip opening it a second time by using .skip(1) here.
for (file, pos) in args.files.into_iter().skip(1) {
if file.is_dir() {
return Err(anyhow::anyhow!(
"expected a path to file, found a directory. (to open a directory pass it as first argument)"
));
} else {
let doc_id = editor.open(file, Action::Load)?;
// If the user passes in either `--vsplit` or
// `--hsplit` as a command line argument, all the given
// files will be opened according to the selected
// option. If neither of those two arguments are passed
// in, just load the files normally.
let action = if args.vsplit {
Action::VerticalSplit
} else if args.hsplit {
Action::HorizontalSplit
} else {
Action::Load // neither vsplit nor hsplit were passed in, so just open files normally
};
let doc_id = editor.open(file, action)?;
// with Action::Load all documents have the same view
// NOTE: this isn't necessarily true anymore, if
// `--vsplit` or `--hsplit` are used, the file which is
// opened last is focused on.
let view_id = editor.tree.focus;
let doc = editor.document_mut(doc_id).unwrap();
let pos = Selection::point(pos_at_coords(doc.text().slice(..), pos, true));
Expand Down
4 changes: 4 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct Args {
pub load_tutor: bool,
pub fetch_grammars: bool,
pub build_grammars: bool,
pub vsplit: bool,
pub hsplit: bool,
sudormrfbin marked this conversation as resolved.
Show resolved Hide resolved
pub verbosity: u64,
pub files: Vec<(PathBuf, Position)>,
}
Expand All @@ -28,6 +30,8 @@ impl Args {
"--version" => args.display_version = true,
"--help" => args.display_help = true,
"--tutor" => args.load_tutor = true,
"--vsplit" => args.vsplit = true,
"--hsplit" => args.hsplit = true,
"--health" => {
args.health = true;
args.health_arg = argv.next_if(|opt| !opt.starts_with('-'));
Expand Down
2 changes: 2 additions & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ FLAGS:
-v Increases logging verbosity each use for up to 3 times
(default file: {})
-V, --version Prints version information
--vsplit Splits all given files vertically into different windows
--hsplit Splits all given files horizontally into different windows
",
env!("CARGO_PKG_NAME"),
env!("VERSION_AND_GIT_HASH"),
Expand Down