Subject: bug#4854: 23.1.50; before-string overlay and show-paren-mode

From: [email-masked]
Date: Fri, 01 Jul 2016 14:42:30 -0400

severity 4854 minor
tags 4854 notabug
quit

A simpler test is

1. emacs -Q

2. eval

(defun show-overlays ()
  (interactive)
  (message "ovlist %S"
           (mapcar (lambda (o)
                     (cons o (overlay-properties o)))
                   (overlays-in (1- (point)) (1+ (point))))))

(global-set-key "\C-cs" 'show-overlays)

3. M-x show-paren-mode

4. with point on a parenthesis

C-c s gives

ovlist ((#<overlay from 730 to 731 in *scratch*> face show-paren-match priority 1000))

M-x show-overlays gives

ovlist nil

Stephen Berman <[email-masked]> writes:
> These two things seem very strange: (i) enabling show-paren-mode and
> getting the show-paren overlay somehow nullifies the unless test; (ii)
> this effect only happens when the command is invoked via a key
> sequence.

It's because show-paren-mode uses a single (pair of) overlay(s) for all
buffers and moves it to right place during idle time.  When you invoke a
command with M-x the overlay pair gets moved to the minibuffer.  With a
direct keybinding the overlay pair stays in the current buffer.  This
can be demonstrated by adding this advice (additional to the code
evaluated above):

(defun debug-show-paren-mode (&rest _args)
  (message "show-paren-function in buffer %S" (current-buffer)))
(advice-add 'show-paren-function :before #'debug-show-paren-mode)

When using C-c s:

show-paren-function in buffer #<buffer *scratch*> [4 times]
ovlist ((#<overlay from 506 to 507 in *scratch*> face show-paren-match priority 1000))

When using M-x show-overlays:

show-paren-function in buffer #<buffer  *Minibuf-1*> [5 times]
ovlist nil
You can run the command ‘show-overlays’ with C-c s

So I think this is not a bug, it's just how show-paren-mode works.