🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #87652

font-lock-mode speedup (patch)

#87652
From: Roland B Roberts, 8*252-6458
Date: Thu, 08 Sep 1994 15:01
87 lines
4302 bytes
GNU Emacs 19.22.4 of Tue Jun 21 1994 on VAXMS2 (vax-vms)

I found one bottle-neck in font-lock-mode that can be sped up some
(sometimes quite a bit!).  Most the modes I've used have comments in a
particular face that overrides whatever other face might apply.
font-lock-mode fontifies the comment, then checks inside the comment for
keywords, even though the default keyword lists never override the
comment face.  I have a patch for it that allows font-lock-mode to skip
even looking.

Note that if you define your own set of keyword regexps that use the
fourth list element to override any current text-property, such skipping
could cause problems.  To prevent that, I've made a new buffer-local
variable called font-lock-leave-comments that tells font-lock-mode never
to look inside comments for keywords; this is the default.  Setting it
nil restores the old behavior.

I haven't looked at any Emacs newer than 19.22, so I don't know if more
recent versions of font-lock-mode are speedier or not.  If this has
already been "fixed" in some other fashion, I'd love to know about
it....

I have tested this somewhat, using yanking non-fontified text into a
C-mode font-locked buffer (as well as just typing).  I did the yanks
into the middle of comments, overlapping a comment (both closing and
ending it with the yanked text) and into the body of a function.  In all
cases it correctly fontifies the text.

This isn't thee cure for font-lock slowness, but it provides a
noticeable improvement when typing C comments...

roland

*** _d1:font-lock.el
--- font-lock.el
**************
*** 107,112
  Be careful composing regexps for this list; the wrong pattern can dramatically
  slow things down!")
  
  (defvar font-lock-keywords-case-fold-search nil
    "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
  
--- 107,117 -----
  Be careful composing regexps for this list; the wrong pattern can dramatically
  slow things down!")
  
+ (defvar font-lock-leave-comments t
+   "*Non-nil means don't scan comments for keywords, just use the comment face.\n\
+ This variable is buffer-local so each mode can do things differently.")
+ (make-variable-buffer-local 'font-lock-leave-comments)
+ 
  (defvar font-lock-keywords-case-fold-search nil
    "*Non-nil means the patterns in `font-lock-keywords' are case-insensitive.")
  
**************
*** 258,266
        ;; First scan for strings and comments.
        ;; Must scan from line start in case of
        ;; inserting space into `intfoo () {}'.
!       (font-lock-fontify-region beg (1+ end))
!       ;; Now scan for keywords.
!       (font-lock-hack-keywords beg end))))
  
  ;;; Fontifying arbitrary patterns
  
--- 263,278 -----
        ;; First scan for strings and comments.
        ;; Must scan from line start in case of
        ;; inserting space into `intfoo () {}'.
!       (let ((prev-state font-lock-cache-state)
! 	    (state nil))
! 	(font-lock-fontify-region beg (1+ end))
! 	;; Now scan for keywords
! 	;; Unless the above parse says we are in a comment
! 	;;  and font-lock-leave-comments is t --RBR
! 	(setq state (parse-partial-sexp beg end nil nil prev-state))
! 	(if (not (and font-lock-leave-comments
! 		      (or (nth 4 state) (nth 7 state))))
! 	    (font-lock-hack-keywords beg end))))))
  
  ;;; Fontifying arbitrary patterns
----
Roland B Roberts                        Martin Marietta
roberts@vaxms2.dnet.ge.com              Ocean, Radar and Sensor Systems
roberts@consl670uc.utica.ge.com         525 French Road
(315) 793-6458                          Utica, NY 13502-5993
Technical Details
Message-ID: <9409081450.AA14298@thomas.ge.com>
Path: arc1-ca.pugleaf.net!nntp.gmd.de!newsserver.jvnc.net!netnews.upenn.edu!rutgers!cis.ohio-state.edu!vaxms2.dnet.ge.COM!roberts

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,e68b872acaed7aa2,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1994-09-08 10:33:31 PST
Path: arc1-ca.pugleaf.net!nntp.gmd.de!newsserver.jvnc.net!netnews.upenn.edu!rutgers!cis.ohio-state.edu!vaxms2.dnet.ge.COM!roberts
From: roberts@vaxms2.dnet.ge.COM (Roland B Roberts, 8*252-6458)
Newsgroups: gnu.emacs.bug
Subject: font-lock-mode speedup (patch)
Date: 8 Sep 1994 11:01:24 -0400
Organization: GNUs Not Usenet
Lines: 87
Sender: daemon@cis.ohio-state.edu
Approved: bug-gnu-emacs@prep.ai.mit.edu
Distribution: gnu
Message-ID: <9409081450.AA14298@thomas.ge.com>