Skip to content

Conversation

@Neko-Box-Coder
Copy link
Contributor

@Neko-Box-Coder Neko-Box-Coder commented Mar 11, 2025

Using saveBufToFile() to allow sudo prompt instead of just failing.

Also, this fixes the bug where the name is not updated when newly saved buffer is saved again as a different file.
So for example if you create a new buffer (AddTab for example) and save as a.txt. Then save again as b.txt, the title is not updated since it is calling the buffer SaveAs() method directly.

I have no idea how the name gets updated in other situations (for example open an existing file and saving it as another file) despite it calling the buffer SaveAs() method directly.

if err != nil {
InfoBar.Error(err)
}
h.saveBufToFile(args[0], "SaveAs", nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Passing action="SaveAs" will in the end cause executing onSaveAs lua callback, which is supposed to be executed by the SaveAs action, not by a command?

Copy link
Contributor Author

@Neko-Box-Coder Neko-Box-Coder Mar 11, 2025

Choose a reason for hiding this comment

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

I think the if block few lines above which calls Save() will also cause a lua callback. I don't mind either way to have an action or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the if block few lines above which calls Save() will also cause a lua callback. I don't mind either way to have an action or not.

Good point. Ok, maybe some users are already relying on that, so let's stay consistent with this inconsistency...

@JoeKar
Copy link
Collaborator

JoeKar commented Mar 12, 2025

I have no idea how the name gets updated in other situations (for example open an existing file and saving it as another file) despite it calling the buffer SaveAs() method directly.

This whole b.SetName() looks superfluous, when we look at b.GetName():

// GetName returns the name that should be displayed in the statusline
// for this buffer
func (b *Buffer) GetName() string {
name := b.name
if name == "" {
if b.Path == "" {
return "No name"
}
name = b.Path
}
if b.Settings["basename"].(bool) {
return path.Base(name)
}
return name
}

Initially on b.NewBuffer() b.name isn't set at all and thus "". When it is set one time, then there is the need to track it accordingly.
We could get rid of this risk when we internally don't call b.SetName() but we've to keep these functions, since we export them and there is the risk to break plugins.

@dmaluka dmaluka merged commit fa31745 into zyedidia:master Mar 12, 2025
6 checks passed
@Neko-Box-Coder Neko-Box-Coder deleted the BetterSaveCmd branch March 12, 2025 23:35
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.

3 participants