unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Deniz Dogan <deniz@dogan.se>
To: help-gnu-emacs@gnu.org
Subject: Re: Syntax highlighting fails on copy-paste
Date: Sat, 14 May 2011 10:21:54 +0200	[thread overview]
Message-ID: <4DCE3BA2.7040304@dogan.se> (raw)
In-Reply-To: <loom.20110513T232440-220@post.gmane.org>

On 2011-05-13 23:31, Alp Aker wrote:
>> So to summarize: when I copy-paste those chords/lyrics into a buffer
>> with guitar-mode, not everything gets syntax highlighted until I edit
>> the content around the chords.
>>
>> Why is this?
>
> It’s not a problem with pasting.  Your function `guitar-chord-matcher’
> isn’t defined correctly.  When font-lock calls a function to provide
> match data for keyword fontification, it calls that function repeatedly
> until either (a) point reaches the limit of the region being fontified,
> or (b) the matching function returns nil.  Your function returns nil
> when it encounters an invalid chord, stopping fontification at that
> point.  What you want is for `guitar-chord-matcher’ to keep searching
> if it encounters an invalid chord.  So, something like:
>
> (defun guitar-chord-matcher (limit)
>    (with-syntax-table guitar-mode-syntax-table
>      (catch 'found
>        (while (re-search-forward guitar-full-chord-regexp limit t)
>          (when (save-match-data
>                  (guitar-valid-chord-p (match-string 0)))
>            (throw 'found t))))))
>
> Although catch forms are slow, so you'll probably want to code it
> differently.
>
>
>

Thank you, that makes sense!



      reply	other threads:[~2011-05-14  8:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-13 12:27 Syntax highlighting fails on copy-paste Deniz Dogan
2011-05-13 21:31 ` Alp Aker
2011-05-14  8:21   ` Deniz Dogan [this message]

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=4DCE3BA2.7040304@dogan.se \
    --to=deniz@dogan.se \
    --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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).