多个emacs lisp配置文件导致“免费变量”并“众所周知”的“函数”警告
我一直在寻找Emacs Config Files一段时间,因此我学习如何以最佳的方式构建我的Emacs配置。现在,我正在寻找 purcell的配置文件看起来很整洁且易于阅读。
但是,对于我发现的每个配置文件,总是存在相同的问题:“免费变量” 并在所有随附的文件上发出警告的“函数不知道”。每次都看到所有来自Flymake的红色下划线是非常令人沮丧的,这也让我质疑这是否确实是编写配置文件的最佳方法。
这是上面提到的存储库中的文件:
;;; init-python.el --- Python editing -*- lexical-binding: t -*-
(setq auto-mode-alist
(append '(("SConstruct\\'" . python-mode)
("SConscript\\'" . python-mode))
auto-mode-alist))
;;WARNING: assignment to free variable ‘python-shell-interpreter’
(setq python-shell-interpreter "python3")
(require-package 'pip-requirements)
(when (maybe-require-package 'toml-mode)
(add-to-list 'auto-mode-alist '("poetry\\.lock\\'" . toml-mode)))
;;WARNING: reference to free variable ‘black’
(when (maybe-require-package 'reformatter)
(reformatter-define black :program "black" :args '("-")))
(provide 'init-python)
;;WARNING: the following functions are not known to be defined: require-package, maybe-require-package, reformatter-define
;;; init-python.el ends here
python-shell-interpreter
是从python-mode
package定义的变量。 require-ackage
和也许是 - 重新包装
是在称为init-elpa.el
的自定义本地文件中定义的'd由init.el
文件,因此这些文件未直接识别它们。 黑色
变量警告是Mostr的“复杂”:我想这是由于Reformater Accetert
package而不包含的事实,因为可能是重新质量包装< /代码>也不包括。
这让我头疼。如果我正确地看到了,根问题是所包含的文件(init-python.el
et al。)取决于包括文件(init.el )没有明确说明。
是否有更好的方法在多个文件中构建Emacs Lisp配置?
I've been looking for emacs config files for a while, so that I learn how to structure my Emacs config in the most optimal way. Now i'm looking at purcell's config files which look very tidy and simple to read.
However, for every config file I've found there's always the same problem: "free variable"
and "function not known to be defined" warnings on all the included files. It is quite frustrating to see all the red underlines from flymake everytime, and it also makes me question if this really is the best way to write the config file.
Here's a file from the repository mentioned above:
;;; init-python.el --- Python editing -*- lexical-binding: t -*-
(setq auto-mode-alist
(append '(("SConstruct\\'" . python-mode)
("SConscript\\'" . python-mode))
auto-mode-alist))
;;WARNING: assignment to free variable ‘python-shell-interpreter’
(setq python-shell-interpreter "python3")
(require-package 'pip-requirements)
(when (maybe-require-package 'toml-mode)
(add-to-list 'auto-mode-alist '("poetry\\.lock\\'" . toml-mode)))
;;WARNING: reference to free variable ‘black’
(when (maybe-require-package 'reformatter)
(reformatter-define black :program "black" :args '("-")))
(provide 'init-python)
;;WARNING: the following functions are not known to be defined: require-package, maybe-require-package, reformatter-define
;;; init-python.el ends here
The python-shell-interpreter
is a variable defined from the python-mode
package.
The require-package
and maybe-require-package
are defined in a custom local file called init-elpa.el
which is requires
'd by the init.el
file and thus they're not directly recognized by this file.
The black
variable warning is the mostr "intricate": I guess it's caused by the fact that the reformatter
package isn't included because maybe-require-package
isn't included as well.
This gives me a headache. If I see it correctly, the root problem is the fact that the included files (init-python.el
et al.) depend on stuff from the including file (init.el
) without it being explicitly stated.
Is there a better way to structure an Emacs Lisp config among multiple files?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加
(需要'Python-Mode)
到文件顶部(或仅在取决于该的代码上方)。add
的自定义本地文件中定义'm假设
提供
sinit-elpa
功能)。,如果所讨论的库已经加载了 ,那么 requief 什么都没做。即使有一个总体上的初始文件加载其他文件,每个文件对于
需要
(除非有循环依赖性),这是明智的。我猜测
Reformatter-define
是一个宏,符号black
不是实际上用作用作多变的。当需要 需要宏时,通常会(当evar-compile(require'regrion Atterate))
,但根据名称也许是 - 重新制定包装
Reformatter
可能根本不可加载。如果这一切都是准确的,则可以使用此包装器来应对假阳性:请参见 ch i g
(ELISP)编译器错误
有关处理字节编译警告和错误的更多信息。Add
(require 'python-mode)
to the top of the file (or simply above the code which depends on that).Add
(require 'init-elpa)
to the file (I'm assuming itprovide
s theinit-elpa
feature).This is fine --
require
does nothing if the library in question has already been loaded. Even when there's an overarching init file loading other files, it's sensible for each file torequire
the things it needs (unless there are circular dependencies).I'm guessing that
reformatter-define
is a macro and that the symbolblack
is not actually used as a variable. When only macros are required, one would typically(eval-when-compile (require 'reformatter))
but judging by the namemaybe-require-package
it's intended thatreformatter
might not be loadable at all. If that's all accurate, you can use this wrapper to cope with the false-positive:See C-hig
(elisp)Compiler Errors
for further information on handling byte-compilation warnings and errors.