ema*_*cer 15 regex emacs nlp typography punctuation
我希望能够在Emacs(Ma,Me)中逐句导航.这是问题所在:默认情况下,Emacs期望每个句子用两个空格分隔,而我习惯于只放一个空格.当然,可以关闭该设置,以允许仅由单个空格分隔的句子,如下所示:
(setq sentence-end-double-space nil)
Run Code Online (Sandbox Code Playgroud)
但是后来Emacs认为句子在带有句号(".")的缩写后结束,例如在"......一个奇怪的命令,例如foo ......"之后.
因此,有没有一种方法来定义句末项变量,以便它将[.!?]计为标记句子的结尾,iff后面是一个或多个空格后跟一个大写字母[ AZ]?
并且...也允许[.!?]标记句子的结尾,如果后跟零或多个空格后跟"\"?[后一种情况的原因是编写LaTeX代码:其中一个句子后跟一个LaTeX命令,如\ footnote {},例如"......所以我们可以看到这一点被证明了.\ footnote {在某些替代世界,至少.}"]
我试着玩弄句末的定义,并提出:
(setq sentence-end "[.!?][]'\")}]*\\(\\$\\|[ ]+[A-Z]\\|[ ]+[A-Z]\\| \\)[
;]*")
Run Code Online (Sandbox Code Playgroud)
但这似乎根本不起作用.
有什么建议?
我不认为句子结尾会做你需要它做的事情。为此,您确实需要前瞻正则表达式,而 Emacs 不支持它们。
不过,您可以推出自己的函数来完成您需要的操作。我不明白您的所有要求,但以下是一个开始:
(defun my-next-sentence ()
"Move point forward to the next sentence.
Start by moving to the next period, question mark or exclamation.
If this punctuation is followed by one or more whitespace
characters followed by a capital letter, or a '\', stop there. If
not, assume we're at an abbreviation of some sort and move to the
next potential sentence end"
(interactive)
(re-search-forward "[.?!]")
(if (looking-at "[ \n]+[A-Z]\\|\\\\")
nil
(my-next-sentence)))
(defun my-last-sentence ()
(interactive)
(re-search-backward "[.?!][ \n]+[A-Z]\\|\\.\\\\" nil t)
(forward-char))
Run Code Online (Sandbox Code Playgroud)
您的大部分调整需要集中在查看正则表达式上,以确保它满足您需要的所有潜在的句子结束条件。修改它以根据它找到的内容将光标移动到特定位置是相对容易的:如果它是一个普通句子,则保留它,如果您使用的是乳胶命令,则移动到下一个 { ,或者任何适合您的命令。
一旦你完成了这个工作,就可以将函数绑定到 Ma 和 Me,可能使用模式挂钩,除非你想在每个模式中使用它们。
| 归档时间: |
|
| 查看次数: |
2060 次 |
| 最近记录: |