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

Plain Text documents do not default to their proper file extension when saving #954

Closed
MasterKale opened this issue Jul 31, 2015 · 11 comments

Comments

@MasterKale
Copy link

When I create a brand new document (using Ctrl+N) I get a new document with Plain Text formatting pre-selected and as confirmed in the bottom-right corner. However, when I save the newly created document the Save As window defaults to All Files (.) so no file extension gets applied to the file. What happens is I type a filename and then hit Enter, which results in an extension-less file.

What's weird is that there IS a Plain Text filetype defined with the desired file extension (.txt). Unlike just about all of the other formatting options (the ones you see in the bottom-right menu), though, that filetype isn't selected by default.

I'm not sure if this is a package issue or not as I couldn't find a "Plain Text" package in the SublimeHQ Packages repo.

OS: Windows 8.1, Windows 10
Sublime: Build 3095 (but also with prior builds from about a year on to today)


Edit by @FichteFoll (2015-08-04)

Proposed solution: Add a new "None" syntax that has no file extensions set and pre-selects the All Files (*.*) file type in the save as dialog and make Plain Text behave like other syntaxes in regards to extension appending. Additionally, add a new setting that allows overriding the new file syntax.

@FichteFoll
Copy link
Collaborator

The package with the Plain Text syntax is named "Text". However, I doubt this is an issue with the package (since the syntax file does have a file extension set, as you said) and instead hardcoded by design to default to the "all files" file type when the file was newly created.

Edit: I also want to add that changing this behavior would be incredibly annoying for creating any new file that is not plain text (and uses .txt as extension), so I'd close this as invalid.

@MasterKale
Copy link
Author

Currently Plain Text is the only language package that doesn't produce the expected result of pre-selecting its file extension in the Save As dialogue. If it would really be that annoying for any new document to default to the .txt extension, then perhaps Sublime Text should default to some kind of None document type that is not associated with any language package. I'm not honestly proposing this as a solution, but it does highlight the fact that this one language package does not follow convention.

And what other types of files that aren't plain text use the .txt extension? I certainly can't think of any. Besides, if a file isn't a plain text file, Sublime already supports saving a new file with the proper extension and then auto-switching the document type to the new extension. And even if you accidentally have the wrong document type selected when creating a new document, saving a file and typing a different extension will save the file as that extension, regardless of whatever document type was previously selected.

For example, I created a new document, selected HTML, then typed "test.txt" and hit Enter. The file was saved as "test.txt", not as "test.txt.html". So the functionality is already built-in to Sublime to handle instances in which new documents will not be saved as plain text. Thus I can't see it making much of an impact to default new documents to the .txt extension to match the default document type of Plain Text when creating a new document.

@FichteFoll
Copy link
Collaborator

If it would really be that annoying for any new document to default to the .txt extension, then perhaps Sublime Text should default to some kind of None document type that is not associated with any language package.

That sounds like a good idea to me. Currently, the "Plain text" syntax is double-purposed.

Sublime already supports saving a new file with the proper extension and then auto-switching the document type to the new extension. And even if you accidentally have the wrong document type selected when creating a new document, saving a file and typing a different extension will save the file as that extension, regardless of whatever document type was previously selected.

You are correct, this invalidates my concern about the potential annoyance of a change. It seems like the first extension of the currently selected file type is only appended if the entered file name does not include an extension. ST then infers the syntax from the extension it was saved with.
This may be dependant on the OS however.

Which brings me to the final suggestion for fixing this issue: Introduce a new "None" syntax that is selected initially when a file is created and that has the "All Files" file type pre-selected when saving for the first time. Is this in line with your report?

@MasterKale
Copy link
Author

I think a None syntax would be an acceptable way of resolving this issue. It's easy to understand and I think it would help bring Plain Text files back in line with all of the other document types.

If you were to go that route, though, would you also consider adding in the ability to select one of the Packages as a "default new file type"? Perhaps a parameter that can be defined in Settings - User? I prefer all new documents being created as Plain Text and saving with a '.txt' extension, and I can't believe no one else would find value in saving a few key strokes when they save a new document. It's definitely not necessary, but would be "nice" to have.

@FichteFoll
Copy link
Collaborator

Default new file type setting sounds fine to me.

@keith-hall
Copy link
Collaborator

I found a way to get Plain Text files to produce the expected result of pre-selecting their .txt file extension in the Save As dialogue. Please see my SO answer here for details: http://stackoverflow.com/a/41257562/4473405

@tofof
Copy link

tofof commented Sep 13, 2017

As a commenter on the above stackoverflow question noted, it's possible to fix this simply by changing the plain text.sublime-settings file.

With a plain text file open, choose preferences -> settings - syntax specific, then in the right tab add the line "default_extension": "txt" within the braces.

@ghost
Copy link

ghost commented Sep 13, 2017

It is perhaps worth adding that, while a .txt extension for a plain text file is what Windows users expect, no extension for such files is what Linux users expect. (Since I use Sublime on both those platforms, I no longer know what I myself expect!)

@wbond
Copy link
Member

wbond commented Oct 9, 2019

FYI: I was just working on some related code, and it is an explicit choice in our codebase to not try and force plain text files to end in .txt. This is because Plain text is the default syntax for a new file, and we don't want to suggest .txt as the extension for every new file a user creates.

@MasterKale
Copy link
Author

It's been six years since the original post, and two years since the last reply. It's probably time to close this 😛

@wbond
Copy link
Member

wbond commented May 11, 2021

Yes, I do believe this is a “working as intended”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants