Skip to content

Accept +num flag for opening at line number #5603

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions helix-term/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Args {
pub log_file: Option<PathBuf>,
pub config_file: Option<PathBuf>,
pub files: Vec<(PathBuf, Position)>,
pub line_number: usize,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this isn't used outside of the parse_args function so it could be a local in that function: let mut line_number = 0;

}

impl Args {
Expand Down Expand Up @@ -73,6 +74,16 @@ impl Args {
}
}
}
arg if arg.starts_with('+') => {
let arg = arg.get(1..).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can also be cleaned up a little: &arg[1..]

args.line_number = match arg.parse() {
Ok(n) => n,
_ => anyhow::bail!("bad line number after +"),
};
if args.line_number > 0 {
args.line_number -= 1;
}
Comment on lines +79 to +85
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args.line_number = match arg.parse() {
Ok(n) => n,
_ => anyhow::bail!("bad line number after +"),
};
if args.line_number > 0 {
args.line_number -= 1;
}
args.line_number = match arg.parse::<usize>() {
Ok(n) => n.saturating_sub(1),
_ => anyhow::bail!("bad line number after +"),
};

}
arg => args.files.push(parse_file(arg)),
}
}
Expand All @@ -82,6 +93,10 @@ impl Args {
args.files.push(parse_file(&arg));
}

if let Some(file) = args.files.first_mut() {
file.1.row = args.line_number;
}

Ok(args)
}
}
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ FLAGS:
-V, --version Prints version information
--vsplit Splits all given files vertically into different windows
--hsplit Splits all given files horizontally into different windows
+N Goto line number N
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+N Goto line number N
+N Open the first given file at line number N

",
env!("CARGO_PKG_NAME"),
VERSION_AND_GIT_HASH,
Expand Down