From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lennart Borgman Newsgroups: gmane.emacs.help Subject: Re: How to fontify region according to mode Date: Sat, 14 Aug 2010 19:21:57 +0200 Message-ID: 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 1281806582 17053 80.91.229.12 (14 Aug 2010 17:23:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Aug 2010 17:23:02 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Dan Davison Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 14 19:23:01 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 1OkKRc-0003Wo-4u for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 19:22:56 +0200 Original-Received: from localhost ([127.0.0.1]:34480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkKRb-0002TT-Ig for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 13:22:55 -0400 Original-Received: from [140.186.70.92] (port=59465 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkKR6-0002RT-Fx for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:22:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OkKR1-0001wZ-2M for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:22:24 -0400 Original-Received: from mail-qw0-f41.google.com ([209.85.216.41]:46332) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OkKR1-0001wI-0B for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:22:19 -0400 Original-Received: by qwk4 with SMTP id 4so4229374qwk.0 for ; Sat, 14 Aug 2010 10:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=/TrHhBFodoXCMWKWkdxpgF1C8JICuP1Yy+gUj8DHzGc=; b=wJ8KmOBuZuvMhb/g4tRbBybeO32KBnSwOnHTS0munENTKx3CNRsGOunjXdSPpkNLsw HvHwlrnZYEQfvJEjrZexgIU5bbP3pnR5g4Om7+jzApCMSG3fY+rm5LlWNDDH+b3h6q8m sxZRGrUobylF2+MIMgHf/Kh61l+w+xtcTOBas= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=LkdRKYOcfvIl6NmoI1niJeWPwO6qa6QH8M9Cib8afUesgaNgiIo8hQqV8cX8G6zl1Q C3AIeryzQ5SzQKBB5HD2ibIfzmPrA+RTlDYX/dMCVcViWJvURITGFH43sAOWA8DHKRA6 zV+jbgTB0A8Kr+EFtcAjOB53EGUevWEBPXLW8= Original-Received: by 10.229.141.75 with SMTP id l11mr124547qcu.154.1281806537201; Sat, 14 Aug 2010 10:22:17 -0700 (PDT) Original-Received: by 10.229.54.80 with HTTP; Sat, 14 Aug 2010 10:21:57 -0700 (PDT) In-Reply-To: <87bp95dsmd.fsf@stats.ox.ac.uk> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:74638 Archived-At: On Sat, Aug 14, 2010 at 7:14 PM, Dan Davison wrote= : > 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?)