* Mysterious buffer switching
@ 2005-02-27 14:29 Chong Yidong
2005-02-27 19:01 ` David Kastrup
2005-02-28 11:25 ` Richard Stallman
0 siblings, 2 replies; 4+ messages in thread
From: Chong Yidong @ 2005-02-27 14:29 UTC (permalink / raw)
Do `emacs -Q', turn on global-font-lock-mode, and visit a long file --
say, `.emacs'. Now go back to the `*scratch*' buffer and evaluate the
following:
(defun check-buffer ()
(if (not (eq (current-buffer) my-buffer))
(message "Foo: %s" (buffer-name (current-buffer)))))
(setq my-buffer (current-buffer))
(run-with-timer 0.1 0.1 'check-buffer)
Wait for around five seconds. You will see:
Foo: .emacs
You need to have font-lock enabled, and there has to be a long fontified
buffer lurking around somewhere. My guess is that the font-lock engine is
doing stuff while waiting for input, which causes current-buffer to be
different when the timer calls the function.
This has the unfortunate consequence of breaking Pong.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mysterious buffer switching
2005-02-27 14:29 Mysterious buffer switching Chong Yidong
@ 2005-02-27 19:01 ` David Kastrup
2005-02-28 11:25 ` Richard Stallman
1 sibling, 0 replies; 4+ messages in thread
From: David Kastrup @ 2005-02-27 19:01 UTC (permalink / raw)
Cc: emacs-devel
"Chong Yidong" <cyd@stupidchicken.com> writes:
> Do `emacs -Q', turn on global-font-lock-mode, and visit a long file --
> say, `.emacs'. Now go back to the `*scratch*' buffer and evaluate the
> following:
>
> (defun check-buffer ()
> (if (not (eq (current-buffer) my-buffer))
> (message "Foo: %s" (buffer-name (current-buffer)))))
>
> (setq my-buffer (current-buffer))
> (run-with-timer 0.1 0.1 'check-buffer)
>
> Wait for around five seconds. You will see:
>
> Foo: .emacs
>
> You need to have font-lock enabled, and there has to be a long fontified
> buffer lurking around somewhere. My guess is that the font-lock engine is
> doing stuff while waiting for input, which causes current-buffer to be
> different when the timer calls the function.
>
> This has the unfortunate consequence of breaking Pong.
Which would be the fault of whatever Pong is. run-with-timer does not
guarantee you any particular buffer. You can always make do with
(run-with-timer 0.1 0.1 `(lambda () (with-current-buffer
,(current-buffer) (whateverfunction))))
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mysterious buffer switching
2005-02-27 14:29 Mysterious buffer switching Chong Yidong
2005-02-27 19:01 ` David Kastrup
@ 2005-02-28 11:25 ` Richard Stallman
2005-02-28 13:46 ` Chong Yidong
1 sibling, 1 reply; 4+ messages in thread
From: Richard Stallman @ 2005-02-28 11:25 UTC (permalink / raw)
Cc: emacs-devel
Wait for around five seconds. You will see:
Foo: .emacs
You need to have font-lock enabled, and there has to be a long fontified
buffer lurking around somewhere. My guess is that the font-lock engine is
doing stuff while waiting for input, which causes current-buffer to be
different when the timer calls the function.
It might be due to this code:
;; In the following code, the `sit-for' calls cause a
;; redisplay, so it's required that the
;; buffer-modified flag of a buffer that is displayed
;; has the right value---otherwise the mode line of
;; an unmodified buffer would show a `*'.
(let (start
(nice (or jit-lock-stealth-nice 0))
(point (point-min)))
(while (and (setq start
(jit-lock-stealth-chunk-start point))
(sit-for nice))
Pong ought to be fixed to avoid depending on this,
but it wouldn't hurt to remove this source of unpredictability.
Does this patch do the job?
*** jit-lock.el 26 Mar 2004 12:04:00 -0500 1.35
--- jit-lock.el 27 Feb 2005 17:09:45 -0500
***************
*** 415,420 ****
--- 415,421 ----
(unless (or executing-kbd-macro
(window-minibuffer-p (selected-window)))
(let ((buffers (buffer-list))
+ (outer-buffer (current-buffer))
minibuffer-auto-raise
message-log-max)
(with-local-quit
***************
*** 449,455 ****
(point (point-min)))
(while (and (setq start
(jit-lock-stealth-chunk-start point))
! (sit-for nice))
;; fontify a block.
(jit-lock-fontify-now start (+ start jit-lock-chunk-size))
--- 450,459 ----
(point (point-min)))
(while (and (setq start
(jit-lock-stealth-chunk-start point))
! ;; In case sit-for runs any timers,
! ;; give them the expected current buffer.
! (with-current-buffer outer-buffer
! (sit-for nice)))
;; fontify a block.
(jit-lock-fontify-now start (+ start jit-lock-chunk-size))
***************
*** 461,467 ****
;; Wait a little if load is too high.
(when (and jit-lock-stealth-load
(> (car (load-average)) jit-lock-stealth-load))
! (sit-for (or jit-lock-stealth-time 30)))))))))))))
\f
--- 465,474 ----
;; Wait a little if load is too high.
(when (and jit-lock-stealth-load
(> (car (load-average)) jit-lock-stealth-load))
! ;; In case sit-for runs any timers,
! ;; give them the expected current buffer.
! (with-current-buffer outer-buffer
! (sit-for (or jit-lock-stealth-time 30))))))))))))))
\f
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Mysterious buffer switching
2005-02-28 11:25 ` Richard Stallman
@ 2005-02-28 13:46 ` Chong Yidong
0 siblings, 0 replies; 4+ messages in thread
From: Chong Yidong @ 2005-02-28 13:46 UTC (permalink / raw)
Cc: emacs-devel
> Pong ought to be fixed to avoid depending on this,
> but it wouldn't hurt to remove this source of unpredictability.
> Does this patch do the job?
Yes.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-02-28 13:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-27 14:29 Mysterious buffer switching Chong Yidong
2005-02-27 19:01 ` David Kastrup
2005-02-28 11:25 ` Richard Stallman
2005-02-28 13:46 ` Chong Yidong
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.