From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Davison Newsgroups: gmane.emacs.help Subject: Re: How to fontify region according to mode Date: Mon, 16 Aug 2010 09:28:26 -0400 Message-ID: <87lj86bsat.fsf@stats.ox.ac.uk> References: <87bp95dsmd.fsf@stats.ox.ac.uk> <874oexdq3f.fsf@stats.ox.ac.uk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1281965811 16280 80.91.229.12 (16 Aug 2010 13:36:51 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 16 Aug 2010 13:36:51 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Lennart Borgman Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 16 15:36:49 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Okzrr-0000oQ-VF for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Aug 2010 15:36:48 +0200 Original-Received: from localhost ([127.0.0.1]:59220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkzkH-0003QE-JQ for geh-help-gnu-emacs@m.gmane.org; Mon, 16 Aug 2010 09:28:57 -0400 Original-Received: from [140.186.70.92] (port=52619 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Okzjt-0003Q8-Fq for help-gnu-emacs@gnu.org; Mon, 16 Aug 2010 09:28:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Okzjr-00035w-Js for help-gnu-emacs@gnu.org; Mon, 16 Aug 2010 09:28:33 -0400 Original-Received: from markov.stats.ox.ac.uk ([163.1.210.1]:34299) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Okzjr-00035d-Cz for help-gnu-emacs@gnu.org; Mon, 16 Aug 2010 09:28:31 -0400 Original-Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id o7GDSTsQ028071; Mon, 16 Aug 2010 14:28:29 +0100 (BST) Original-Received: by blackcap.stats.ox.ac.uk (Postfix, from userid 5158) id 3BA8E2046B; Mon, 16 Aug 2010 14:28:29 +0100 (BST) In-Reply-To: (Lennart Borgman's message of "Sat, 14 Aug 2010 20:35:48 +0200") User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Solaris 8 (1) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:74673 Archived-At: Lennart Borgman writes: > On Sat, Aug 14, 2010 at 8:08 PM, Dan Davison wro= te: >> Lennart Borgman writes: >> >>> On Sat, Aug 14, 2010 at 7:14 PM, Dan Davison w= rote: >>>> I want to write a function to fontify a region according to a certain >>>> mode, and I tried the following tactic (see function below): >>>> >>>> - get the value of `font-lock-defaults' from a buffer in the target mo= de >>>> =C2=A0and bind it inside a let >>>> - bind a bunch of other font-lock variable names to stop them being >>>> =C2=A0overwritten >>>> - call `font-lock-set-defaults' >>>> - call `font-lock-fontify-region' >>>> >>>> It didn't seem to work. Could someone suggest how to alter this so that >>>> it works, or is this approach fundamentally flawed? >>>> >>>> (defun dan/font-lock-fontify-region (mode start end) >>>> =C2=A0(let ((font-lock-defaults >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (with-temp-buffer >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (funcall mode) >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 font-lock-defaults)) >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0font-lock-keywords >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0font-lock-keywords-only >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0font-lock-keywords-case-fold-search >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0font-lock-syntax-table >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0font-lock-beginning-of-syntax-function) >>>> =C2=A0 =C2=A0(font-lock-set-defaults) >>>> =C2=A0 =C2=A0(font-lock-fontify-region start end))) >>>> >>>> >>>> I want the rest of the buffer to remain unaltered and, for now, I'm not >>>> looking for a solution involving mumamo/multi-mode etc. >>> >>> >>> If you want to see how it works then look in mumamo.el. I think you >>> will find the answers to your questions there. (But why do you want to >>> reinvent the wheel? What is the purpose?) >> >> Hi Lennart, >> >> I was looking at mumamo.el earlier today, but it is 9,101 lines long, so >> I would definitely appreciate some guidance. Note that I don't want >> different regions to be subject to different major modes; I only want to >> change the text properties in a region. That was why I was not using >> mumamo and was attempting the simple approach above. I would certainly >> consider mumamo if I wanted multiple major modes. >> >> Dan > > > Hi Dan, > > I am afraid that what you want actually involves the same problem as > using multiple major modes. Why don't you think so? Hi Lennart, OK, I see. It looks like I was being naive and thinking it was simpler than it really is. Seeing as you have worked extensively on this, and as I have wasted a little bit of time on it, would you mind explaining to me where my above approach encounters problems? I.e., inside a let binding, 1. bind `font-lock-defaults' to the appropriate value 2. bind to nil all the other font-lock related variables that `font-lock-set-defaults' will change 3. call `font-lock-set-defaults' 4. call `font-lock-fontify-region' Thanks, Dan