emacs Can't guess python-indent-offset, using defaults: 4

时间:2022-04-01 19:46:43

首先,这只是一个提示,Emacs 在打开python 文件时,如果是个空文件,会有此提示。

在python.el文件配置中,有如下代码:

Python.el

(defcustom python-indent-guess-indent-offset t
  "Non-nil tells Python mode to guess `python-indent-offset' value."
  :type 'boolean
  :group 'python
  :safe 'booleanp)

(defcustom python-indent-guess-indent-offset-verbose t
  "Non-nil means to emit a warning when indentation guessing fails."
  :version "25.1"
  :type 'boolean
  :group 'python
  :safe' booleanp)

.................

(if (and indentation (not (zerop indentation)))
              (set (make-local-variable 'python-indent-offset) indentation)
            (when python-indent-guess-indent-offset-verbose
              (message "Can't guess python-indent-offset, using defaults: %s"                                           
                       python-indent-offset))))))))

从这断代码中来看,出现这个错误,是因为Python 模式下,如果python-indent-guess-indent-offset-verbose的值是t,在符合前提条件的情况下,会提示该错误 。

因此,想要忽略此错误,只需要修改此变量的值即可。

在init.el 中加入 一行:

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