I've seen at least two recommendations on StackOverflow to insert newlines between sentences when editing LaTeX documents. The reason being that the practice facilitates source control, diff
ing, and collaborative editing.
I'm basically convinced, but I'm lazy, and I don't want to have to think about it.
So I'm searching for some emacs incantation to handle it for me. Could be a minor mode, could be a set of variables that need to be set.
I think what I don't want is
(set long-lines-auto-wrap 't)
). This is because I don't want to impose requirements on my collaborators' editors, and I sometimes use other unix tools to examine these files.I think what I do want is
fill-paragraph
to fill between newlines that look like they mark the end of a sentence. auto-fill-mode
would be a bonus.That is:
chat chat chat.
A new sentence
with goofed up wrapping that needs to be fixed.
Mumble mumble
Transformed to:
chat chat chat.
A new sentence with goofed up wrapping that needs to be fixed.
Mumble mumble
Your comments and suggestions are appreciated.
Edit: The suggestion by Jouni K. Seppänen pointed me at LaTeX-fill-break-at-separators
, which suggests that emacs almost knows how to do this already. Anyway, I'm off to read some code, and will report back. Thanks again.
More general version of the same question: Editor showdown: Maintain newlines at the ends of sentences. Thanks, dreeves.
The variable fill-column illustrates a symbol with a value attached to it: in every GNU Emacs buffer, this symbol is set to some value, usually 72 or 70, but sometimes to some other value. To find the value of this symbol, evaluate it by itself.
The command M-q ( fill-paragraph ) fills the current paragraph. It redistributes the line breaks within the paragraph, and deletes any excess space and tab characters occurring within the paragraph, in such a way that the lines end up fitting within a certain maximum width.
Here's what I use, which was mostly cribbed from Luca de Alfaro:
(defun fill-sentence () (interactive) (save-excursion (or (eq (point) (point-max)) (forward-char)) (forward-sentence -1) (indent-relative t) (let ((beg (point)) (ix (string-match "LaTeX" mode-name))) (forward-sentence) (if (and ix (equal "LaTeX" (substring mode-name ix))) (LaTeX-fill-region-as-paragraph beg (point)) (fill-region-as-paragraph beg (point))))))
I bind this to M-j
with
(global-set-key (kbd "M-j") 'fill-sentence)
The references to "LaTeX"
are for AUCTeX support. If you don't use AUCTeX, the let
can be simplified to
(let (beg (point)) (forward-sentence) (fill-region-as-paragraph beg (point)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With