-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Accept +num flag for opening at line number #5603
Conversation
Need to fix Clippy warnings. I'll do that, probably after the weekend. Anyone willing to help me with this? |
I've pushed my second implementation as a second commit, for review and discussion. In the second implementation, Anyway, any comments, suggestions, reviews are more than welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the issue. I'm missing the number in +11
since it's the first element. Need to either add an if here or insert "goto" into command
Fixed the numeric command issue in the final commit. Tested with the following commands: $ ./target/debug/hx README.md +11
$ ./target/debug/hx README.md +'g 11'
$ ./target/debug/hx README.md +'goto 11'
$ ./target/debug/hx +'open README.md' +11
$ ./target/debug/hx +'open README.md' +'theme acme' |
Maybe this was already discussed (altough I didn't find anything) but what about using |
@pascalkuthe that was mentioned in the original issue: #5437. |
9575ffd
to
eaea712
Compare
@@ -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, |
There was a problem hiding this comment.
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;
args.line_number = match arg.parse() { | ||
Ok(n) => n, | ||
_ => anyhow::bail!("bad line number after +"), | ||
}; | ||
if args.line_number > 0 { | ||
args.line_number -= 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 +"), | |
}; |
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+N Goto line number N | |
+N Open the first given file at line number N |
@@ -73,6 +74,16 @@ impl Args { | |||
} | |||
} | |||
} | |||
arg if arg.starts_with('+') => { | |||
let arg = arg.get(1..).unwrap(); |
There was a problem hiding this comment.
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..]
* Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR #5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
Closed by #8521 |
…#8521) * Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR helix-editor#5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
…#8521) * Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR helix-editor#5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
…#8521) * Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR helix-editor#5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
…#8521) * Accept +num flag for opening at line number * Update +N argument feature according to feedback in original PR helix-editor#5603 * Only override the line number of the first file if +N is specified --------- Co-authored-by: Nachum Barcohen <38861757+nabaco@users.noreply.github.com>
Resolves #5437
Added basic logic for opening files with
+N
argument, where N is the line number.Can be mentioned after each file. If mentioned several times, latest one will be taken.
This is a very basic implementation, since in Vim/NeoVim the
+
arguments runs a command in the editor.With some help, I can try to change the implementation. Need to understand how I can use the
execute()
method upon startup. (helix-term/src/commands.rs:164)P.S: I'm new to Rust, so any comments about my code are more than welcome :)