1

I have this comment that I write in my python file

# -*- Mode: Python; tab-width: 8; indent-tabs-mode: nil; python-indent-offset: 2 -*-
# vim:set et sts=4 ts=4 tw=80:

But when I load a python file, there's the following messages:
Can’t guess python-indent-offset, using defaults: 4

However, it set the indentation to the value precised (I tried with 99). But it still display the message. It seems that it tried first to guess the indent, then it read the local variable.

I don't want to set python-guess-indent-offset to nil (for files which aren't mine) but I would like to get ride of this warning if possible.

Does anyone have an idea how?

1

The error message is controlled by the python-indent-guess-indent-offset-verbose variable.

Since the variable is file-local, you should be able to disable it globally if you put the following in your init.el:

   (setq python-indent-guess-indent-offset-verbose nil)

Then do what you're already doing, that is, put the following at the top of your personal files:

# -*- mode: python; python-indent-offset: 2 -*-

To discover this, I did the following:

  1. C-h e to see the *Messages* buffer
  2. Copied part of the error message text
  3. C-h f python-mode
  4. Clicked the link for python.el
  5. Searched for the error message in python.el using C-s using defaults
  6. Found that the message was called in the following block:

        (when python-indent-guess-indent-offset-verbose
          (message "Can't guess python-indent-offset, using defaults: %s"
                   python-indent-offset)))))))) 
    

From there, I looked at the documentation for python-indent-guess-indent-offset-verbose using C-h v.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.