Subject: 31.0.50; Deleting editable-field widget leaves some overlays behind
From: Mauro Aranda <[email-masked]>
To: [email-masked]
Date: Sat, 18 Jan 2025 08:02:01 -0300
List-Id: <debbugs-submit.debbugs.gnu.org>

I discovered this bug while testing my fix for Bug#51550.

With emacs -Q, eval this:

(defvar my-field)
(defvar my-field-overlay)
(defvar my-overlay)

(defun widget-example ()
   "Create the widgets from the Widget manual."
   (interactive)
   (switch-to-buffer "*Overlay Left Behind*")
   (kill-all-local-variables)
   (let ((inhibit-read-only t))
     (erase-buffer))
   (remove-overlays)
   (widget-insert "There will be an overlay left behind when we delete 
the editable field.\n\n")
   (setq my-field (widget-create 'editable-field
                 :format "%t: %v "
                 :tag "Delete me"))
   (widget-insert "\n")
   (use-local-map widget-keymap)
   (widget-setup)
   (widget-backward 1)
   (setq my-field-overlay (widget-get my-field :field-overlay))
   (setq my-overlay (car (overlays-at (point)))))

After M-x widget-example eval the following, to delete the field.
(widget-delete my-field)

Then, check the value of my-field-overlay:
#<overlay in no buffer>

That's good, we deleted that one.

Now check the value of my-overlay:
#<overlay from 70 to 70 in *Spurious Overlay*>

That's not good, this one should be deleted as well.

In GNU Emacs 31.0.50 (build 7, x86_64-pc-linux-gnu, GTK+ Version
  3.24.33, cairo version 1.16.0) of 2025-01-18 built on tbb-desktop
Repository revision: 43c2e49d19f2e7a840507ae9e728b623fcb7c341
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12201001
System Description: Ubuntu 22.04.5 LTS

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
   value of $LC_MONETARY: es_AR.UTF-8
   value of $LC_NUMERIC: es_AR.UTF-8
   value of $LC_TIME: es_AR.UTF-8
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: @im=ibus
   locale-coding-system: utf-8-unix

Major mode: Org

Minor modes in effect:
   auto-insert-mode: t
   global-hl-line-mode: t
   tooltip-mode: t
   global-eldoc-mode: t
   show-paren-mode: t
   mouse-wheel-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   minibuffer-regexp-mode: t
   column-number-mode: t
   line-number-mode: t
   auto-fill-function: org-auto-fill-function
   indent-tabs-mode: t
   transient-mark-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t

Load-path shadows:
/home/tbb/.emacs.d/elpa/transient-20230919.2146/transient hides 
/home/tbb/code/emacs/emacs/lisp/transient

Features:
(shadow sort mail-extr emacsbug oc-basic cl-extra help-mode org-habit
ol-eww eww vtable mule-util url-queue mm-url ol-rmail ol-mhe ol-irc
ol-info ol-gnus nnselect gnus-art mm-uu mml2015 mm-view mml-smime smime
gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg dom gnus-group
gnus-undo gnus-start gnus-dbus gnus-cloud nnimap nnmail mail-source utf7
nnoo parse-time gnus-spec gnus-int gnus-range message sendmail
yank-media puny rfc822 mml mml-sec mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 ietf-drums mailabbrev gmm-utils
mailheader gnus-win ol-docview doc-view filenotify jka-compr image-mode
exif dired dired-loaddefs ol-bibtex bibtex ol-bbdb ol-w3m ol-doi
org-link-doi vc-theme time-theme hiddenquote-theme epkg-theme emms-theme
egerrit-theme autoinsert gnus nnheader gnus-util text-property-search
mail-utils range mm-util mail-prsvr org-journal-theme org-journal
org-crypt epa derived epg rfc6068 epg-config cal-iso ox-odt rng-loc
rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn nxml-parse nxml-ns
nxml-enc xmltok nxml-util ox-latex ox-icalendar org-agenda ox-html table
ox-ascii ox-publish ox org-attach org-element org-persist org-id
org-refile org-element-ast inline avl-tree generator org-clock org ob
ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-src sh-script
treesit executable ob-comint org-pcomplete pcomplete org-list
org-footnote org-faces org-entities noutline outline org-version
ob-emacs-lisp ob-core ob-eval org-cycle org-table ol rx org-fold
org-fold-core org-keys oc org-loaddefs thingatpt find-func cal-menu
calendar cal-loaddefs org-compat org-macs format-spec newsticker
newst-treeview tree-widget newst-plainview newst-reader newst-ticker
newst-backend iso8601 time-date octave smie comint ansi-osc ansi-color
ring vc vc-dispatcher cc-mode cc-fonts cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs dbus xml social-theme
org-theme holidays-theme mail-theme dired-theme faces-theme
modus-vivendi-theme modus-themes questionable-theme hl-line
intermediate-user-theme basic-theme clean-gui-theme cus-edit pp cus-load
wid-edit finder-inf debbugs-autoloads geiser-guile-autoloads
geiser-autoloads magit-autoloads pcase git-commit-autoloads
magit-section-autoloads dash-autoloads org-journal-autoloads
php-mode-autoloads poke-line-autoloads transient-autoloads info
with-editor-autoloads package-theme package browse-url xdg url url-proxy
url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs icons password-cache json
subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib
server rmc iso-transl tooltip cconv eldoc paren electric uniquify
ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
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 emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames emacs)

Memory information:
((conses 16 575236 24485) (symbols 48 38479 4)
  (strings 32 179233 5434) (string-bytes 1 4519335) (vectors 16 66704)
  (vector-slots 8 1312156 196553) (floats 8 348 42)
  (intervals 56 501 0) (buffers 992 12))