Subject: Re: bug#16975: 24.3.50; redisplay--update-region-highlight: (wrong-type-argument number-or-marker-p nil)

From: Stefan Monnier <[email-masked]>
Date: Tue, 11 Mar 2014 13:12:17 -0400

> Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
>   redisplay--update-region-highlight(#<window 10 on *Help*>)

I installed the patch below, which fixes problems that can cause
the above.  Of course, those problems may come from elsewhere as well,
so please try it out and tell me if you still bump into the problem with
this patch applied.

        Stefan

--- lisp/simple.el	2014-03-06 04:11:08 +0000
+++ lisp/simple.el	2014-03-11 16:56:06 +0000
@@ -4415,14 +4415,18 @@
 store it in a Lisp variable.  Example:
 
    (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
-
-  (set-marker (mark-marker) pos (current-buffer))
   (if pos
-      (activate-mark 'no-tmm)
+      (progn
+        (set-marker (mark-marker) pos (current-buffer))
+        (activate-mark 'no-tmm))
     ;; Normally we never clear mark-active except in Transient Mark mode.
     ;; But when we actually clear out the mark value too, we must
     ;; clear mark-active in any mode.
-    (deactivate-mark t)))
+    (deactivate-mark t)
+    ;; `deactivate-mark' sometimes leaves mark-active non-nil, but
+    ;; it should never be nil if the mark is nil.
+    (setq mark-active nil)
+    (set-marker (mark-marker) nil)))
 
 (defcustom use-empty-active-region nil
   "Whether \"region-aware\" commands should act on empty regions.