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

前端 未结 10 1062
予麋鹿
予麋鹿 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 02:58

    May not work in all circumstances, but:

    (defun my-fill-sentence ()
      "Fill sentence separated by punctuation or blank lines."
      (interactive)
      (let (start end)
        (save-excursion
          (re-search-backward "\\(^\\s-*$\\|[.?!]\\)" nil t)
          (skip-syntax-forward "^w")
          (setq start (point-at-bol)))
        (save-excursion
          (re-search-forward "\\(^\\s-*$\\|[.?!]\\)" nil t)
          (setq end (point-at-eol)))
        (save-restriction
          (narrow-to-region start end)
          (fill-paragraph nil))))
    

    To make it work with auto-fill-mode, add (setq normal-auto-fill-function 'my-fill-sentence) to your LaTeX mode hook (I think).

提交回复
热议问题