我使用emacs编辑所有内容.在我的一些LateX文档中,我想在编辑表和代码时自动禁用自动填充模式.基本上,我想要两个标签,如:
%%% BEGIN NO FILL
%%% END NO FILL
Run Code Online (Sandbox Code Playgroud)
他们之间没有任何东西可以自动填充.
任何人都可以想到这样做的方法吗?我需要弄清楚光标是否在区域内,然后必须切换模式,并且每次光标移动时都需要这样做.或者有更好的方法吗?
知道了。看一下这个:
(defun in-no-auto-fill-region ()
(> (save-excursion (or (search-backward "%%% BEGIN NO FILL" (point-min) t) 0))
(save-excursion (or (search-backward "%%% END NO FILL" (point-min) t) 0))
))
(defun previous-line-checking-auto-fill (arg)
(interactive "P")
(previous-line arg)
(if (in-no-auto-fill-region)
(turn-off-auto-fill)
(turn-on-auto-fill)))
(defun next-line-checking-auto-fill (arg)
(interactive "P")
(next-line arg)
(if (in-no-auto-fill-region)
(turn-off-auto-fill)
(turn-on-auto-fill)))
(add-hook 'LaTeX-mode-hook
'(lambda nil
(local-set-key "C-p" 'previous-line-checking-auto-fill)
(local-set-key "C-n" 'next-line-checking-auto-fill)
(auto-fill-mode 1)
))
Run Code Online (Sandbox Code Playgroud)