基于每个文件(而不是文件类型)禁用自动填充模式

发布于 2024-11-19 20:14:25 字数 149 浏览 5 评论 0 原文

我默认为所有 LaTeX 文件启用自动填充模式。

这通常很好,但有时一个乳胶文件主要包含表格,我想在编辑该特定文件时禁用自动填充模式。

是否可以在 .tex 文件的顶部指定我希望它成为例外? 或者,是否可以在 .emacs 中指定这些文件的路径/名称?

I keep auto-fill-mode enabled by default for all LaTeX files.

This is usually nice, but occasionally one latex file contains mostly tables and I would like to disable auto-fill-mode whenever I edit that particular file.

Is it possible to specify at the top of a .tex file that I would like it to be the exception?
Alternatively, is it possible to specify in .emacs the paths/names of these files?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

女皇必胜 2024-11-26 20:14:25

查看官方 Emacs 文档中的“文件中的局部变量”部分。有 eval 变量,允许评估任何代码。所以它看起来像这样(将其放入文件末尾,注释字符应该是特定于模式的):

# Local Variables:
# eval: (auto-fill-mode -1)
# End:

look onto "Local Variables in Files" section in official Emacs documentation. There is eval variable, that allows to evaluate any code. So it will look something like (put this into end of file, comment char should be mode-specific):

# Local Variables:
# eval: (auto-fill-mode -1)
# End:
流年里的时光 2024-11-26 20:14:25

我喜欢在文件中查找某些内容来确定是否具有自动填充的解决方案。

如果您想在顶部放置一个标识符,您可以使用如下代码:

(defun my-auto-fill-disabling-hook ()
  "Check to see if we should disable autofill."
  (save-excursion
    (when (re-search-forward "Some Unique Identifier" 1000 t)
      (auto-fill-mode -1))))

(add-hook 'find-file-hooks 'my-auto-fill-disabling-hook)

并且显然将“Some Unique Identifier”更改为合理的内容 - 例如搜索表本身。然后你就会得到你想要的,带有表格的 LaTeX 文件不会被自动填充。

注意:@Alex 建议使用文件局部变量,但根据 手册本身

但是,以这种方式启用次要模式通常是错误的。最多
次要模式(例如自动填充模式)代表个人用户
偏好。如果想使用minor模式,最好设置一下
主要模式与您的初始化文件挂钩以打开次要模式
你自己(参见初始化文件),而不是使用局部变量列表
把你的品味强加给每个人。

I like the solution of looking for something in the file to determine whether or not to have autofill.

If you want to put an identifier at the top, you can use code like this:

(defun my-auto-fill-disabling-hook ()
  "Check to see if we should disable autofill."
  (save-excursion
    (when (re-search-forward "Some Unique Identifier" 1000 t)
      (auto-fill-mode -1))))

(add-hook 'find-file-hooks 'my-auto-fill-disabling-hook)

And obviously change "Some Unique Identifier" to something reasonable - such as a search for the tables themselves. Then you'd get exactly what you want, LaTeX files with tables wouldn't be auto-filled.

Note: @Alex suggested using a file-local variable, but this is a mistake according to the manual itself:

Often, however, it is a mistake to enable minor modes this way. Most
minor modes, like Auto Fill mode, represent individual user
preferences. If you want to use a minor mode, it is better to set up
major mode hooks with your init file to turn that minor mode on for
yourself alone (see Init File), instead of using a local variable list
to impose your taste on everyone.

蓝海似她心 2024-11-26 20:14:25

从技术上讲,这种方法不会禁用填充模式,但与启用 eval 不同,它是安全的,并且可以达到预期的结果。将这样的行作为文件的第一行。只需指定正确的主要模式(可能是文本),并将填充列设置为适当大的值:

-*- mode: text; fill-column: 99999 -*-

如前所述,您可以编写一个钩子来决定是否应启用自动填充,但我觉得这比必要的工作更多。

This approach does not technically disable fill mode, but it is safe, unlike enabling eval, and achieves the desired result. Put a line like this as the first line of your file. Just specify the correct major mode, probably text, and set the fill-column to an appropriately large value:

-*- mode: text; fill-column: 99999 -*-

As previously suggested, you could write a hook that decides if auto-fill should be enabled, but I felt that was more work than necessary.

天生の放荡 2024-11-26 20:14:25

不确定这是与哪个 Emacs 版本一起添加的,但您也可以在每个文件的基础上“中性”auto-fill-function 变量:

# Local Variables:
# auto-fill-function: (lambda nil nil)
# End:

Not sure which Emacs version this was added with, but you can also 'neuter' the auto-fill-function variable on a per-file basis:

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