如何通过全局设置覆盖 Emacs 包设置(脚本)(无需编辑包脚本)

How to overwrite Emacs package settings (script) via global settings (without editing package script)

目的:

通过全局设置文件覆盖包脚本中的值(无需编辑包脚本)

环境:

详情:

我想在 vue 组件文件的 lang="pug" 部分使用 yajade-mode 而不是 pug-mode。我找到了一种方法,即在 .emacs.d/elpa/vue-mode-xxxxxxxx.xx/vue-mode.elc 上(而不是在 vue-mode.el 文件上)

(:type template :name pug :mode pug-mode) 重写为 (:type template :name pug :mode yajade-mode)

但我想通过全局设置文件 (.spacemacs) 做同样的事情。有什么好的方法吗?

有问题的代码似乎是:

(defcustom vue-modes
  '((:type template :name nil :mode vue-html-mode)
    (:type template :name html :mode vue-html-mode)
    (:type template :name jade :mode jade-mode)
    (:type template :name pug :mode pug-mode)
    [...])
  "A list of vue component languages [...]"
  [...]
  :group 'vue)

(defcustom vue-modes 告诉您变量 vue-modes 是一个 用户选项 ,因此您可以 自定义 它:

M-x customize-option RET vue-modes RET

您也可以通过 "customize" link 在 C-hv vue-modes 到达那里返回

在自定义缓冲区中进行所需的更改,然后使用 "Apply and Save" 按钮将更改保存到您的初始化文件(或您的 C-h v custom-file RET 如果已设置)。


您还会在自定义缓冲区中看到一个 link,用于编辑 vue 组的所有用户选项(请注意代码中的 :group 'vue)。您可以直接转到:

M-x customize-group RET vue RET

大量 Emacs 库都有这样的自定义组,您通常 guess/autocomplete 甚至不用看代码就可以找到它。


I found a way that is to rewrite ... to ... on .emacs.d/elpa/vue-mode-xxxxxxxx.xx/vue-mode.elc (not on vue-mode.el file)

如您所知,您可能不应该编辑这些文件——但编辑字节编译的 .elc 文件 绝对 不推荐。

默认情况下,Emacs 更喜欢字节编译的文件(因为它们更高效),但这是基于这样的假设,即字节编译的 .elc 文件将与它们的更新保持一致.el 来源。

使用M-xcustomize-optionRETload-prefer-newerRET到启用该选项,之后如果您对 .el 文件进行任何更改,Emacs 将优先于其关联的字节编译但现在已过时的 .elc 文件(如果有)。另见 C-hig (emacs)Lisp Libraries RET

您还可以使用 M-x byte-compile-file RET /path/to/file.el 重新编译修改后的 .el 文件RET(以及其他方法),以便您对 .el 文件的更改传播到已编译的 .elc 文件。