[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: appointment display during isearch replaces buffer contents with his

From: Johan Bockgård
Subject: Re: appointment display during isearch replaces buffer contents with history-element
Date: Mon, 19 Nov 2007 01:37:28 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

Martin Fischer <address@hidden> writes:

>   Start isearch-forward, type M-p and scroll the history buffer with
>   <up> (previous-history-element).
>   If at the same time emacs tries to display an appointment in the
>   same frame, the contents of the buffer, where you wanted to isearch,
>   is replaced by one of the history elements.
>   The buffer may be restored by undo.

Ok. Here's a condensed recipe.

    $ emacs -Q

    (defun foo ()
        (other-window 1)))

    (push "foo" extended-command-history)

    (run-with-timer 5 nil 'foo)

Wait 5 seconds
Press <up>

The contents of the *scratch* buffer are replaced with "foo"; that is,
the key binding is looked up in the minibuffer's keymap but executed
in *scratch*.

In contrast, executing

    emacsclient --eval '(save-excursion (other-window 1))'

while Emacs is waiting at the M-x prompt doesn't confuse the keymaps.

Using this definition for foo also works correctly

    (defun foo ()
      (other-window 1))

So the problem is when a timer changes the selected window, but not
the current buffer.

This is what I found

* read_process_output (and similar code in exec_sentinel); call
  record_asynch_buffer_change unconditionally (processes):

  #if 0 /* Call record_asynch_buffer_change unconditionally,
           because we might have changed minor modes or other things
           that affect key bindings.  */
        if (! EQ (Fcurrent_buffer (), obuffer)
            || ! EQ (current_buffer->keymap, okeymap))
          /* But do it only if the caller is actually going to read events.
             Otherwise there's no need to make him wake up, and it could
             cause trouble (for example it would make sit_for return).  */
          if (waiting_for_user_input_p == -1)
            record_asynch_buffer_change ();

* wait_reading_process_output; (2 places) call
  record_asynch_buffer_change only if buffer has changed (timers):

    /* If a timer has run, this might have changed buffers
       an alike.  Make read_key_sequence aware of that.  */
    if (timers_run != old_timers_run
        && waiting_for_user_input_p == -1
        && old_buffer != current_buffer)
      record_asynch_buffer_change ();

* read_key_sequence; look for a BUFFER_SWITCH_EVENT (from

    if (BUFFERP (key))
        timer_resume_idle ();

        mock_input = t;
        /* Reset the current buffer from the selected window
           in case something changed the former and not the latter.
           This is to be more consistent with the behavior
           of the command_loop_1.  */
        if (fix_current_buffer)
            if (! FRAME_LIVE_P (XFRAME (selected_frame)))
              Fkill_emacs (Qnil);
            if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
              Fset_buffer (XWINDOW (selected_window)->buffer);

        orig_local_map = get_local_map (PT, current_buffer, Qlocal_map);
        orig_keymap = get_local_map (PT, current_buffer, Qkeymap);
        goto replay_sequence;

* command_loop_1; set selected window's buffer as current between
  looking up and executing command:

    /* Read next key sequence; i gets its length.  */
    i = read_key_sequence (keybuf, sizeof keybuf / sizeof keybuf[0],
                           Qnil, 0, 1, 1);
    /* A filter may have run while we were reading the input.  */
    if (! FRAME_LIVE_P (XFRAME (selected_frame)))
      Fkill_emacs (Qnil);
    if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
      set_buffer_internal (XBUFFER (XWINDOW (selected_window)->buffer));

Johan Bockgård

reply via email to

[Prev in Thread] Current Thread [Next in Thread]