-
-
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
Add command expansions %key{body} #6979
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f7cdf69
Add command expansions %key{body}
ksdrar aca7d51
Add some requested changes
ksdrar e6801c8
Change "filedir" to "dirname"
ksdrar 8b1aa90
Use standalone implementation for %sh{}
ksdrar f54ef6b
Move expand_args() to helix_view::editor
ksdrar 66ddd23
Add requested changes
ksdrar d360ac6
Put variable expansion in its own module
ksdrar cf64b25
Fail typed command if variable expansion fails
ksdrar c474611
Add unit tests
ksdrar 4f7413d
Format with cargo fmt
ksdrar 3bf311a
Change expansion method
ksdrar 1543a26
Trim shell output in variable expansion
ksdrar 49fce83
Merge mapable command args before expanding
ksdrar c0105aa
Split args before executing the command
ksdrar c710ff4
Add basename and selection variables
ksdrar 406fb08
Add integration tests
ksdrar ed4cf00
Fix clippy lints
ksdrar 77d26cb
Use cwd when no buffer is open
ksdrar 28372db
Test for empy editor and follow /var symlink
ksdrar f38a26b
Add echo command. Add %{cwd}
ksdrar f2672bf
Generate docs and use helix's canonicalize
ksdrar 778db9b
Make requested changes and add usage docs
ksdrar efe6aef
main cursor to primary cursor
ksdrar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
use super::*; | ||
|
||
#[tokio::test(flavor = "multi_thread")] | ||
async fn test_variable_expansion() -> anyhow::Result<()> { | ||
{ | ||
let mut app = AppBuilder::new().build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{filename}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
helix_view::document::SCRATCH_BUFFER_NAME | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
|
||
let mut app = AppBuilder::new().build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{basename}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
helix_view::document::SCRATCH_BUFFER_NAME | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
|
||
let mut app = AppBuilder::new().build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{dirname}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
helix_view::document::SCRATCH_BUFFER_NAME | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
} | ||
|
||
{ | ||
let file = tempfile::NamedTempFile::new()?; | ||
let mut app = AppBuilder::new().with_file(file.path(), None).build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{filename}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
helix_stdx::path::canonicalize(file.path()) | ||
.to_str() | ||
.unwrap() | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
|
||
let mut app = AppBuilder::new().with_file(file.path(), None).build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{basename}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
file.path().file_name().unwrap().to_str().unwrap() | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
|
||
let mut app = AppBuilder::new().with_file(file.path(), None).build()?; | ||
|
||
test_key_sequence( | ||
&mut app, | ||
Some("<esc>:echo %{dirname}<ret>"), | ||
Some(&|app| { | ||
assert_eq!( | ||
app.editor.get_status().unwrap().0, | ||
helix_stdx::path::canonicalize(file.path().parent().unwrap()) | ||
.to_str() | ||
.unwrap() | ||
); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
} | ||
|
||
{ | ||
let file = tempfile::NamedTempFile::new()?; | ||
let mut app = AppBuilder::new().with_file(file.path(), None).build()?; | ||
test_key_sequence( | ||
&mut app, | ||
Some("ihelix<esc>%:echo %{selection}<ret>"), | ||
Some(&|app| { | ||
assert_eq!(app.editor.get_status().unwrap().0, "helix"); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
} | ||
|
||
{ | ||
let file = tempfile::NamedTempFile::new()?; | ||
let mut app = AppBuilder::new().with_file(file.path(), None).build()?; | ||
test_key_sequence( | ||
&mut app, | ||
Some("ihelix<ret>helix<ret>helix<ret><esc>:echo %{linenumber}<ret>"), | ||
Some(&|app| { | ||
assert_eq!(app.editor.get_status().unwrap().0, "4"); | ||
}), | ||
false, | ||
) | ||
.await?; | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I am pretty sure this is not correct. We allow quoting strings so arguments can contain whitespace and a simple split like this will not work. This seems like entirely the wrong place to handle command 3xpansion. This probably needs to be integrated into the command parser properly so that it can correctly interact with whitespace and escapes(without requiring quotes everywhere) so into the shellwords parser somehow. Altough that should likely not actually handle the expansion since it's also used for auto completion. This PR also doens't seem to handle completions at all (
:open %{dirname}/
will not offer useful completions). It should be possible to to properly implement that altough it may be tricky (%sh should not be executed for completions tough)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.
@pascalkuthe Is it possible for completions to be implemented in another PR?