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 20:35:48 +0200 Message-ID: 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 1281811015 32236 80.91.229.12 (14 Aug 2010 18:36:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Aug 2010 18:36:55 +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 20:36:52 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 1OkLb8-0007CN-Tg for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 20:36:51 +0200 Original-Received: from localhost ([127.0.0.1]:47540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkLb8-0004Eo-Bl for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 14:36:50 -0400 Original-Received: from [140.186.70.92] (port=52682 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkLaY-0004DS-6Y for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:36:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OkLaT-0002aB-1M for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:36:14 -0400 Original-Received: from mail-qw0-f41.google.com ([209.85.216.41]:51524) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OkLaS-0002a2-UA for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 14:36:09 -0400 Original-Received: by qwk4 with SMTP id 4so4264229qwk.0 for ; Sat, 14 Aug 2010 11:36:08 -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=05q60y/MM2/ITtrdeSt1MFplvFjs5VLFTpmDHNVPeDY=; b=VI7A3XbYHxOeFZuWEUaKCkgwyO6JuoTzHZiGAY7FJhInQwPa6uQ1+hBP8WgdxrcVvX J0Bf6eU4w4YDX80YXYbYpwU22qqGWEGvz4YgODHcGxtO3rAY+/EMeCwc/XWyHeh6xACB PHNzMKseYjh4rCWXDg2l+9Ty+d9eBGs0suLzE= 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=tgBvIhpOoze/Fxy9YJ7pJEU+sinuUSk4OIXW2f/auBWM1qIM1XS1prap4Pj7lNCKR/ WllLP94+i82vv65fjxXXSNWe1vEkYEUswEsgZh2p3O6KQY627ww2Y5l4EjMQPkRL0h6D xD0i4b10roMoViqxrzPvZrbEGqawkrK66PPKA= Original-Received: by 10.229.215.19 with SMTP id hc19mr2363287qcb.107.1281810968226; Sat, 14 Aug 2010 11:36:08 -0700 (PDT) Original-Received: by 10.229.54.80 with HTTP; Sat, 14 Aug 2010 11:35:48 -0700 (PDT) In-Reply-To: <874oexdq3f.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:74640 Archived-At: On Sat, Aug 14, 2010 at 8:08 PM, Dan Davison wrote= : > Lennart Borgman writes: > >> On Sat, Aug 14, 2010 at 7:14 PM, Dan Davison wr= ote: >>> 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 mod= e >>> =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?