我在我的 emacs 中编辑了很多MoinMoinWiki页面并且喜欢flyspell-mode. 预先格式化的内容{{{...}}}(在多行中)以及“反引号文本反引号”通常包含对拼写检查毫无意义的编程代码片段。
我可以配置ispell/flyspell不包含编程代码吗?
例子:
Bla bla lorem ipsum die Standardcontainer wie `vector` eine
''Methode'' haben, die ein einzelnes Argument nimmt, also
`vector<T>::swap(vector<T)>&)`. Bla bla und diese `swap`-Methoden sind
von dieser Sorte. Warum das so ist, sehen wir gleich. Bla bla
was '''kanonisch''' ist bla bla Template-Funktion<<tlitref(stdswap)>>
{{{#!highlight c++ title="Man könnte 'std::swap@LT@@GT@' spezialisieren"
namespace std {
template<> // wir können durchaus im namespace std spezialisieren
void swap<Thing>(Thing&, Thing&) {
// ...hier swappen...
}
}
}}}
Nun, das würde sicherlich in diesem Fall helfen, doch es bleibt ein
größeres Problem: Eine teilweise Spezialisierung lorem ipsum bla bla
Run Code Online (Sandbox Code Playgroud)
Iva*_*rus 15
该变量ispell-skip-region-alist在拼写检查缓冲区时执行您想要的操作,但不适用于 flyspell。只需添加一个条目,如
(add-to-list 'ispell-skip-region-alist
'("^{{{" . "^}}}"))
Run Code Online (Sandbox Code Playgroud)
不幸的是,要让 flyspell 忽略某些区域并不容易。你必须使用flyspell-generic-check-word-predicatewhich 是一个函数。几种模式已经定义了这一点,因此您必须将以下内容作为建议添加到这些函数中。为简单起见,我将假设您使用的text-mode是没有定义的模式(我在下面使用)。然后您可以将以下内容添加到您的 .emacs 中:
(defun flyspell-ignore-verbatim ()
"Function used for `flyspell-generic-check-word-predicate' to ignore {{{ }}} blocks."
(save-excursion
(widen)
(let ((p (point))
(count 0))
(not (or (and (re-search-backward "^{{{" nil t)
(> p (point))
;; If there is no closing }}} then assume we're still in it
(or (not (re-search-forward "^}}}" nil t))
(< p (point))))
(eq 1 (progn (while (re-search-backward "`" (line-beginning-position) t)
(setq count (1+ count)))
(- count (* 2 (/ count 2))))))))))
(put 'text-mode 'flyspell-mode-predicate 'flyspell-ignore-verbatim)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1572 次 |
| 最近记录: |