@@ 257,13 257,31 @@ backup file has already been made)."
"Fill just the current sentence, as by fill-paragraph."
(interactive)
(save-excursion
- (let ((start (save-excursion
- (backward-sentence)
- ;; Include everything from bol on the first line so we don't
- ;; go past the fill column.
- (beginning-of-line)
- (point)))
- (end (save-excursion (forward-sentence) (point))))
+ (let ((original (point)) start end)
+ ;; Find the start.
+ (save-excursion
+ (backward-sentence)
+ (let ((putative-start (point)))
+ ;; Move to what ought to be the end.
+ (forward-sentence)
+ (when (< (point) original)
+ ;; The original point is at the start or in between sentences, so
+ ;; fill the next sentence. Since forward-sentence always moves
+ ;; point, we wind up filling two sentences if we don't check for
+ ;; this. We do so treating forward-sentence as a black box because
+ ;; the default implementation is smart about such things as
+ ;; paragraph boundaries, and may even have been overridden in some
+ ;; modes by forward-sentence-function.
+ (skip-chars-forward " \t\r\n")
+ (setq putative-start (point))
+ (forward-sentence))
+ (setq end (point))
+ ;; Include everything from bol on the first line so we don't go past
+ ;; the fill column.
+ (goto-char putative-start)
+ (beginning-of-line)
+ (setq start (point))))
+ ;; Fill between start & end.
(save-restriction
(narrow-to-region start end)
(fill-paragraph)))))