unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: [rudalics@gmx.at: Re: jit lock sit-for provokes redisplay provokes imenu]
Date: Tue, 29 Aug 2006 22:43:13 -0400	[thread overview]
Message-ID: <878xl754fy.fsf@furball.mit.edu> (raw)
In-Reply-To: <E1GI24C-00077w-1P@fencepost.gnu.org> (Richard Stallman's message of "Tue, 29 Aug 2006 07:47:40 -0400")

Richard Stallman <rms@gnu.org> writes:

>     > + 	(when jit-lock-mode
>     > + 	  ;; Avoid updating the menubar after each stealth fontification.
>     > + 	  (jit-lock-register 'imenu-save-tick-before-jit-lock nil nil)
>     > + 	  (jit-lock-register 'imenu-update-tick-after-jit-lock nil t))
>
>     Won't work if font-lock-mode is enabled after imenu is used.
>
> Could that be solved by making jit-lock-mode also enable these hooks?

How about this?  It adds jit-lock-pre-stealth-fontify-hook and
jit-lock-post-stealth-fontify-hook, which are normal hooks run before
and after each chunk of stealth fontification.  Then imenu can use
this to avoid menu bar updates resulting from stealth fontification.

The only disadvantage is adding two `run-hook' called to the
jit-lock-stealth-fontify timer function, but hopefully the performance
impact isn't too bad.

*** emacs/lisp/imenu.el.~1.118.~	2006-08-29 18:14:09.000000000 -0400
--- emacs/lisp/imenu.el	2006-08-29 22:38:21.000000000 -0400
***************
*** 953,958 ****
--- 953,962 ----
  	(define-key newmap [menu-bar index]
  	  `(menu-item ,name ,(make-sparse-keymap "Imenu")))
  	(use-local-map newmap)
+ 	(add-hook 'jit-lock-pre-stealth-fontify-hook
+ 		  'imenu-pre-stealth-fontify-fn nil t)
+ 	(add-hook 'jit-lock-post-stealth-fontify-hook
+ 		  'imenu-post-stealth-fontify-fn nil t)
  	(add-hook 'menu-bar-update-hook 'imenu-update-menubar))
      (error "The mode `%s' does not support Imenu" mode-name)))
  
***************
*** 970,980 ****
--- 974,1000 ----
    "The value of (buffer-modified-tick) as of last call to `imenu-update-menubar'.")
  (make-variable-buffer-local 'imenu-menubar-modified-tick)
  
+ (defvar imenu-unmodified-before-stealth-fontify nil)
+ (make-variable-buffer-local 'imenu-unmodified-before-stealth-fontify)
+ 
+ (defun imenu-pre-stealth-fontify-fn ()
+   (setq imenu-unmodified-before-stealth-fontify
+ 	(eq (buffer-modified-tick) imenu-menubar-modified-tick)))
+ 
+ (defun imenu-post-stealth-fontify-fn ()
+   (if imenu-unmodified-before-stealth-fontify
+       (setq imenu-menubar-modified-tick (buffer-modified-tick)
+ 	    imenu-unmodified-before-stealth-fontify nil)))
+ 
+ (setq foo 0)
+ 
  (defun imenu-update-menubar ()
    (when (and (current-local-map)
  	     (keymapp (lookup-key (current-local-map) [menu-bar index]))
  	     (not (eq (buffer-modified-tick)
  		      imenu-menubar-modified-tick)))
+     (setq foo (% (1+ foo) 10))
+     (message (format "Foo %d" foo))
      (setq imenu-menubar-modified-tick (buffer-modified-tick))
      (let ((index-alist (imenu--make-index-alist t)))
        ;; Don't bother updating if the index-alist has not changed
*** emacs/lisp/jit-lock.el.~1.55.~	2006-08-29 18:14:09.000000000 -0400
--- emacs/lisp/jit-lock.el	2006-08-29 22:33:28.000000000 -0400
***************
*** 182,187 ****
--- 182,192 ----
    "List of buffers with pending deferred fontification.")
  (defvar jit-lock-stealth-buffers nil
    "List of buffers that are being fontified stealthily.")
+ 
+ (defvar jit-lock-pre-stealth-fontify-hook nil
+   "Normal hook run before performing each chunk of stealth fontification.")
+ (defvar jit-lock-post-stealth-fontify-hook nil
+   "Normal hook run after performing each chunk of stealth fontification.")
  \f
  ;;; JIT lock mode
  
***************
*** 488,495 ****
--- 493,502 ----
  		  (with-temp-message (if jit-lock-stealth-verbose
  					 (concat "JIT stealth lock "
  						 (buffer-name)))
+ 		    (run-hooks 'jit-lock-pre-stealth-fontify-hook)
  		    (jit-lock-fontify-now start
  					  (+ start jit-lock-chunk-size))
+ 		    (run-hooks 'jit-lock-post-stealth-fontify-hook)
  		    ;; Run again after `jit-lock-stealth-nice' seconds.
  		    (setq delay (or jit-lock-stealth-nice 0)))
  		;; Nothing to fontify here.  Remove this buffer from
***************
*** 503,509 ****
  	(timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
  	(timer-inc-time jit-lock-stealth-repeat-timer delay)
  	(timer-activate-when-idle jit-lock-stealth-repeat-timer t)))))
- 
  \f
  ;;; Deferred fontification.
  
--- 510,515 ----

  reply	other threads:[~2006-08-30  2:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-28  9:52 [rudalics@gmx.at: Re: jit lock sit-for provokes redisplay provokes imenu] Richard Stallman
2006-08-28 10:01 ` David Kastrup
2006-08-28 11:47   ` Kim F. Storm
2006-08-29 17:18   ` Richard Stallman
2006-08-28 16:22 ` Chong Yidong
2006-08-28 16:44   ` Stefan Monnier
2006-08-29 11:47     ` Richard Stallman
2006-08-30  2:43       ` Chong Yidong [this message]
2006-08-30  3:41         ` Stefan Monnier
2006-08-30  7:52           ` Kim F. Storm
2006-08-31  0:28           ` Chong Yidong
2006-08-31  4:01             ` Stefan Monnier
2006-08-30 17:59         ` Richard Stallman
2006-08-30 18:29           ` martin rudalics
2006-08-31  0:29             ` Chong Yidong
2006-08-31  6:11               ` martin rudalics
2006-08-31  7:49                 ` Kim F. Storm
2006-08-31 13:12                   ` Chong Yidong
2006-08-31 22:57                     ` Richard Stallman
2006-09-01 13:42                       ` Chong Yidong
2006-08-31 18:16             ` Richard Stallman
2006-09-01  6:41               ` martin rudalics
2006-09-01 12:47                 ` Richard Stallman
2006-08-30 20:49           ` Stefan Monnier
2006-08-31 18:16             ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878xl754fy.fsf@furball.mit.edu \
    --to=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).