From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Trouble fontifying /** ... */ Date: Tue, 13 Jan 2009 23:04:24 -0800 (PST) Organization: http://groups.google.com Message-ID: <04c514f4-f93b-4884-87b0-2031d6141553@z28g2000prd.googlegroups.com> References: <9e66205f-0f64-47da-8eef-b351311beba6@d42g2000prb.googlegroups.com> <32501463-47d1-4553-9961-c4654cffffeb@v15g2000yqn.googlegroups.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: ger.gmane.org 1231934298 28399 80.91.229.12 (14 Jan 2009 11:58:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 14 Jan 2009 11:58:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jan 14 12:59:29 2009 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.50) id 1LN4P9-0007dp-VX for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Jan 2009 12:59:28 +0100 Original-Received: from localhost ([127.0.0.1]:41255 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LN4Nt-0008PT-JA for geh-help-gnu-emacs@m.gmane.org; Wed, 14 Jan 2009 06:58:09 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!z28g2000prd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 147 Original-NNTP-Posting-Host: 24.6.175.142 Original-X-Trace: posting.google.com 1231916664 21291 127.0.0.1 (14 Jan 2009 07:04:24 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Wed, 14 Jan 2009 07:04:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z28g2000prd.googlegroups.com; posting-host=24.6.175.142; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:165987 X-Mailman-Approved-At: Wed, 14 Jan 2009 06:57:11 -0500 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:61325 Archived-At: On Jan 13, 7:18=C2=A0pm, Davin Pearson wrote: > On Jan 10, 2:21=C2=A0am, Xah Lee wrote: > > > On Jan 8, 8:54=C2=A0pm, Davin Pearson wrote: > > > > I have invented a language called SJS that it a mixture of Pascal and > > > Java for easier learning of the Java language. =C2=A0In sjs-mode > > > I would like the following code: > > > > /** > > > =C2=A0 I am a Javadoc-style comment. > > > */ > > > > To be fontified in font-lock-doc-face but I cannot find an elegant wa= y > > > to do this. =C2=A0What follows is some Emacs version information, > > > via report-emacs-bug: > > > your question is a FAQ but without much polished answer. > > Here is my existing code. =C2=A0The trouble with it is > that it sometimes highlights the keyword end in font-lock-type-face. > This is a problem with inheriting from the java major mode. > > (defun sjs-mode > () > > (interactive) > =C2=A0 (font-lock-mode > 0) > =C2=A0 (kill-all-local- > variables) > =C2=A0 (java- > mode) > > =C2=A0 (setq major-mode 'sjs- > mode) > =C2=A0 (setq mode-name > "SJS") > > =C2=A0 (set-syntax-table sjs-mode-syntax- > table) > =C2=A0 (use-local-map sjs-mode- > map) > > =C2=A0 (local-set-key "\t" 'sjs-- > tab) > > =C2=A0 (local-set-key [(meta control \\)] 'sjs--meta-control- > backslash) > > =C2=A0 (abbrev-mode > 1) > =C2=A0 (setq local-abbrev-table java-mode-abbrev- > table) > > =C2=A0 (font-lock-add- > keywords > > nil > > '( > =C2=A0 =C2=A0 =C2=A0("\\<\\(assert\\|begin\\|end\\|function\\|var\\|class= Var\\| > instanceVariable\\|property\\|method\\|constructor\\|until\\|then\\|and > \\|or\\)\\>" (1 'font-lock-keyword-face nil)) > > =C2=A0 =C2=A0 =C2=A0("\\<\\(beginMain\\|endMain\\)\\>" 0 'font-lock-keywo= rd-face > nil) > > =C2=A0 =C2=A0 =C2=A0("\\<\\(null\\|true\\|false\\)\\>" 1 'font-lock-const= ant-face > nil) > > =C2=A0 =C2=A0 =C2=A0("\\<\\(abstract\\|break\\|byte\\|case\\|catch\\|clas= s\\|const\\| > continue\\|default\\|do\\|else\\|extends\\|final\\|finally\\|for\\|goto > \\|if\\|implements\\|import\\|instanceof\\|interface\\|native\\|new\\| > package\\|private\\|protected\\|public\\|return\\|static\\|super\\| > switch\\|synchronized\\|this\\|throw\\|throws\\|transient\\|try\\| > volatile\\|while\\|null\\)\\>" 1 'font-lock-keyword-face nil) > > =C2=A0 =C2=A0 =C2=A0 ("\\ function-name-face nil) > =C2=A0 =C2=A0 =C2=A0 ("\\ function-name-face nil) > > =C2=A0 =C2=A0 =C2=A0 ("\\<\\([A-Z]+[a-z][A-Za-z0-9]*\\|[A-Z]\\|boolean\\|= char\\|int\\| > long\\|short\\|float\\|double\\)[][]*[ \t]+\\([a-z][A-Za-z0-9]*\\)" > =C2=A0 =C2=A0 =C2=A0 =C2=A0(1 'font-lock-type-face > nil) > =C2=A0 =C2=A0 =C2=A0 =C2=A0(2 'font-lock-variable-name-face > nil)) > > =C2=A0 =C2=A0 =C2=A0 ("\\<[A-Z]+[a-z][A-Za-z0-9_]*" 0 'font-lock-type-fac= e > nil) > =C2=A0 =C2=A0 =C2=A0 ("\\<[A-Z]\\>" 0 'font-lock-type-face > nil) > =C2=A0 =C2=A0 =C2=A0 ("\\<\\(boolean\\|char\\|int\\|long\\|short\\|float\= \|double\\| > void\\)\\>" 0 'font-lock-type-face nil t) > > =C2=A0 =C2=A0 =C2=A0)) > > =C2=A0 (font-lock-mode > 3) > > =C2=A0 ) > > > If your comment syntax is more complex, you cannot use syntax table > > for it. You have to use font-lock-syntactic-keywords, and also you'll > > need to implement your own comment-dwim. > > =E2=80=A2 How To Add Comment Handling In Your Major Mode > > =C2=A0http://xahlee.org/emacs/elisp_comment_handling.html > > > See also Rick (rgb)'s experience, at > > > =E2=80=A2http://groups.google.com/group/gnu.emacs.help/browse_frm/threa= d/465e9... > > > =E2=80=A2http://groups.google.com/group/comp.emacs/browse_frm/thread/c1= b7de448... > > Could you give me some more information as to how to proceed. I am > stuck. i'm not expert in dealing with emacs font lock... only wrote 1 mode myself and only started to explore it in recent months. Your code is too big for me to dig into and give helpful advice. ... maybe others here can pitch in. i wouldn't inherit or call java mode though... but this may not be a expert advice. I wouldn't because unless you really need to, calling other modes esp complex mode like java, introduces a lot complexities and behaviors into your mode, which is hard to guess what's going on and you have little control. Xah =E2=88=91 http://xahlee.org/ =E2=98=84