Skip to content

New editor config #2523

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

Merged
merged 10 commits into from
Apr 13, 2023
Merged

Conversation

stefanhaller
Copy link
Collaborator

  • PR Description

This implements the new editor configuration as discussed on Discord:

EditCommand and EditCommandTemplate were replaced by Edit, EditAtLine, and EditAndLineAndWait.

In addition, there's a new EditInTerminal boolean to say whether lazygit should suspend to background before calling the editor.

Also, there's a new EditPreset config that can set all four of the above settings at once.

Finally, OpenCommand and OpenLinkCommand were renamed to Open and OpenLink, respectively, for consistency with the others.

  • Please check if the PR fulfills these requirements
  • Cheatsheets are up-to-date (run go run scripts/cheatsheet/main.go generate)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • Docs (specifically docs/Config.md) have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

@github-actions
Copy link
Contributor

github-actions bot commented Mar 29, 2023

Uffizzi Preview deployment-20642 was deleted.

Copy link
Owner

@jesseduffield jesseduffield left a comment

Choose a reason for hiding this comment

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

Great work :) I left some comments

or
If for some reason you are not happy with the default commands from a preset, or
there simply is no preset for your editor, you can customize the commands by
setting the `edit`, `editAtLine`, and `editAtLineAndWait` options, e.g.:
Copy link
Owner

Choose a reason for hiding this comment

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

I'd also mention that they can go and update the getPreset function if they want to add a preset to lazygit for all others to use.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added in 7cd3fb9

}

editorToPreset := map[string]string{
"vim": "vim",
Copy link
Owner

Choose a reason for hiding this comment

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

we should also add nvim and vi as those were previously covered in GetEditCmdStr

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This took three fixup commits :) I took the opportunity to simplify the code a bit, see 1ba3f10, f5c1a05, and 7685a04.


// Whether the given edit commands use the terminal. Used to decide whether
// lazygit needs to suspend to the background before calling the editor.
// Pointer to bool so that we can distinguish unset (nil) from false.
Copy link
Owner

Choose a reason for hiding this comment

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

makes sense

EditInTerminal *bool `yaml:"editInTerminal,omitempty"`

// A built-in preset that sets all of the above settings. Supported presets
// are "vim", "emacs", "nano", "vscode", "sublime", "bbedit", "xcode".
Copy link
Owner

Choose a reason for hiding this comment

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

I wouldn't enumerate the presets here given they'll change over time and it'll be one more place we need to keep in sync. I'd instead reference the place where the presets are defined

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, see ed17d96.

@@ -570,7 +608,7 @@ func GetDefaultConfig() *UserConfig {
BulkMenu: "b",
},
},
OS: GetPlatformDefaultConfig(),
OS: OSConfig{},
Copy link
Owner

Choose a reason for hiding this comment

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

For posterity I'll just state that (if I understand correctly) we're not using the default here because it prevents us from knowing whether a user has explicitly set one of the configs or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly, that's how I tried to explain it in the commit message. 😉

@@ -222,6 +222,9 @@ func (gui *Gui) onInitialViewsCreation() error {
if storedPopupVersion < StartupPopupVersion {
popupTasks = append(popupTasks, gui.showIntroPopupMessage)
}
if deprecatedEditConfigPopup := gui.makeDeprecatedEditConfigPopup(); deprecatedEditConfigPopup != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

We should only show this popup once: it would be annoying to get the popup every time you open lazygit until you've resolved the issue. We could add a new field to our AppState to support this

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I disagree pretty strongly here. If we warn only once, people will ignore it the one time they see it, and then likely forget about it. They will then be very annoyed after a year when we remove the old configs and break their lazygit. I think this is not much better than not warning at all. That's exactly what I meant when we discussed the different options on Discord.

I could imagine throttling the warning to once a day, or maybe once a week, but I'm not sure it's worth the extra logic.

Cc @mark2185 who also had a strong opinion on Discord.

Copy link
Owner

@jesseduffield jesseduffield Apr 2, 2023

Choose a reason for hiding this comment

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

How about an alternative approach: rather than show a popup, we print a deprecation notice after the gui closes, so the message appears in the user's terminal. This means we'll still be able to nag the user, but it won't actually interfere with their flow (many people such as myself will start a new lazygit session frequently and having the popup there will be very annoying).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would personally like the popup at startup better, as I'm afraid the terminal output is too easy to miss (especially when there's a lot of terminal output already, e.g. from multiple "commit with editor" commands).

But I'd be fine with it if you prefer it; see 2e4ce16.

@jesseduffield
Copy link
Owner

@stefanhaller fantastic work! Sorry it took me so long to get around to re-reviewing, but this is good to merge. Feel free to clean up your commits and I'll hit the button

These files were renamed from os_windows_test.go to os_test_windows.go (etc.) in
95b2e95. Since then, the tests have no longer run, since go only looks for
tests in files ending with "test.go".

It isn't important that the file name ends with "_windows.go", since there are
already build constrains in the files themselves.
Now that the tests run again, it turns out that they actually fail, so fix them.
The "open" command is supposed to behave in the same way as double-clicking a
file in the Finder/Explorer. The concept of jumping to a specific line in the
file doesn't make sense for this; use "edit" instead.
Instead, query the platform defaults only if the config is empty. This will be
necessary later to distinguish an empty config from a default config, so that we
can give deprecation warnings.
We do this for consistency with the edit settings. The old names are kept as a
fallback for now.
We print this to the terminal after lazygit quits rather than showing it in a
panel at startup, so as to not annoy people too much. Hopefully it will still be
prominent enough this way.
@stefanhaller
Copy link
Collaborator Author

Done. Thanks!

@jesseduffield jesseduffield merged commit 04e0a9b into jesseduffield:master Apr 13, 2023
@stefanhaller stefanhaller deleted the editor-config branch April 13, 2023 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants