Skip to content

Commit

Permalink
feat: interactive changing of relativity default per-harp
Browse files Browse the repository at this point in the history
  • Loading branch information
Axlefublr committed Nov 9, 2024
1 parent e78fa65 commit b8dc8ab
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,25 @@ Useful global searches like `(TODO|FIXME|HACK|MOVE):?`, and buffer-specific sear

Project-specific register harps, as a way to gain register session persistence, and filetype-specific register harps, that can act as a basic snippet implementation.

When using harp relativity, you may eventually notice that you *mostly* want a certain relativity for a given harp type: global searches are rarer to want compared to project local ones, for example.

You can actually change the default relativity, from "global"!

When using a harp (whether `get` or `set`, doesn't matter), if you *just* supply `.` / `,` / `;` / `'` as your harp name (without anything afterwards), you will *set* the default relativity for *that* harp type only.

`'` sets the default relativity back to "global", as you may have guessed. I omitted it above for clarity, but you can use `'` at the start of your harp names to override relativity to be global.

The workflow goes like this:
1. use a harp action
2. enter just `,`
3. now this harp action is relative to the current buffer by default. this stays forever, until you override it
4. use it again, now entering `a`
5. you used what is equivalent to `,a`, but without having to type in `,`, because you changed the default relativity
6. use it again, now entering `'a`
7. you just used the *global* relativity, overriding the (new) default of buffer-relative
8. use it again, now entering *just* `'`
9. you set default relativity *back* to "global"

How you use relativity is up to you! In some cases relativity doesn't make sense logically, but this approach lets me implement flexible functionality that *you* may, in some cases, use in ways that I didn't think of.

---
Expand Down
37 changes: 35 additions & 2 deletions helix-term/src/commands/forkcommands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,26 @@ fn eval_harp_relativity(
register_input: &str,
) -> Option<(String, String)> {
// relative to buffer
if let Some(register_input) = register_input.strip_prefix(',') {
if register_input == ","
|| register_input == "."
|| register_input == ";"
|| register_input == "'"
{
if let Err(msg) = harp_update(
&format!("{}!!relativity", &section_name),
"current",
HarpInput {
extra: Some(register_input.to_owned()),
..Default::default()
},
) {
cx.editor.set_error(msg);
} else {
cx.editor
.set_status(format!("update section's relativity to {}", register_input));
};
None
} else if let Some(register_input) = register_input.strip_prefix(',') {
let (_, doc) = current!(cx.editor);
let Some(path) = &doc.path else {
cx.editor
Expand All @@ -162,8 +181,22 @@ fn eval_harp_relativity(
let section_name = format!("{}!{}", section_name, language_name);
Some((section_name, register_input.to_owned()))
// not relative to anything (global)
} else {
} else if let Some(register_input) = register_input.strip_prefix('\'') {
Some((section_name.to_owned(), register_input.to_owned()))
} else {
let relativity = HarpOutput::build(
&format!("{}!!relativity", &section_name),
"current",
HarpContract::extra(),
)
.unwrap_or_default()
.extra
.unwrap_or_else(|| String::from("'"));
eval_harp_relativity(
cx,
section_name,
&format!("{}{}", relativity, register_input),
)
}
}

Expand Down

0 comments on commit b8dc8ab

Please sign in to comment.