Subject: 30.0.50; wrong-type-argument error on widget-button--check-and-call-button
From: David Ponce <[email-masked]>
To: [email-masked]
Cc: Po Lu <[email-masked]>
Date: Tue, 30 Apr 2024 21:18:05 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I sometimes encounter the below error when I click on a push-button widget.
Here is an example.

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p t)
   widget-button--check-and-call-button((down-mouse-1 (#<window 16 on test-widget-button-click> 3 (29 . 11) 20874080 nil 3 (2 . 0) nil (5 . 11) (12 . 26))) (push-button :tag "TEST" :action test-widget-button-press :button-overlay #<overlay from 1 to 7 in test-widget-button-click> :from #<marker (moves after insertion) at 1 in test-widget-button-click> :to #<marker at 7 in test-widget-button-click>))
   widget-button-click((down-mouse-1 (#<window 16 on test-widget-button-click> 3 (29 . 11) 20874080 nil 3 (2 . 0) nil (5 . 11) (12 . 26))))
   funcall-interactively(widget-button-click (down-mouse-1 (#<window 16 on test-widget-button-click> 3 (29 . 11) 20874080 nil 3 (2 . 0) nil (5 . 11) (12 . 26))))
   call-interactively(widget-button-click nil nil)
   command-execute(widget-button-click)

It seems the problem is due to this commit:

author	Po Lu <[email-masked]>	2024-04-16 15:38:53 +0800
commit	f5e0fb11dbf4d2cc5d7ceabcec7600556fb12843 (patch)

Fix touch screen hscroll when initiated from widgets
* lisp/wid-edit.el (widget-button--check-and-call-button):
Return to the position of point during the tracking loop if a
touch event is canceled.

The issue is that on some cases the below catch statement (line 1109),
whose value now set the variable newpoint, returns t instead of a valid
buffer position:

     (setq newpoint
           (catch 'button-press-cancelled
     ...
       
The culprit is at line 1156:

                               (while (not (widget-button-release-event-p event))
                                 (setq event (read--potential-mouse-event))
                                 (when (and mouse-1 (mouse-movement-p event))
                                   (push event unread-command-events)
                                   (setq event oevent)
                                   (throw 'button-press-cancelled t)) <<<<<<<<<

The below simple patch fixed the issue for me:

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 2d82fbe7c89..3b467434d29 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -1153,7 +1153,7 @@ widget-button--check-and-call-button
                                  (when (and mouse-1 (mouse-movement-p event))
                                    (push event unread-command-events)
                                    (setq event oevent)
-                                  (throw 'button-press-cancelled t))
+                                  (throw 'button-press-cancelled nil))
                                  (unless (or (integerp event)
                                              (memq (car event)
                                                    '(switch-frame select-window))

Thanks!

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
  3.24.41, cairo version 1.18.0) of 2024-04-30
Repository revision: b36fd07560fd12c5e819e808a6f0eb9579f77c25
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 39 (KDE Plasma)

Configured using:
  'configure --prefix=/home/dponce --with-x-toolkit=gtk3 --with-cairo-xcb
  --with-native-compilation=no
  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig'

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 WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
   value of $LC_TIME: fr_FR.utf8
   value of $LANG: fr_FR.UTF-8
   locale-coding-system: utf-8-unix