Emacs 24.3 python:使用默认值4无法猜测python-indent-offset

boh*_*anl 15 python emacs elisp indentation python-2.7

任何了解Lisp的人都可以帮忙解决这个警告吗?

我升级到Emacs 24.3,每当我使用Emacs创建Python文件时,我都会收到此警告消息.搜索python.el并找到产生警告的以下代码部分:

(let ((indentation (when block-end
                     (goto-char block-end)
                     (python-util-forward-comment)
                     (current-indentation))))
  (if indentation
      (set (make-local-variable 'python-indent-offset) indentation)
    (message "Can't guess python-indent-offset, using defaults: %s"
             python-indent-offset)))
Run Code Online (Sandbox Code Playgroud)

这是我的.emacs设置:

(setq-default c-basic-offset   4
              tab-width        4
              indent-tabs-mode nil)

(add-hook 'c-mode-common-hook
          (lambda ()
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-close 0)))

(add-hook 'python-mode-hook
          (lambda ()
            (c-set-offset 'arglist-intro '+)
            (c-set-offset 'arglist-close 0)))
Run Code Online (Sandbox Code Playgroud)

jua*_*eon 22

当您打开python文件时,emacs会根据该文件样式猜测缩进偏移量(缩进的空格数).当您创建文件(您描述的情况)时,emacs无法猜测(文件为空),因此它使用您的默认值(4)并通知用户.

换句话说:tt是一个无害的警告; 如果你发现这是一个错误请报告.

如果您不喜欢emacs猜测偏移量,请将变量自定义python-indent-guess-indent-offset为nil,然后emacs将始终使用您的默认值(在python中非常不安全,其中缩进有意义,您可能正在编辑由其他人使用其他默认值创建的文件) .

  • 如果你不喜欢 emacs *告诉你*关于它猜测偏移量,自定义变量 `python-indent-guess-indent-offset-verbose` 为 nil。 (2认同)

Nik*_*yks 10

如果您只想让警告静音,同时让 emacs 仍然像 juanleon 的答案所解释的那样猜测偏移量,则可以关闭python-indent-guess-indent-offset-verbose变量。

(setq python-indent-guess-indent-offset t)  
(setq python-indent-guess-indent-offset-verbose nil)
Run Code Online (Sandbox Code Playgroud)

根据emacs SE 上的综合答案