多个emacs lisp配置文件导致“免费变量”并“众所周知”的“函数”警告

发布于 2025-02-08 05:05:38 字数 1664 浏览 4 评论 0原文

我一直在寻找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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2025-02-15 05:05:38

python-shell-Interpreter是由python-mode package定义的变量。

添加(需要'Python-Mode)到文件顶部(或仅在取决于该的代码上方)。

在称为init-elpa.el

的自定义本地文件中定义了要求包装和重新包装。

add 的自定义本地文件中定义'm假设提供 s init-elpa功能)。

由INIT.el文件

需要

,如果所讨论的库已经加载了 ,那么 requief 什么都没做。即使有一个总体上的初始文件加载其他文件,每个文件对于需要(除非有循环依赖性),这是明智的。

黑色变量警告是最“复杂的”:我想这是由于Reformatter不包含包装而引起的,因为也许是require-package isn '也包括。

猜测 Reformatter-define是一个宏,符号black不是实际上用作用作多变的。当需要 需要宏时,通常会(当evar-compile(require'regrion Atterate)),但根据名称也许是 - 重新制定包装 Reformatter可能根本不可加载。如果这一切都是准确的,则可以使用此包装器来应对假阳性:

(with-suppressed-warnings ((free-vars black))
  ...)

请参见 ch i g (ELISP)编译器错误有关处理字节编译警告和错误的更多信息。

The python-shell-interpreter is a variable defined from the python-mode package.

Add (require 'python-mode) to the top of the file (or simply above the code which depends on that).

The require-package and maybe-require-package are defined in a custom local file called init-elpa.el

Add (require 'init-elpa) to the file (I'm assuming it provides the init-elpa feature).

which is require'd by the init.el file

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 to require the things it needs (unless there are circular dependencies).

The black variable warning is the most "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.

I'm guessing that reformatter-define is a macro and that the symbol black is not actually used as a variable. When only macros are required, one would typically (eval-when-compile (require 'reformatter)) but judging by the name maybe-require-package it's intended that reformatter might not be loadable at all. If that's all accurate, you can use this wrapper to cope with the false-positive:

(with-suppressed-warnings ((free-vars black))
  ...)

See C-hig (elisp)Compiler Errors for further information on handling byte-compilation warnings and errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文