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: How to fontify region according to mode Date: Sat, 14 Aug 2010 13:14:02 -0400 Message-ID: <87bp95dsmd.fsf@stats.ox.ac.uk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1281806080 15434 80.91.229.12 (14 Aug 2010 17:14:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 Aug 2010 17:14:40 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 14 19:14:39 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 1OkKJW-0008Tz-HO for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 19:14:34 +0200 Original-Received: from localhost ([127.0.0.1]:46732 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkKJV-0000K0-Uc for geh-help-gnu-emacs@m.gmane.org; Sat, 14 Aug 2010 13:14:33 -0400 Original-Received: from [140.186.70.92] (port=49624 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OkKJ6-0000Jv-Jd for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:14:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OkKJ5-00013a-If for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:14:08 -0400 Original-Received: from markov.stats.ox.ac.uk ([163.1.210.1]:57738) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OkKJ5-00013I-BM for help-gnu-emacs@gnu.org; Sat, 14 Aug 2010 13:14:07 -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 o7EHE5Ts016642 for ; Sat, 14 Aug 2010 18:14:05 +0100 (BST) Original-Received: by blackcap.stats.ox.ac.uk (Postfix, from userid 5158) id 45888201CA; Sat, 14 Aug 2010 18:14:05 +0100 (BST) 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:74637 Archived-At: 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 and bind it inside a let - bind a bunch of other font-lock variable names to stop them being overwritten - 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) (let ((font-lock-defaults (with-temp-buffer (funcall mode) font-lock-defaults)) font-lock-keywords font-lock-keywords-only font-lock-keywords-case-fold-search font-lock-syntax-table font-lock-beginning-of-syntax-function) (font-lock-set-defaults) (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. Thanks, Dan