How do I get Emacs to fill sentences, but not paragraphs?

前端 未结 10 1018
予麋鹿
予麋鹿 2020-12-23 02:23

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 so

10条回答
  •  礼貌的吻别
    2020-12-23 03:00

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

提交回复
热议问题