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: Sat, 14 Aug 2010 14:08:36 -0400 Message-ID: <874oexdq3f.fsf@stats.ox.ac.uk> References: <87bp95dsmd.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 1281809364 26962 80.91.229.12 (14 Aug 2010 18:09:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Aug 2010 18:09:24 +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 Sat Aug 14 20:09:23 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 1OkLAY-0005ut-5G for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 20:09:22 +0200 Original-Received: from localhost ([127.0.0.1]:41399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkLAX-0006Rt-Ig for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 14:09:21 -0400 Original-Received: from [140.186.70.92] (port=34614 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkL9y-0006QM-GV for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:08:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OkL9t-0007mR-V0 for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:08:46 -0400 Original-Received: from markov.stats.ox.ac.uk ([163.1.210.1]:62833) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OkL9t-0007m7-NN for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:08:41 -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 o7EI8dHn018493; Sat, 14 Aug 2010 19:08:39 +0100 (BST) Original-Received: by blackcap.stats.ox.ac.uk (Postfix, from userid 5158) id 3F498201CA; Sat, 14 Aug 2010 19:08:39 +0100 (BST) In-Reply-To: (Lennart Borgman's message of "Sat, 14 Aug 2010 19:21:57 +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:74639 Archived-At: Lennart Borgman writes: > On Sat, Aug 14, 2010 at 7:14 PM, Dan Davison wro= te: >> 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 mode >> =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