能否了解LISP的人可以帮助解决此警告?
I升级到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)))
这是我的
.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)))
当您打开一个Python文件时,Emacs猜测基于该文件样式的缩进偏移量(缩进的空间数)。 当您Create
文件(您描述的情况)时,Emacs无法猜测(文件为空),因此它使用您的默认值(4)并通知用户。换句话说:这是无害的警告;如果您发现这是一个错误,请这样报告。
如果您不喜欢Emacs猜测偏移量,将变量自定义为python-indent-guess-indent-offset
nil
python-indent-guess-indent-offset-verbose
,然后Emacs将始终使用您的默认值(在Python中非常不安全,在Python中,凹痕具有含义,您可以编辑由其他人与其他默认值创建的文件)。
如果您想要的只是警告,同时让Emacs仍然猜测偏移量正如Juanleon的答案所解释的那样,您可以关闭(setq python-indent-guess-indent-offset t)
(setq python-indent-guess-indent-offset-verbose nil)
变量。
python.el
per this this the emacs se的全面答案。
在python.elc
中看,而不是python.el
python.el
是一个字节编译的文件,它对于人类来说几乎是无法理解的。
源代码在
python-indent-guess-indent-offset
中会告诉您
C-x C-b
做什么,因此您为什么会看到您看到的结果。
在以前的答案中增加并沉默警告,此过程涉及该问题,并给出了两个示例,说明了警告为何有用。
获取使用
(dolist (f '(
"/path/to/file1"
"/path/to/file2"
))
(message (concat "Opening file: " f))
(find-file (expand-file-name f)))
的当前打开缓冲区的列表。用蟒蛇过滤那些 扩展,在它们周围添加引号,然后在此命令中替换它们:
M-x evaluate-region
*Messages*
开文件:/path/to/file1 打开文件:/path/to/file2 无法猜测python-indent-offset,使用默认值:4 有关GNU EMACS和GNU系统的信息,请使用C-H型C-A型。我有我用于测试的文件,例如我忘记了:
from time import sleep
sleep(10000)
我仅通过此消息才意识到它,然后删除了文件。在另一种情况下,我有一个有用的文件,其中只有全局变量,所以我添加了此文件 线:
# -*- mode: python; python-indent-offset: 4 -*-
SOME_GLOBAL_VAR = 0
尽管这确实设置了缓冲区 - 本地变量(通过更改为6,然后检查 使用
C-h v python-indent-offset
)检查值,仅在 警告消息,而不是以前。我决定容忍此消息。