Subject: bug#16196: 24.3.50; Disable ding when scrolling

From: "Basil L. Contovounesios" <[email-masked]>
Date: Fri, 09 Aug 2019 11:57:58 +0300

Stefan Kangas <[email-masked]> writes:

> To make it easier to review, I've also included a git diff
> ignoring whitespace changes.

FWIW, you can slightly reduce the amount of code that needs reindenting
by binding saw-error in the existing let* form:

diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index dfea55374b..6403c57236 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -237,7 +237,8 @@ mwheel-scroll
 	       (window-point)))
          (mods
 	  (delq 'click (delq 'double (delq 'triple (event-modifiers event)))))
-         (amt (assoc mods mouse-wheel-scroll-amount)))
+         (amt (assoc mods mouse-wheel-scroll-amount))
+         saw-error)
     (unless (eq scroll-window selected-window)
       ;; Mark window to be scrolled for redisplay.
       (select-window scroll-window 'mark-for-redisplay))
@@ -251,6 +252,7 @@ mwheel-scroll
       ;; So by adding things up we get a squaring up (1, 3, 6, 10, 15, ...).
       (setq amt (* amt (event-click-count event))))
     (when (numberp amt) (setq amt (* amt (event-line-count event))))
+    (condition-case nil
         (unwind-protect
 	    (let ((button (mwheel-event-button event)))
 	      (cond ((eq button mouse-wheel-down-event)
@@ -293,15 +295,21 @@ mwheel-scroll
 	          (goto-char old-point)
 	          (deactivate-mark)
 	          (goto-char new-point)))
-	(select-window selected-window t))))
+            (select-window selected-window t)))
+      ;; Do not ding at buffer limits.  Show a message instead.
+      (beginning-of-buffer (message "Beginning of buffer")
+                           (setq saw-error t))
+      (end-of-buffer (message "End of buffer")
+                     (setq saw-error t)))
 
-  (when (and mouse-wheel-click-event mouse-wheel-inhibit-click-time)
-    (if mwheel-inhibit-click-event-timer
+    (when (and (not saw-error)
+               mouse-wheel-click-event mouse-wheel-inhibit-click-time)
+      (if mwheel-inhibit-click-event-timerp
 	  (cancel-timer mwheel-inhibit-click-event-timer)
         (add-hook 'pre-command-hook 'mwheel-filter-click-events))
       (setq mwheel-inhibit-click-event-timer
 	    (run-with-timer mouse-wheel-inhibit-click-time nil
-			  'mwheel-inhibit-click-timeout))))
+                            'mwheel-inhibit-click-timeout)))))
 
 (put 'mwheel-scroll 'scroll-command t)

Thanks,

-- 
Basil