GNU bug report logs - #4081
Overlay keymap and timers

Previous Next

Package: emacs;

Reported by: Mihai Bazon <mihai <at> bazon.net>

Date: Sat, 8 Aug 2009 09:55:04 UTC

Severity: normal

Merged with 4093, 10459, 11088

Found in version 24.0.94

Fixed in version 24.4

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 4081 in the body.
You can then email your comments to 4081 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4081; Package emacs. (Sat, 08 Aug 2009 09:55:05 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mihai Bazon <mihai <at> bazon.net>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 08 Aug 2009 09:55:05 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Mihai Bazon <mihai <at> bazon.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Overlay keymap and timers
Date: Sat, 8 Aug 2009 12:24:51 +0300
Hi folks,

I identified a possible bug, just wondering if there's a known
workaround.  Please CC me in any reply as I'm not subscribed to the
list.

Short description
=================

    When creating overlays in a function called by run-with-timer,
    their keymap becomes available only *after* some key has been
    pressed.

Sample code
===========

    (setq counter 0)
    (setq my-keymap (make-sparse-keymap))
    (define-key my-keymap (kbd "M-n") 
      (lambda()
        (interactive)
        (message "Got it %s!" (setq counter (+ counter 1)))))
    
    (defun my-highlight ()
      (interactive)
      (save-excursion
        (beginning-of-buffer)
        (while (search-forward-regexp "\\<overlay\\>" nil t)
          (let ((overlay (make-overlay (- (point) 7) (point))))
            (overlay-put overlay 'face 'highlight)
            (overlay-put overlay 'evaporate t)
            ;; using 'local-map doesn't make any difference
            (overlay-put overlay 'keymap my-keymap)
            (overlay-put overlay 'my-property t)))))
    
    (defun my-highlight-with-timer ()
      (interactive)
      (run-with-timer 0.5 nil 'my-highlight))
    
    (defun my-highlight-clear ()
      (interactive)
      (remove-overlays (point-min) (point-max) 'my-property t))

Eval this code, then type "overlay" in some buffer and move the caret
somewhere in the middle of the word.

* Case 1.  M-x my-highlight.  The word gets colored.  If you press M-n,
  it will display "Got it 1!" in the minibuffer -- works as expected.

Now clear it with M-x my-highlight-clear.

* Case 2.  M-x my-highlight-with-timer.  After half a second, the word
  gets colored.  If we immediately press M-n now, we get "M-n is 
  undefined". However, pressing M-n a second time works.

Clear it again with my-highlight-clear.

* Case 3.  M-x my-highlight-with-timer, then press some key such as C-f
  (make sure the cursor doesn't leave the overlay).  Then pressing M-n
  works as expected.

My guess is that the keymap becomes active the moment a key is released
(?) (or in some post-command-hook?) and the cursor is within the
overlay.  So if set without a timer, it gets a chance to be activated
straight away, but with a timer there isn't any key release to trigger
it so it becomes active only after some key has been pressed.

Not sure if this is a bug, but it's sure annoying and I've no idea how
to work around it.  Any help is appreciated.

Cheers,
-Mihai



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4081; Package emacs. (Sun, 09 Aug 2009 14:05:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Mihai Bazon <mihai <at> bazon.net>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sun, 09 Aug 2009 14:05:04 GMT) Full text and rfc822 format available.

Message #10 received at 4081 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Mihai Bazon <mihai <at> bazon.net>
To: 4081 <at> debbugs.gnu.org
Subject: Overlay keymap and timers
Date: Sun, 9 Aug 2009 16:53:47 +0300
Actually, it seems it hasn't anything to do with overlays:

(defun my-set-keymap-with-timer ()
  (interactive)
  (run-with-timer 0.5 nil (lambda()
                            (use-local-map my-keymap)
                            (message "Done setting keymap"))))

If we eval the following and M-x my-set-keymap-with-timer, the keymap
will only be enforced after the first keypress (i.e. first press of M-n
says "M-n is undefined", but subsequently it works).

Found another thread about this issue here:

   http://www.mail-archive.com/emacs-pretest-bug <at> gnu.org/msg12003.html

Stallman says "we should consider that a serious problem". ;-)

Cheers,
-Mihai


Merged 4081 4093. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> emacsbugs.donarmstrong.com. (Mon, 10 Aug 2009 21:05:06 GMT) Full text and rfc822 format available.

Merged 4081 4093 11088. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 25 Mar 2012 19:04:02 GMT) Full text and rfc822 format available.

Merged 4081 4093 10459 11088. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 25 Mar 2012 19:05:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 02 Nov 2014 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 232 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.