Sublime Forum

Anaconda adds a new line on save, despite ensure_newline_at_eof_on_save = false

#1

Hello, I am working on a python file using the anaconda package. While I am saving my .py file, the editor adds a new line, despite I have set up “ensure_newline_at_eof_on_save”: false in my user-settings. I have tried to restart ST3 several times, but the problem still remains. Does someone know how to solve this issue?

0 Likes

#2

I would verify that you don’t have a syntax specific setting set up that overrides it for Python files. Open a Python file and then use Preferences > Settings - Syntax Specific to check.

Anaconda might be forcing something like that, so adding the setting to the above file even if it’s not there might help. Failing that, it’s possible that perhaps the Anaconda package is just modifying the file on your behalf (for example if it tries to help you with code style or what have you).

0 Likes

#3

THX but I have added this line in the syntax specifics, too, but the problem still remains. The file contains this:

{
“ensure_newline_at_eof_on_save”: false,
“tab_size”: 1
}

In addition, the tab size is still 4 sizes and not one despite of the setting. Maybe this is an issue of anaconda but I would like to know where I can edit anaconda specific settings if someone knows.

EDIT: I have tried several settings but the problem not only remains but does a line break while saving like this here after the format syntax.

print("Clien Error {}: {}".format(
                response_code, _status_codes[response_code]))
0 Likes

#4

The tab size not changing is semi-expected, depending on your setup.

The tab_size setting indicates how big tabs should be:

    // The number of spaces a tab is considered equal to
    "tab_size": 4,

However, the detect_indentation setting causes Sublime to examine each file as it opens it to see how it’s indented, and then set setting automatically as appropriate:

    // Set to false to disable detection of tabs vs. spaces on load
    "detect_indentation": true,

So if this is turned on for you (and it’s enabled by default), then you might notice that even if you set your tab_size to 1, if you open existing Python files it will still show you the same indent as before. For a more complete test, you need to either turn the setting off or create a new empty Python file and see what the tab size is there.

However…

Sublime will trim trailing spaces on lines and ensure there’s a newline on the end (if the appropriate settings are set) but one thing it does not do is arbitrarily fiddle with the content of your file when you save it.

So that is most likely the result of a package that you’ve installed, which might be Anaconda or something else. If whatever it is is reformatting your code on save, then it’s most likely doing it without any regard to the Sublime settings and instead some sort of set style guide.

The Anaconda package appears to have a setting for formatting files on save, though it’s turned off by default:

    /*
        Autoformat files on save
        This option is disabled by default, AutoPEP8 is really slow and it get
        the file buffer read only while its working in the background.
        Use this at your own risk.
    */
    "auto_formatting": false,

You may want to check the Anaconda settings to see if it’s perhaps turned on in your settings. If not, then I would check for any other linting/autoformat/code style type packages you have installed to see if they’re causing you issues.

In a pinch you can see what packages are doing something when you save files by using Tools > Developer > Profile Plugins (after you’ve saved at least one file where this happens), and then check to see what appears under on_pre_save and on_post_save (and their async equivalents).

The first thing in each line under an event tells you the package that’s doing this, which may help you narrow down the culprit.

0 Likes

#5

Thank you very much for your suggestions and detailed explanations. I will check out all of them and hope that my issue gets fixed.

EDIT: I have set up the following and the issue is gone :sunny:

“detect_indentation”: true

“auto_formatting”: false

I addition, I have checked out Tools > Developer > Profile Plugins, but I don’t understand the output. The data shown looks like statistics of some operations done by anaconda, but I don’t know what linting and autopep8 means.

on_post_save:

Anaconda.listeners.linting: 0.005s total, mean: 0.001s, max: 0.004s

on_pre_save:
Anaconda.listeners.autopep8: 0.001s total, mean: 0.000s, max: 0.001s

0 Likes