Skip to content
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 helix editor preset #2668

Merged
merged 1 commit into from May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Config.md
Expand Up @@ -289,7 +289,7 @@ os:
```

Supported presets are `vim`, `nvim`, `emacs`, `nano`, `vscode`, `sublime`, `bbedit`,
`kakoune` and `xcode`. In many cases lazygit will be able to guess the right preset
`kakoune`, `helix`, and `xcode`. In many cases lazygit will be able to guess the right preset
from your $(git config core.editor), or an environment variable such as $VISUAL or $EDITOR.

If for some reason you are not happy with the default commands from a preset, or
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/editor_presets.go
Expand Up @@ -44,6 +44,7 @@ func getPreset(osConfig *OSConfig, guessDefaultEditor func() string) *editPreset
"emacs": standardTerminalEditorPreset("emacs"),
"nano": standardTerminalEditorPreset("nano"),
"kakoune": standardTerminalEditorPreset("kakoune"),
"hx": helixEditorPreset(),

Choose a reason for hiding this comment

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

Shouldn't the name of the preset be helix rather than hx? That's what Config.md above says, and I'd prefer the more descriptive name (like with "code" vs. "vscode"). We'll then need an entry "hx": "helix", in the editorToPreset map below.

Copy link

Choose a reason for hiding this comment

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

Indeed, this one bit me!

"vscode": {
editTemplate: "code --reuse-window -- {{filename}}",
editAtLineTemplate: "code --reuse-window --goto -- {{filename}}:{{line}}",
Expand Down Expand Up @@ -104,6 +105,15 @@ func standardTerminalEditorPreset(editor string) *editPreset {
}
}

func helixEditorPreset() *editPreset {
return &editPreset{
editTemplate: "hx -- {{filename}}",
editAtLineTemplate: "hx -- {{filename}}:{{line}}",
editAtLineAndWaitTemplate: "hx -- {{filename}}:{{line}}",
editInTerminal: true,
}
}

Choose a reason for hiding this comment

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

All the other presets (except the standardTerminalEditorPreset ones) are inlined in the table above, this is the only one that has a separate function. I'd prefer this to be consistent, either inline them all, or make functions for all of them. (I prefer inlining them myself, but not strongly.)

Copy link
Owner

Choose a reason for hiding this comment

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

Fair points. I've raised a PR for this: #2673

func getEditInTerminal(osConfig *OSConfig, preset *editPreset) bool {
if osConfig.EditInTerminal != nil {
return *osConfig.EditInTerminal
Expand Down