Subject: 27.2; stale marker left by `fill-region-as-paragraph'

From: Ikumi Keita <[email-masked]>
Date: Mon, 29 Nov 2021 19:49:53 +0900

The function `fill-region-as-paragraph' leaves a temporal marker which
isn't cleared in the buffer.

Here is the structure of `fill-region-as-paragraph':
----------------------------------------------------------------------
(defun fill-region-as-paragraph (from to &optional justify
				      nosqueeze squeeze-after)
[...]
    (setq to (copy-marker (point) t))
[...]
  (if (not (> to (point)))
      nil ;; There is no paragraph, only whitespace: exit now.
[...]
      (goto-char to)
      (unless (eobp) (forward-char 1))
      ;; Return the fill-prefix we used
      fill-prefix)))
----------------------------------------------------------------------
With this code, temporal marker bound to local variable `to' is left in
the buffer. According to elisp reference `(elisp) Overview of Markers',
it is recommended to clear such stale marker with suitable `(set-marker
MARKER nil)':
,----
|    Insertion and deletion in a buffer must check all the markers and
| relocate them if necessary.  This slows processing in a buffer with a
| large number of markers.  For this reason, it is a good idea to make a
| marker point nowhere if you are sure you don’t need it any more.
`----
I'd propose to apply the attached patch to accomplish that.

Regards,
Ikumi Keita

diff -r b5040f7ef2cb -r a9285b04999c lisp/textmodes/fill.el
--- a/lisp/textmodes/fill.el	Sat Mar 27 02:27:15 2021 +0900
+++ b/lisp/textmodes/fill.el	Fri Nov 19 14:00:38 2021 +0900
@@ -708,7 +709,10 @@
     (goto-char from-plus-indent))
 
   (if (not (> to (point)))
-      nil ;; There is no paragraph, only whitespace: exit now.
+      ;; There is no paragraph, only whitespace: exit now.
+      (progn
+        (set-marker to nil)
+        nil)
 
     (or justify (setq justify (current-justification)))
 
@@ -784,6 +788,7 @@
       ;; Leave point after final newline.
       (goto-char to)
       (unless (eobp) (forward-char 1))
+      (set-marker to nil)
       ;; Return the fill-prefix we used
       fill-prefix)))

In GNU Emacs 27.2 (build 1, x86_64-unknown-freebsd13.0, GTK+ Version 3.24.27, cairo version 1.16.0)
 of 2021-04-15 built on freebsd.vmware
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: 13.0-RELEASE-p5

Recent messages:
No current message
Scanning +outbox...done
No more undeleted messages
Processing deletes and refiles for +outbox...done
Making completion list...
C-x v ~ runs the command vc-revision-other-window
Type C-x 1 to delete the help window, C-M-v to scroll help.
Mark saved where search started
Mark set
Making completion list...

Configured using:
 'configure --with-canna --with-canna-includes=/usr/local/canna/include
--with-canna-libraries=/usr/local/canna/lib --without-xim
--disable-largefile --without-modules --with-sound=yes
--with-file-notification=yes --with-cairo=yes CFLAGS=-O3'

Configured features:
XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND DBUS GSETTINGS GLIB NOTIFY KQUEUE
ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ ZLIB TOOLKIT_SCROLL_BARS GTK3 X11
XDBE XIM THREADS JSON PDUMPER LCMS2 GMP

Important settings:
  value of $EMACSLOADPATH: /home/keita/elisp:
  value of $LANG: ja_JP.eucJP
  locale-coding-system: japanese-iso-8bit-unix

Major mode: Info

Minor modes in effect:
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
~/elisp/reftex-parse hides /usr/local/share/emacs/27.2/lisp/textmodes/reftex-parse
/home/keita/.emacs.d/elpa/soap-client-3.2.0/soap-client hides /usr/local/share/emacs/27.2/lisp/net/soap-client
/home/keita/.emacs.d/elpa/soap-client-3.2.0/soap-inspect hides /usr/local/share/emacs/27.2/lisp/net/soap-inspect

Features:
(shadow emacsbug mule-util jka-compr misearch multi-isearch log-view vc
vc-dispatcher vc-hg bug-reference magit-gitignore face-remap
magit-submodule magit-obsolete magit-blame magit-stash magit-reflog
magit-bisect magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs magit-status
magit magit-repos magit-apply magit-wip magit-log magit-diff smerge-mode
diff git-commit rx log-edit pcvs-util add-log magit-core
magit-autorevert autorevert filenotify magit-margin magit-transient
magit-process with-editor shell pcomplete comint ring server ansi-color
magit-mode transient magit-git magit-section magit-utils dash mh-thread
boxquote rect supercite regi mh-identity mh-letter mh-comp sendmail
vc-git diff-mode easy-mmode conf-mode flow-fill cl-extra help-mode
shr-color color mh-search mh-alias multi-prompt crm smiley qp mm-archive
mail-extr mh-mime mh-gnus mh-show goto-addr thingatpt gnus-cite gnus-art
mm-uu mml2015 mm-view mml-smime smime dig gnus-sum url url-proxy
url-privacy url-expand url-methods url-history mailcap shr url-cookie
url-domsuf url-util svg xml dom gnus-group gnus-undo gnus-start
gnus-cloud nnimap nnmail mail-source utf7 netrc nnoo parse-time iso8601
gnus-spec gnus-int message rmc puny dired dired-loaddefs format-spec
rfc822 mml mml-sec epa derived epg epg-config mm-decode mm-bodies
mm-encode mail-parse rfc2231 gmm-utils mailheader gnus-win gnus-range
gnus nnheader wid-edit mh-seq mh-inc hl-line mh-tool-bar mh-xface
mh-utils mh-folder which-func imenu gnus-util rmail rmail-loaddefs
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils
text-property-search time-date mh-scan mh-e mh-compat mailabbrev
mh-buffers mh-loaddefs edmacro kmacro preview-latex auto-loads tex-site
canna-im info package easymenu browse-url url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs eieio-loaddefs
password-cache json subr-x map url-vars seq byte-opt gv bytecomp
byte-compile cconv cl-loaddefs cl-lib japan-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win x-win
term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode elisp-mode lisp-mode
prog-mode register page tab-bar menu-bar rfn-eshadow isearch timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
term/tty-colors frame minibuffer cl-generic cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite charscript charprop case-table epa-hook
jka-cmpr-hook help simple abbrev obarray cl-preloaded nadvice loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote threads dbusbind kqueue lcms2 dynamic-setting
system-font-setting font-render-setting cairo move-toolbar gtk x-toolkit
x multi-tty make-network-process emacs)

Memory information:
((conses 16 244096 28812)
 (symbols 48 22813 1)
 (strings 32 77097 10106)
 (string-bytes 1 2539003)
 (vectors 16 43698)
 (vector-slots 8 1236535 74930)
 (floats 8 398 186)
 (intervals 56 4375 0)
 (buffers 1000 31))