重新定义“句子”在Emacs? (句子之间的单一空格,但忽略缩写) [英] Redefining "sentence" in Emacs? (single space between sentences, but ignoring abbreviations)

查看:173
本文介绍了重新定义“句子”在Emacs? (句子之间的单一空格,但忽略缩写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Emacs(M-a,M-e)中的句子来导航。这里的问题是:默认情况下,Emacs希望每个句子分开两个空格,我只是放一个空格。当然,这个设置可以被关闭,只允许句子由一个空格隔开,如下所示:

 (setq sentence-end-double-space nil)

但是,Emacs认为一个句子在缩写之后已经停止了(。),例如之后,像...一个奇怪的命令,例如foo ...。



所以不是使用上面的代码,有没有办法定义句子 - 结束变量,以便将[...!]标记为句子的结尾,如果以下是一个或多个空格,后跟大写字母[AZ]?



而且...还允许[。!?]标记句子的结尾,如果后跟零个或多个空格后跟\? [后一种情况的原因是用于编写LaTeX代码:其中一个句子后面是一个LaTeX命令,如\footnote {},例如...所以我们可以看到这一点被证明了。\脚注{至少在一些替代世界中。]



我试过玩句子结尾的定义,并提出:

 (setq sentence-end[。!?] []'\)}] * \\(\\ $ \\ | [] + [AZ] \\ | [] + [AZ] \\ | \\)[
;] *)





任何建议?

解决方案

我不认为句末端会做你需要做的事情,你真的需要先行的正则表达式,Emacs不支持它们。



您可以滚动自己的功能来做所需的事情,我不明白您的所有要求,但以下是一个开始:

 (defun my-next-sentence()
向前移动下一句。
从开始
如果这个标点符号后面是一个或多个空格
字符,后跟大写字母或\,则停止。如果
不是,假设我们是某种缩写,并移动到
下一个潜在句子结尾
(interactive)
(re-search-forward[。 ?])
(if(looking-at[\\\
] + [AZ] \\ | \\\\)
nil
我的下一句))

(defun my-last-sentence()
(interactive)
(re-search-backward[。?!] [ \\ n] + [AZ] \\ | \\\\\\\\\\\\\\\\\\\\\\\\\\\\\

您的大部分调整都将需要专注于正则表达式,以确保它符合您需要的所有潜在的结束条件。修改它可以相对容易地将光标移动到特定的位置,基于它发现的内容:如果它是一个正常的句子,移动到下一个{如果你在一个乳胶命令,或任何适合你的话。 / p>

一旦你有这个工作,可以将功能绑定到一个Ma和Me,可能使用mode-h ooks,除非你想为每个模式使用它们。


I would like to be able to navigate by sentence in Emacs (M-a, M-e). Here's the problem: by default, Emacs expects that each sentence is separated by two spaces, and I'm used to just putting a single space. Of course, that setting can be turned off, to allow for sentences separated by only a single space, like so:

(setq sentence-end-double-space nil)   

But then Emacs thinks that a sentence has ended after abbreviations with a full stop ("."), e.g. after something like "...a weird command, e.g. foo...".

So rather than using the above code, is there a way to define the sentence-end variable so that it counts [.!?] as marking the end of the sentence, iff what follows is one or more spaces followed by a capital letter [A-Z]?

And...to also allow [.!?] to mark the end of a sentence, if followed by zero or more spaces followed by a "\"? [The reason for this latter condition is for writing LaTeX code: where a sentence is followed by a LaTeX command like \footnote{}, e.g. "...and so we can see that the point is proved.\footnote{In some alternate world, at least.}"]

I tried playing around with the definition of sentence-end, and came up with:

(setq sentence-end "[.!?][]'\")}]*\\(\\$\\|[ ]+[A-Z]\\|[ ]+[A-Z]\\| \\)[
 ;]*")

But this doesn't seem to work at all.

Any suggestions?

解决方案

I don't think sentence-end will do what you need it to do. You really need look-ahead regexps for this, and Emacs doesn't support them.

You can roll your own function to do what you need though. I don't understand all of your requirements, but the following is a start:

(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))

Most of your tweaking will need to focus on the looking-at regexp, to make sure it hits all the potential end-of-sentence conditions you need. It would be relatively easy to modify it to move the cursor to particular locations based on what it finds: Leave it be if it's a normal sentence, move past the next { if you're at a latex command, or whatever suits you.

Once you've got that working, can bind the functions to a M-a and M-e, probably using mode-hooks unless you want to use them for every mode.

这篇关于重新定义“句子”在Emacs? (句子之间的单一空格,但忽略缩写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆