Redefining “sentence” in Emacs? (single space between sentences, but ignoring abbreviations)

戏子无情 提交于 2019-12-03 11:27:42

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!