all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* JFlex mode for FSF-Emacs ?
@ 2003-01-22 15:24 Andreas Wieweg
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Wieweg @ 2003-01-22 15:24 UTC (permalink / raw)


Hi
The following mode only seems to work for XEmacs.
Why doesn't it work for FSF-Emacs 21.2 ?

If anybody could give me some pointers about what I
need to modify I would appreciate it very much !

Regards
/ Andreas Wieweg





; -*- Mode: Emacs-Lisp; -*-

;;;  jflex-mode

;;;  author: Gerwin Klein <lsf@jflex.de>
;;;  $Revision: 1.3 $, $Date: 2001/10/25 18:55:52 $

(require 'derived)

(define-derived-mode jflex-mode java-mode "JFlex"
  "Major mode for editing JFlex files"

  ;; set the indentation
  (setq c-basic-offset 2)

  (c-set-offset 'knr-argdecl-intro 0)
  (c-set-offset 'topmost-intro-cont 0)

  ;; remove auto and hungry anything
  (c-toggle-auto-hungry-state -1)
  (c-toggle-auto-state -1)
  (c-toggle-hungry-state -1)

  (use-local-map jflex-mode-map)

  ;; get rid of that damn electric-brace
  (define-key jflex-mode-map "{" 'self-insert-command)
  (define-key jflex-mode-map "}" 'self-insert-command)

  (define-key jflex-mode-map [tab] 'jflex-indent-command)

  )

(defalias 'jflex-indent-command 'c-indent-command)

(defconst jflex-font-lock-keywords
  (append
   '(
     ("^%%" . font-lock-reference-face)
     "^%{"
     "^%init{"
     "^%initthrow{"
     "^%eof{"
     "^%eofthrow{"
     "^%yylexthrow{"
     "^%eofval{"
     "^%}"
     "^%init}"
     "^%initthrow}"
     "^%eof}"
     "^%eofthrow}"
     "^%yylexthrow}"
     "^%eofval}"
     "^%standalone"
     "^%scanerror"
     "^%switch"
     "^%states" ; fixme: state identifiers
     "^%state"
     "^%s"
     "^%xstates"
     "^%xstate"
     "^%x"
     "^%char"
     "^%line"
     "^%column"
     "^%byaccj"
     "^%cupsym"
     "^%cupdebug"
     "^%cup"
     "^%eofclose"
     "^%class"
     "^%function"
     "^%type"
     "^%integer"
     "^%intwrap"
     "^%int"
     "^%yyeof"
     "^%notunix"
     "^%7bit"
     "^%full"
     "^%8bit"
     "^%unicode"
     "^%16bit"
     "^%caseless"
     "^%ignorecase"
     "^%implements"
     "^%extends"
     "^%public"
     "^%final"
     "^%abstract"
     "^%debug"
     "^%table"
     "^%pack"
     "^%include"
     "^%buffer"
     "^%initthrow"
     "^%eofthrow"
     "^%yylexthrow"
     "^%throws"
     ("%[%{}0-9a-zA-Z]+" . font-lock-warning-face) ; errors
     ("{[ \t]*[a-zA-Z][0-9a-zA-Z_]+[ \t]*}" . font-lock-variable-name-face)
; macro uses
     "<<EOF>>" ; special <<EOF>> symbol
     ("<[ \t]*[a-zA-Z][0-9a-zA-Z_]+[ \t]*\\(,[ \t]*[a-zA-Z][0-9a-zA-Z_]+[
\t]*\\)*>" . font-lock-type-face) ; lex state list
     )
   java-font-lock-keywords-2)
  "JFlex keywords for font-lock mode")

(put 'jflex-mode 'font-lock-defaults
  '(jflex-font-lock-keywords
    nil nil ((?_ . "w")) beginning-of-defun))

(provide 'jflex-mode)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: JFlex mode for FSF-Emacs ?
       [not found] <mailman.781.1043249234.21513.help-gnu-emacs@gnu.org>
@ 2003-01-22 16:22 ` Stefan Monnier <foo@acm.com>
  2003-01-22 19:04   ` Andreas Wieweg
       [not found]   ` <mailman.800.1043262475.21513.help-gnu-emacs@gnu.org>
  2003-01-22 20:28 ` Stefan Monnier <foo@acm.com>
  1 sibling, 2 replies; 6+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-01-22 16:22 UTC (permalink / raw)


>>>>> "Andreas" == Andreas Wieweg <andreas.wieweg@obbit.se> writes:
> Why doesn't it work for Emacs 21.2 ?

If things don't work in Emacs-21.2 it's because there's a problem.
Try to fix it and things will then work,


        Stefan


PS: of course, we could provide a more specific diagnosis if you
    could give us a more specific description of "doesn't work".

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: JFlex mode for FSF-Emacs ?
  2003-01-22 16:22 ` JFlex mode for FSF-Emacs ? Stefan Monnier <foo@acm.com>
@ 2003-01-22 19:04   ` Andreas Wieweg
       [not found]   ` <mailman.800.1043262475.21513.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Wieweg @ 2003-01-22 19:04 UTC (permalink / raw)


> >>>>> "Andreas" == Andreas Wieweg <andreas.wieweg@obbit.se> writes:
> > Why doesn't it work for Emacs 21.2 ?
>
> If things don't work in Emacs-21.2 it's because there's a problem.
> Try to fix it and things will then work,
>
> PS: of course, we could provide a more specific diagnosis if you
>     could give us a more specific description of "doesn't work".

I'm sorry. I didn't realise I didn't give enough information.


*** A try at giving a more specific description: ***
The jflex-mode should for jflex-files do:
"Syntax highlighting (with font-lock) for JFlex keywords and Java actions "

However there is almost no syntax-highligting when using FSF-Emacs, only
comments and strings are highlighted.

I thought that maybe some function/variable was used in the code,
and that it was obvious for experienced emacs-lisp users that the
function/variable was a XEmacs function/variable. But maybe it
isn't that easy and takes more time and effort.

I would like to fix it but I don't know where start looking.
So any pointers and clues about what may be wrong
(why the syntax-highlighting doesn't work) are very welcome!

Hopefully this is a somewhat more specific description
of "doesn't work" :)

Regards
/ Andreas Wieweg




*** A small example jflex file (expr.flex) ***
/* A small calculator example */

import java_cup.runtime.*;
class Yytoken extends Symbol
{
  Yytoken(int token, Object obj)
    {
      super(token,obj);
    }
  Yytoken(int token)
    {
      super(token);
    }
}

%%

%eofval {
  return (new Yytoken(sym.EOF));
%eofval }

NONNEWLINE_WHITE_SPACE_CHAR=[\ \t\b\012]
DIGIT=[0-9]
NUMBER={DIGIT}+

%%
  {NONNEWLINE_WHITE_SPACE_CHAR}+ {;}
"("                            {return new Yytoken(sym.LPAREN);}
")"                            {return new Yytoken(sym.RPAREN);}
";"                            {return new Yytoken(sym.SEMI);}
"+"                            {return new Yytoken(sym.PLUS);}
"-"                            {return new Yytoken(sym.MINUS);}
"*"                            {return new Yytoken(sym.TIMES);}
"/"                            {return new Yytoken(sym.DIVIDE);}
"%"                            {return new Yytoken(sym.MOD);}
"^"                            {return new Yytoken(sym.MACHT);}
{NUMBER}                       {return new Yytoken(sym.NUMBER,new
Integer(yytext()));}
.|\n                           {;}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: JFlex mode for FSF-Emacs ?
       [not found]   ` <mailman.800.1043262475.21513.help-gnu-emacs@gnu.org>
@ 2003-01-22 20:25     ` Stefan Monnier <foo@acm.com>
  2003-01-23  6:44       ` Andreas Wieweg
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-01-22 20:25 UTC (permalink / raw)


>>>>> "Andreas" == Andreas Wieweg <andreas.wieweg@obbit.se> writes:
> However there is almost no syntax-highligting when using FSF-Emacs, only
> comments and strings are highlighted.

Now you're talking.

> I thought that maybe some function/variable was used in the code,
> and that it was obvious for experienced emacs-lisp users that the
> function/variable was a XEmacs function/variable. But maybe it
> isn't that easy and takes more time and effort.

It's generally easier to find a bug when you know what you're looking for.
Given the lack of info, I didn't even bother to look.

Here's the problem:

XEmacs recommends to set up the font-lock info of a mode by adding
a `font-lock-defaults' property to the symbol of the major mode, as in:

   (put 'jflex-mode 'font-lock-defaults
     '(jflex-font-lock-keywords
       nil nil ((?_ . "w")) beginning-of-defun))

Instead, in Emacs, the recommended way is to set the `font-lock-defaults'
variable (buffer-locally).  So add to the definition of `jflex-mode'
(for example right after the call to `use-local-map' which you can remove
while you're at it since it's redundant):

  (set (make-local-variable 'font-lock-defaults)
       '(jflex-font-lock-keywords
         nil nil ((?_ . "w")) beginning-of-defun))

Note that XEmacs understands Emacs' way of doing things, so you can remove
the (put 'jflex-mode ...) stuff.


        Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: JFlex mode for FSF-Emacs ?
       [not found] <mailman.781.1043249234.21513.help-gnu-emacs@gnu.org>
  2003-01-22 16:22 ` JFlex mode for FSF-Emacs ? Stefan Monnier <foo@acm.com>
@ 2003-01-22 20:28 ` Stefan Monnier <foo@acm.com>
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Monnier <foo@acm.com> @ 2003-01-22 20:28 UTC (permalink / raw)


>>>>> "Andreas" == Andreas Wieweg <andreas.wieweg@obbit.se> writes:
>   (define-key jflex-mode-map [tab] 'jflex-indent-command)

Don't do that.  Instead use:

    (set (make-local-variable 'indent-line-function) 'jflex-indent-command)

but since jflex-indent-command is the same as c-indent-command and
it's already the setting of the parent mode, you might as well
not do anything at all.


        Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: JFlex mode for FSF-Emacs ?
  2003-01-22 20:25     ` Stefan Monnier <foo@acm.com>
@ 2003-01-23  6:44       ` Andreas Wieweg
  0 siblings, 0 replies; 6+ messages in thread
From: Andreas Wieweg @ 2003-01-23  6:44 UTC (permalink / raw)


Thanks for the help, it works perfectly now !

/Andreas Wieweg

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-01-23  6:44 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.781.1043249234.21513.help-gnu-emacs@gnu.org>
2003-01-22 16:22 ` JFlex mode for FSF-Emacs ? Stefan Monnier <foo@acm.com>
2003-01-22 19:04   ` Andreas Wieweg
     [not found]   ` <mailman.800.1043262475.21513.help-gnu-emacs@gnu.org>
2003-01-22 20:25     ` Stefan Monnier <foo@acm.com>
2003-01-23  6:44       ` Andreas Wieweg
2003-01-22 20:28 ` Stefan Monnier <foo@acm.com>
2003-01-22 15:24 Andreas Wieweg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.