From xemacs-m  Thu Jul 10 19:11:05 1997
Received: from martigny.ai.mit.edu (daemon@martigny.ai.mit.edu [18.43.0.152])
	by xemacs.org (8.8.5/8.8.5) with ESMTP id TAA14554
	for <xemacs-beta@xemacs.org>; Thu, 10 Jul 1997 19:11:04 -0500 (CDT)
Received: from berne.ai.mit.edu by martigny.ai.mit.edu with SMTP
	(1.40.112.8/16.2) id AA056399856; Thu, 10 Jul 1997 20:10:56 -0400
From: Bill Dubuque <wgd@martigny.ai.mit.edu>
Message-Id: <199707110010.AA056399856@martigny.ai.mit.edu>
Received: by berne.ai.mit.edu
	(1.40.112.8/16.2) id AA233049854; Thu, 10 Jul 1997 20:10:54 -0400
Date: Thu, 10 Jul 1997 20:10:54 -0400
To: karlheg@inetarena.com
Cc: xemacs-beta@xemacs.org
Subject: Re: font-lock, hanging defun's

"Karl M. Hegbloom" <karlheg@inetarena.com> wrote:
| 
|  I don't think the 'five times slower' is very real; with lazy-lock,
| who'll really notice anyhow?
| 
| --- lisp/packages/font-lock.el.orig	Thu Jun 26 02:43:08 1997
| +++ lisp/packages/font-lock.el	Wed Jul  9 21:55:42 1997
| @@ -1587,7 +1587,7 @@
|     ;; Anything not a variable or type declaration is fontified as a function.
|     ;; It would be cleaner to allow preceding whitespace, but it would also be
|     ;; about five times slower.
| -   (list (concat "^(\\(def\\("
| +   (list (concat "(\\(def\\("
|  		  ;; Variable declarations.
|  		  "\\(const\\(\\|ant\\)\\|ine-key\\(\\|-after\\)\\|var\\)\\|"
|  		  ;; Structure declarations.

The comment is correct: if you remove the bol anchor by changing the
regexp from "^(def..." to "(def..." it will cause a radical slowdown 
(just how much of a slowdown will depend on the density of '('s in 
the code -- which is usually high in Lisp code). Having worked 
very closely on font-lock packages (FontiFly) I can assure you
this is really the case. E.g. whenever the internal syntax
caches are flushed (a frequent occurrence when deleting backwards)
font-lock needs to locate the enclosing defun, then totally
reparse from that point on. If you slow down locating defuns
then you may slow down auto-repeated backward deletes, etc, a 
situation already noticed by those editing large C functions.

You are incorrect in thinking that lazy-lock will prevent the
slowdown, e.g. it doesn't help the aforementioned problem when 
the internal (C-coded) syntax caches are flushed.

Moreover, since other packages depend upon the Emacs convention 
that defuns start in column 0, it is better to NOT font-lock
defuns that do not start in column 0 so as to visually warn the 
user that they are not globally recognized as defuns by Emacs.

-Bill Dubuque

