禁止 emacs 在选定区域自动填充
我使用 emacs 来编辑所有内容。在我的一些 LateX 文档中,我想在编辑表格和代码时自动禁用自动填充模式。基本上,我想要两个标签,例如:
%%% BEGIN NO FILL
%%% END NO FILL
并且它们之间不会自动填充任何内容。
有人能想出一种方法来做到这一点吗?我需要确定光标是否在该区域内,然后必须切换模式,并且每次光标移动时都需要执行此操作。或者有更好的方法吗?
I use emacs to edit everything. On some of my LateX documents I would like to automatically disable auto-fill mode when I am editing tables and code. Basically, I'd like to have two tags, like:
%%% BEGIN NO FILL
%%% END NO FILL
and nothing between them will be autofilled.
Can anybody think of a way to do this? I would need to figure out whether or not the cursor is inside the region and then have to toggle the mode, and would need to do that every time the cursor moved. Or is there a better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您正在使用 AUCTeX(您应该使用),那么您可能需要查看
LaTeX-indent-environment-list
。向此变量添加环境将使(除其他外)Mq 不会重新填充该段落。不幸的是,它似乎不适用于自动填充模式。添加到LaTeX-mode-hook
中的以下大部分未经测试的代码可能会满足您的需求。这是非常愚蠢和低效的,但在我的机器上似乎足够快。它不允许嵌套,并且要求您手动标记所有不想填充的部分。我正在考虑添加到我的 .emacs 中的内容(直到我读到你的问题,我没有意识到这对我有多大的困扰)低于当前环境的哪个键,因此不需要特殊的标记(尽管它只查看最里面的环境(我不确定在实践中会造成多大的问题))。将两者结合起来作为练习留给感兴趣的读者。
我以前从未使用过 defcustom,所以我确信这部分可以改进很多。
If you are using AUCTeX (you should be) then you may want to check out
LaTeX-indent-environment-list
. Adding an environment to this variable will make it so that (among other things) M-q doesn't refill the paragraph. Unfortunately it doesn't seem work for auto-fill-mode. The following largely untested code added toLaTeX-mode-hook
might do what you want.It's very stupid and inefficient, but seems to be fast enough on my machine. It doesn't allow nesting, and requires that you manually mark up all sections that you don't want filled. What I am thinking of adding to my .emacs (until I read your question I didn't realize how much this bugged me) is below which keys off of the current environment so there is no need for special markup (though it only looks at the innermost environment (I'm not sure how much of a problem that will cause in practice)). Combining the two is left as an exercise to the interested reader.
I have never used defcustom before so I'm sure that part could be improved quite a bit.
知道了。看看这个:
Got it. Check this out:
或者,您可以关闭自动填充模式并使用 Mq 来格式化段落。我不喜欢自动填充的跳跃性,所以我在每种模式下都使用它。
Alternately, you can turn off auto-fill-mode and use M-q to format paragraphs. I don't love auto-fill's jumpiness so I use this in every mode.
如果您想走建议/重新定义所有运动功能的路线,这应该会有所帮助:
If you want to go the route of advising/redefining all the movement functions, this should help: