all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lennart Borgman <lennart.borgman@gmail.com>
To: Dan Davison <davison@stats.ox.ac.uk>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to fontify region according to mode
Date: Sat, 14 Aug 2010 19:21:57 +0200	[thread overview]
Message-ID: <AANLkTimb-FpyvL-qP0PCz64WQhWy-zn1ib617wTmwd9r@mail.gmail.com> (raw)
In-Reply-To: <87bp95dsmd.fsf@stats.ox.ac.uk>

On Sat, Aug 14, 2010 at 7:14 PM, Dan Davison <davison@stats.ox.ac.uk> 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
>  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.


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?)



  reply	other threads:[~2010-08-14 17:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-14 17:14 How to fontify region according to mode Dan Davison
2010-08-14 17:21 ` Lennart Borgman [this message]
2010-08-14 18:08   ` Dan Davison
2010-08-14 18:35     ` Lennart Borgman
2010-08-16 13:28       ` Dan Davison
2010-08-16 14:39         ` Lennart Borgman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimb-FpyvL-qP0PCz64WQhWy-zn1ib617wTmwd9r@mail.gmail.com \
    --to=lennart.borgman@gmail.com \
    --cc=davison@stats.ox.ac.uk \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.