Compare commits

..

3 Commits

Author SHA1 Message Date
Spenser Black 72932a391b
Support `.git-blame-ignore-revs` (#13460) 2025-05-04 08:52:28 -05:00
RoloEdits 4c630c148a
feat(commands): add `selection` variable expansion (#13467) 2025-05-04 08:43:09 -05:00
RoloEdits ac3c6ebaff
feat(commands): add `language` variable expansion (#13466) 2025-05-04 08:35:58 -05:00
3 changed files with 20 additions and 1 deletions

View File

@ -47,6 +47,8 @@ The following variables are supported:
| `cursor_column` | The column number of the primary cursor in the currently focused document, starting at 1. This is counted as the number of grapheme clusters from the start of the line rather than bytes or codepoints. | | `cursor_column` | The column number of the primary cursor in the currently focused document, starting at 1. This is counted as the number of grapheme clusters from the start of the line rather than bytes or codepoints. |
| `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. | | `buffer_name` | The relative path of the currently focused document. `[scratch]` is expanded instead for scratch buffers. |
| `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. | | `line_ending` | A string containing the line ending of the currently focused document. For example on Unix systems this is usually a line-feed character (`\n`) but on Windows systems this may be a carriage-return plus a line-feed (`\r\n`). The line ending kind of the currently focused document can be inspected with the `:line-ending` command. |
| `language` | A string containing the language name of the currently focused document.|
| `selection` | A string containing the contents of the primary selection of the currently focused document. |
Aside from editor variables, the following expansions may be used: Aside from editor variables, the following expansions may be used:

View File

@ -33,6 +33,10 @@ pub enum Variable {
BufferName, BufferName,
/// A string containing the line-ending of the currently focused document. /// A string containing the line-ending of the currently focused document.
LineEnding, LineEnding,
// The name of current buffers language as set in `languages.toml`
Language,
// Primary selection
Selection,
} }
impl Variable { impl Variable {
@ -41,6 +45,8 @@ impl Variable {
Self::CursorColumn, Self::CursorColumn,
Self::BufferName, Self::BufferName,
Self::LineEnding, Self::LineEnding,
Self::Language,
Self::Selection,
]; ];
pub const fn as_str(&self) -> &'static str { pub const fn as_str(&self) -> &'static str {
@ -49,6 +55,8 @@ impl Variable {
Self::CursorColumn => "cursor_column", Self::CursorColumn => "cursor_column",
Self::BufferName => "buffer_name", Self::BufferName => "buffer_name",
Self::LineEnding => "line_ending", Self::LineEnding => "line_ending",
Self::Language => "language",
Self::Selection => "selection",
} }
} }
@ -58,6 +66,8 @@ impl Variable {
"cursor_column" => Some(Self::CursorColumn), "cursor_column" => Some(Self::CursorColumn),
"buffer_name" => Some(Self::BufferName), "buffer_name" => Some(Self::BufferName),
"line_ending" => Some(Self::LineEnding), "line_ending" => Some(Self::LineEnding),
"language" => Some(Self::Language),
"selection" => Some(Self::Selection),
_ => None, _ => None,
} }
} }
@ -215,5 +225,12 @@ fn expand_variable(editor: &Editor, variable: Variable) -> Result<Cow<'static, s
} }
} }
Variable::LineEnding => Ok(Cow::Borrowed(doc.line_ending.as_str())), Variable::LineEnding => Ok(Cow::Borrowed(doc.line_ending.as_str())),
Variable::Language => Ok(match doc.language_name() {
Some(lang) => Cow::Owned(lang.to_owned()),
None => Cow::Borrowed("text"),
}),
Variable::Selection => Ok(Cow::Owned(
doc.selection(view.id).primary().fragment(text).to_string(),
)),
} }
} }

View File

@ -1899,7 +1899,7 @@ source = { git = "https://github.com/mtoohey31/tree-sitter-gitattributes", rev =
[[language]] [[language]]
name = "git-ignore" name = "git-ignore"
scope = "source.gitignore" scope = "source.gitignore"
file-types = [{ glob = ".gitignore_global" }, { glob = "git/ignore" }, { glob = ".ignore" }, { glob = "CODEOWNERS" }, { glob = ".config/helix/ignore" }, { glob = ".helix/ignore" }, { glob = ".*ignore" }] file-types = [{ glob = ".gitignore_global" }, { glob = "git/ignore" }, { glob = ".ignore" }, { glob = "CODEOWNERS" }, { glob = ".config/helix/ignore" }, { glob = ".helix/ignore" }, { glob = ".*ignore" }, { glob = ".git-blame-ignore-revs" }]
injection-regex = "git-ignore" injection-regex = "git-ignore"
comment-token = "#" comment-token = "#"
grammar = "gitignore" grammar = "gitignore"