From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: how to prevent font-lock from messing with a portion of text? Date: Mon, 26 Mar 2007 09:01:04 -0400 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1174914172 14447 80.91.229.12 (26 Mar 2007 13:02:52 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 26 Mar 2007 13:02:52 +0000 (UTC) Cc: Emacs-Devel To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 26 15:02:45 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HVoqS-0005RE-GZ for ged-emacs-devel@m.gmane.org; Mon, 26 Mar 2007 15:02:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HVosh-0007tQ-8o for ged-emacs-devel@m.gmane.org; Mon, 26 Mar 2007 08:05:03 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HVorG-0005QY-02 for emacs-devel@gnu.org; Mon, 26 Mar 2007 09:03:34 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HVorB-0005Lv-Jp for emacs-devel@gnu.org; Mon, 26 Mar 2007 09:03:33 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HVorA-0005LI-LW for emacs-devel@gnu.org; Mon, 26 Mar 2007 08:03:29 -0500 Original-Received: from bc.sympatico.ca ([209.226.175.184] helo=tomts22-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HVoov-0003YQ-4C for emacs-devel@gnu.org; Mon, 26 Mar 2007 09:01:09 -0400 Original-Received: from pastel.home ([70.55.83.113]) by tomts22-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20070326130105.XIAJ1767.tomts22-srv.bellnexxia.net@pastel.home> for ; Mon, 26 Mar 2007 09:01:05 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id 4388C7F50; Mon, 26 Mar 2007 09:01:04 -0400 (EDT) In-Reply-To: (Drew Adams's message of "Sun\, 25 Mar 2007 18\:48\:09 -0700") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux) X-detected-kernel: Solaris 8 (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:68593 Archived-At: > (defun put-text-property-unless-ignore (start end property value &optional > object) > "`put-text-property', but ignore text with property `font-lock-ignore'." > (let ((here (min start end)) > (end1 (max start end))) > (while (< here end1) > (unless (get-text-property here 'font-lock-ignore object) > (put-text-property here (1+ here) property value object)) > (setq here (1+ here))))) This will still override a face on a word inside a string, because (get-text-property 'font-lock-ignore object) will be nil. You need to check for the presence of the property over the whole start..end region. > 2. In font-lock.el, use this definition of > `font-lock-default-unfontify-region': > (defun font-lock-default-unfontify-region (beg end) > "Unfontify from BEG to END, unless text with property `font-lock-ignore'." > (let ((here (min beg end)) > (end1 (max beg end))) > (while (< here end1) > (unless (get-text-property here 'font-lock-ignore) > (remove-list-of-text-properties > here (1+ here) (append font-lock-extra-managed-props > (if font-lock-syntactic-keywords > '(syntax-table face font-lock-multiline) > '(face font-lock-multiline))))) > (setq here (1+ here))))) Same thing here, except even more so. Then the problem becomes that doing all those extra checks costs time, all the time, for a feature which will be almost never used. OK, here's another option: don't change anything to font-lock, don't fiddle with it at all, just don't use text-properties to add your special faces. Use overlays instead. Problem solved, Stefan