help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax highlighting fails on copy-paste


From: Deniz Dogan
Subject: Re: Syntax highlighting fails on copy-paste
Date: Sat, 14 May 2011 10:21:54 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10

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 via email to

[Prev in Thread] Current Thread [Next in Thread]