Article View: gnu.emacs.bug
Article #8737419.27 fill-region: don't add extraneous newline at end of region
From: mernst
Date: Tue, 27 Sep 1994 23:34
Date: Tue, 27 Sep 1994 23:34
105 lines
3769 bytes
3769 bytes
Fill-region and fill-region-as-paragraph, when called on a region which
doesn't end just after a newline, insert an extraneous newline at the end
of the region.
-Michael Ernst
mernst@research.microsoft.com
To reproduce:
emacs -q
abcde
C-a C-SPC C-f C-f C-f
M-x fill-region RET ;; fill the "abc" part of "abcde"
This results in the buffer looking like
abc
de
That is, a newline has been inserted at the end of the filled region.
Do the same thing again:
M-< C-SPC C-e
M-x fill-region RET ;; fill the "abc" part of "abc\nde"
Now the buffer looks like
abc
de
In other words, another newline has been inserted.
Repeat as often as you like:
M-< C-SPC C-e
M-x fill-region RET ;; fill the "abc" part of "abc\n\nde"
And the buffer is
abc
de
Solution:
This patch arranges that if the region ends just before a newline, the
region is expanded to include the newline.
ChangeLog entry:
Tue Sep 27 16:29:27 1994 Michael Ernst <mernst@research.microsoft.com>
* fill.el (fill-region): If region ends just before newline,
extend region to include the newline. This prevents a spurious
newline from being added at the end of the region.
(fill-region-as-paragraph): If region ends just before newline,
extend region to include the newline. This prevents a spurious
newline from being added at the end of the region.
diff -c /usr/people/mernst/emacs/lisp/fill.el\~ /usr/people/mernst/emacs/lisp/fill.el
*** /usr/people/mernst/emacs/lisp/fill.el~ Wed Jul 27 13:07:31 1994
--- /usr/people/mernst/emacs/lisp/fill.el Tue Sep 27 16:25:50 1994
***************
*** 97,103 ****
)))
(save-restriction
! (narrow-to-region from to)
(goto-char (point-min))
(skip-chars-forward "\n")
(narrow-to-region (point) (point-max))
--- 97,106 ----
)))
(save-restriction
! (goto-char (max from to))
! (if (and (not (eobp)) (char-equal ?\n (char-after (point))))
! (forward-char 1))
! (narrow-to-region (min from to) (point))
(goto-char (point-min))
(skip-chars-forward "\n")
(narrow-to-region (point) (point-max))
***************
*** 256,264 ****
space does not end a sentence, so don't break a line there."
(interactive "r\nP")
(save-restriction
! (narrow-to-region from to)
! (goto-char (point-min))
! (while (not (eobp))
(let ((initial (point))
(end (progn
(forward-paragraph 1) (point))))
--- 259,270 ----
space does not end a sentence, so don't break a line there."
(interactive "r\nP")
(save-restriction
! (goto-char (max from to))
! (if (and (not (eobp)) (char-equal ?\n (char-after (point))))
! (forward-char 1))
! (narrow-to-region (min from to) (point))
! (goto-char (point-min))
! (while (not (eobp))
(let ((initial (point))
(end (progn
(forward-paragraph 1) (point))))
Diff exited abnormally with code 1 at Tue Sep 27 16:28:25
Technical Details
Message-ID:
<9409272333.AA04574@monozygote.research.microsoft.com>Path:
arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!research.microsoft.com!mernstShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,e502f143c0385fc9,start X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1994-09-27 17:00:26 PST Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!research.microsoft.com!mernst From: mernst@research.microsoft.com Newsgroups: gnu.emacs.bug Subject: 19.27 fill-region: don't add extraneous newline at end of region Date: 27 Sep 1994 19:34:59 -0400 Organization: GNUs Not Usenet Lines: 106 Sender: daemon@cis.ohio-state.edu Approved: bug-gnu-emacs@prep.ai.mit.edu Distribution: gnu Message-ID: <9409272333.AA04574@monozygote.research.microsoft.com>