我有一个需要 2 个空格缩进的项目 A,但它在使用 4 个空格的子文件夹 B 中嵌入了另一个项目。
我在 A/.dir-locals.el 中有以下内容:
((c-mode . ((indent-tabs-mode . nil)
(c-basic-offset . 2))))
。它很好地适用于目录 A 中的所有 C 文件。
问:我可以在同一个 dir-locals.el 文件中排除子文件夹 B 不受 2 个空格缩进的影响吗?
我可能会导致使用 B 的设置创建一个 A/B/.dir-locals.el,但由于现在是例外,因此我更愿意将设置保留在 A/.dir-locals.el 中
引用手册:
Here’s an example of a ‘.dir-locals.el’ file:
((nil . ((indent-tabs-mode . t)
(fill-column . 80)))
(c-mode . ((c-file-style . "BSD")
(subdirs . nil)))
("src/imported"
. ((nil . ((change-log-default-name
. "ChangeLog.local"))))))
This sets ‘indent-tabs-mode’ and ‘fill-column’ for any file in the
directory tree, and the indentation style for any C source file. The
special ‘subdirs’ element is not a variable, but a special keyword which
indicates that the C mode settings are only to be applied in the current
directory, not in any subdirectories. Finally, it specifies a different
‘ChangeLog’ file name for any file in the ‘src/imported’ subdirectory.
-C-hig(emacs)Directory Variables
RET
因此,在您的情况下,您可能正在寻找以下内容:
((c-mode . ((indent-tabs-mode . nil)
(c-basic-offset . 2)))
("B" . ((c-mode . ((c-basic-offset . 4))))))
不能在.dir-locals
文件中指定路径。
我认为.editorconfig无论如何都是一个更好的解决方案。因为它允许您与其他编辑器的用户共享编码样式。Emacs 有一个很好的软件包来应用.editorconfig
文件的设置。
将其放在您的A
目录中:
# top-most EditorConfig file
root = true
# only match files in root folder
[/*.c]
indent_style = space
indent_size = 2