From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: rusi Newsgroups: gmane.emacs.help Subject: Re: How to make font lock work with comments? Date: Thu, 30 Dec 2010 09:28:44 -0800 (PST) Organization: http://groups.google.com Message-ID: <82cc058d-0daf-4750-8725-0ffaa20783e3@29g2000prb.googlegroups.com> References: <8649bced-1240-483b-ba41-9bc581938275@t8g2000prh.googlegroups.com> <87bp43nyha.fsf@kuiper.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1293730857 9593 80.91.229.12 (30 Dec 2010 17:40:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 30 Dec 2010 17:40:57 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 30 18:40:53 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 1PYMUf-0003Nq-6e for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Dec 2010 18:40:53 +0100 Original-Received: from localhost ([127.0.0.1]:55987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PYMUe-0000c4-MF for geh-help-gnu-emacs@m.gmane.org; Thu, 30 Dec 2010 12:40:52 -0500 Original-Path: usenet.stanford.edu!postnews.google.com!29g2000prb.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: 116.73.35.230 Original-X-Trace: posting.google.com 1293730124 31194 127.0.0.1 (30 Dec 2010 17:28:44 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 30 Dec 2010 17:28:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 29g2000prb.googlegroups.com; posting-host=116.73.35.230; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13,gzip(gfe) Original-Xref: usenet.stanford.edu gnu.emacs.help:183754 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:77972 Archived-At: On Dec 30, 7:09=C2=A0pm, "Pascal J. Bourguignon" wrote: > rusi writes: > > Im hacking on an apl mode > > In other words emacs sees this as a comment-type char (similar to what > > it says for semicolon in elisp buffers > > > And yet in an elisp buffer the ; to EOL is red > > but here it is not. > > Font locking is a tricky matter. > > (font-lock-add-keywords nil > =C2=A0 =C2=A0 '(("=E2=8D=9D.*" =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00 font-lock-comment-face pr= epend) > =C2=A0 =C2=A0 =C2=A0("[^\\]\"\\([^\"\\]*\\|\\.\\)\"" 0 font-lock-string-f= ace =C2=A0prepend))) Thanks Pascal. I gave this (\x235 is that char) and it works [Else I get some unicode-related messages when I try ot save the el file] (font-lock-add-keywords 'inferior-apl-mode '(("\x235d.*" 0 font-lock-comment-face prepend))) I guess the second line is for strings? Where do I get all the (typical) faces that should be set up for a progmode? Ive been trying to copy stuff from scheme.el -- is there a better model? > > The main problem is that it uses regular expressions to find the > "keywords", but you want syntax coloring. =C2=A0However, there's a way to= use > it for syntax coloring, since instead of a regular expression, you can > use a function here, which will have to set the "matched regions". > > For example, for an assembler, I wrote a function to parse > (syntactically) an assembler line, and matching the fields. =C2=A0It is > configured with font-lock-add-keywords as: > > =C2=A0(font-lock-add-keywords > =C2=A0 =C2=A0nil > =C2=A0 =C2=A0(list > =C2=A0 =C2=A0 (list > =C2=A0 =C2=A0 =C2=A0(function search-asm7090-fields) > =C2=A0 =C2=A0 =C2=A0'(1 font-lock-function-name-face) =C2=A0 =C2=A0 =C2= =A0 ; labels > =C2=A0 =C2=A0 =C2=A0'(2 font-lock-keyword-face) =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ; operation codes > =C2=A0 =C2=A0 =C2=A0'(3 font-lock-reference-face) =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 ; arguments > =C2=A0 =C2=A0 =C2=A0'(4 font-lock-comment-face) =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ; comments > =C2=A0 =C2=A0 =C2=A0'(5 font-lock-preprocessor-face) =C2=A0 =C2=A0 =C2=A0= =C2=A0; ibsys > =C2=A0 =C2=A0 =C2=A0'(6 font-lock-type-face) =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0; cols 72-80 > =C2=A0 =C2=A0 =C2=A0))) I dont think I really understand this... In any case I guess I dont need much parsing (for apl) > > Of course, you can also implement buffer-wide syntax analysis, and have > these functions just report the findings. > > -- > __Pascal Bourguignon__ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0http://www.informatimago.com/ > A bad day in () is better than a good day in {}.