Is there any way to make the `fill-paragraph` stop at the end of a sentence?

Sometimes it is advisable to start each sentence in a paragraph on a separate line. For example, this makes it easier to distinguish between large text documents, since changing one sentence will not affect the entire paragraph. Some markup systems (e.g. * roff) also require that each sentence starts on a new line.

Is there a way, for example. by reasonably redefining paragraph-separateand paragraph-startto make a fill-paragraphstop between sentences?

(note: I am using Emacs 23.3.1)


Update: mdoc example (* roff):

The
.Nm
utility makes a series of passes with increasing block sizes.
In each pass, it either reads or writes (or both) a number of
non-consecutive blocks at increasing offsets relative to the ideal
alignment, which is assumed to be multiples of the block size.
The results are presented in terms of time elapsed, transactions per
second and kB per second.

, , () . fill-paragraph

The
.Nm
utility makes a series of passes with increasing block sizes.  In each
pass, it either reads or writes (or both) a number of non-consecutive
blocks at increasing offsets relative to the ideal alignment, which is
assumed to be multiples of the block size.  The results are presented
in terms of time elapsed, transactions per second and kB per second.

.


:

, , "", , Emacs , , , ( groff, ..). ,

  • - ; groff , .
  • fill-paragraph , -, , , .
  • , fill-paragraph , , .

, :

The
.Nm
utility makes a series of passes with increasing block sizes.
In each pass, it either reads or writes (or both) a number of non-consecutive blocks at increasing offsets relative to the ideal alignment, which is assumed to be multiples of the block size.
The results are presented in terms of time elapsed, transactions per second and kB per second.

, " " M-q, :

The
.Nm
utility makes a series of passes with increasing block sizes.
In each pass, it either reads or writes (or both) a number of
non-consecutive blocks at increasing offsets relative to the ideal
alignment, which is assumed to be multiples of the block size.
The results are presented in terms of time elapsed, transactions per second and kB per second.

, .

+5
3

paragraph-start , :

"\f\\|[     ]*$\\|^[A-Z]"

, \\^[A-Z]

, , , , .

: , , :

"\f\\|[     ]*$\\|^[    ]*[A-Z]"

.

EDIT: case-fold-search, , !

EDIT: case-fold-search , M-q ( , ).

(defun my-fill-paragraph ()
  (interactive)
  (let ((case-fold-search nil))
    (fill-paragraph)))
+1

DTRT?

(defun separate-sentences (&optional beg end)
  "ensure each sentence ends with a new line.
When no region specified, use current paragraph."
  (interactive (when (use-region-p)
                   (list (region-beginning) (region-end))))
  (unless (and beg end)
    (save-excursion
      (forward-paragraph -1)
      (setq beg (point))
      (forward-paragraph 1)
      (setq end (point))))
  (setq end (if (markerp end)
                end
              (set-marker (make-marker) end)))
  (save-excursion
    (goto-char beg)
    (while (re-search-forward (sentence-end) end t)
      (unless (or (looking-at-p "[ \t]*$")
                  (looking-back "^[ \t]*"))
        (insert "\n")))))

(defun fill-paragraph-sentence-groups (justify)
  "Groups of sentences filled together.  A sentence ending with newline marks end of group."
  (save-excursion
    (save-restriction
      (narrow-to-region (progn (forward-paragraph -1) (point))
                        (progn (forward-paragraph 1) (point)))
      (goto-char (point-min))
      (skip-chars-forward " \t\n")
      (while (not (or (looking-at-p paragraph-separate)
                      (eobp)))
        (fill-region (point)
                     (progn
                       (loop do (forward-sentence 1)
                             until (looking-at "[ \t]*$"))
                       (point))
                     justify)
        (unless (looking-back "^[ \t]*")
          (forward-line 1)))
      t)))

(defun fill-paragraph-sentence-individual (justify)
  "Each sentence in paragraph is put on new line."
  (save-excursion
    (separate-sentences)
    (fill-paragraph-sentence-groups justify)))

;; deployment option 1: add to major-mode hook

(add-hook 'text-mode-hook (lambda ()
                            (set (make-local-variable fill-paragraph-function) 'fill-paragraph-sentence-individual)))

;; deployment option 2: call my-fill-paragraph any where

(defun my-fill-paragraph (arg)
  (interactive "*P")
  (let ((fill-paragraph-function 'fill-paragraph-sentence-individual))
    (fill-paragraph arg)))

. , . .

, , , OP. , , .

+1

fill-region, , , . fill-sentence. , , :

  • ., ? !, .

  • , - , .

, .

0

All Articles