dips
dips

Reputation: 1637

Emacs: how to end sentences on encountering a newline

The commands M-a (backward-sentence) and M-e (forward-sentence) move to the beginning and end of the current sentence, respectively. I would like to end a sentence if there is a newline. So, I would like emacs to treat the following text as two lines (even though there are no periods). With the default config, emacs treats it as a single sentence.

This is line one
This is line two

Why do I need this?

I use visual-line-mode. So my sentences never contain a newline character. I am using the sentence hilight mode which relies on emacs "sentence end". This creates problem in cases where there are no periods. For example program source listing. (The whole program is treated as a single line by emacs.)

Upvotes: 2

Views: 241

Answers (1)

lawlist
lawlist

Reputation: 13467

Adding \n to the end of the regexp for sentence-end should accomplish the goal you seek -- it is done by adding a delimiter that looks like this \\| and then the \n.

Here is the default regexp for sentence-highlight-mode:

(setq sentence-end "[^.].[.?!]+\\([]\"')}]*\\|<[^>]+>\\)\\($\\| $\\|\t\\| \\)[ \t\n]*")

Here is the revised regexp for sentence-highlight-mode:

(setq sentence-end "[^.].[.?!]+\\([]\"')}]*\\|<[^>]+>\\)\\($\\| $\\|\t\\| \\)[ \t\n]*\\|\n")

Upvotes: 4

Related Questions