From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Deniz Dogan Newsgroups: gmane.emacs.help Subject: Re: Syntax highlighting fails on copy-paste Date: Sat, 14 May 2011 10:21:54 +0200 Message-ID: <4DCE3BA2.7040304@dogan.se> References: <4DCD23B9.7020400@dogan.se> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1305361385 6525 80.91.229.12 (14 May 2011 08:23:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 14 May 2011 08:23:05 +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 May 14 10:23:01 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QLA7o-00032D-Uu for geh-help-gnu-emacs@m.gmane.org; Sat, 14 May 2011 10:23:01 +0200 Original-Received: from localhost ([::1]:34328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLA7o-0002mO-75 for geh-help-gnu-emacs@m.gmane.org; Sat, 14 May 2011 04:23:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:50967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLA7i-0002mJ-GG for help-gnu-emacs@gnu.org; Sat, 14 May 2011 04:22:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QLA7h-0007OL-K9 for help-gnu-emacs@gnu.org; Sat, 14 May 2011 04:22:54 -0400 Original-Received: from ch-smtp04.sth.basefarm.net ([80.76.153.5]:35387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QLA7h-0007OH-6h for help-gnu-emacs@gnu.org; Sat, 14 May 2011 04:22:53 -0400 Original-Received: from c80-216-105-155.bredband.comhem.se ([80.216.105.155]:50848 helo=[192.168.0.10]) by ch-smtp04.sth.basefarm.net with esmtp (Exim 4.73) (envelope-from ) id 1QLA6t-0004PV-DB for help-gnu-emacs@gnu.org; Sat, 14 May 2011 10:22:04 +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 In-Reply-To: X-Originating-IP: 80.216.105.155 X-Scan-Result: No virus found in message 1QLA6t-0004PV-DB. X-Scan-Signature: ch-smtp04.sth.basefarm.net 1QLA6t-0004PV-DB 67e9f5f10357eb9572e16eb4c19f683e X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.76.153.5 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:80975 Archived-At: 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!