unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* write your own emacs mode
@ 2003-12-15 10:06 Joerg Schuster
  2003-12-15 12:37 ` Jesper Harder
  0 siblings, 1 reply; 7+ messages in thread
From: Joerg Schuster @ 2003-12-15 10:06 UTC (permalink / raw)


Hello,

I "wrote" (i.e. copied and manipulated) an emacs mode with the help of
the following site:

http://www.emacswiki.org/cgi-bin/wiki.pl/GenericMode

My mode is called grammar-mode, because I use it for editing linguistic
grammars of a certain type. grammar-mode works fine except for one
thing: It uses to mark strings of a certain form as expressions of
type X, although I did not define type X anywhere in the code of
grammar-mode. (Example: Strings that are enclosed in quotes are
displayed with font-lock-string-face. Yet, in the type of files which
I use grammar-mode for, strings of the form '^".*"$' are not
wellformed expressions of any type.) How can I prevent this?

Another question: Is there a (not too complicated) way to replace the
face names like "font-lock-type-face" and so on by more direct
descriptions of the face (e.g. "blue")?

Jörg



;;;;; Here is the code ;;;;;;;;;;;;

;; grammar-mode
(define-generic-mode 'grammar-mode
  '("%")
  '("adj" "adj4" "adj5" "adjB" "adjb" "adjc" 
    "adjs" "adv" "advb" "advc" "advs" "advv" 
    "advw" "be" "cnj" "cnjK" "cnjS" "det" "deto" 
    "detw" "en" "eng" "have" "infp" "intj" "n" 
    "n4" "ne" "nem" "ng" "nm" "prep" "pron" 
    "pronj" "pronl" "prono" "pronq" "pronw" 
    "tok" "v" "vC" "vD" "vG" "vG3e" "vI" "vP" 
    "vV")
  nil
  '(".syn$")
  nil
  "Major mode for editing grammar files as used by pm and skonk.")

(defvar grammar-mode-keywords
  '(("[A-Z][^ ]*" . font-lock-type-face)                ; syntactic category
    ("=[a-zA-Z0-9]+" . font-lock-string-face)           ; surface form
    ("_[a-zA-Z0-9]+" . font-lock-string-face)           ; base form
    ("\\^[a-zA-Z0-9]+" . font-lock-string-face)         ; semantic category
    ("[\*\+\?]" . font-lock-function-name-face)         ; *,+,?
    (":" . font-lock-warning-face)))                    ; head symbol

(font-lock-add-keywords 'grammar-mode syntax-mode-keywords)

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

* Re: write your own emacs mode
  2003-12-15 10:06 write your own emacs mode Joerg Schuster
@ 2003-12-15 12:37 ` Jesper Harder
  2003-12-16 10:05   ` Joerg Schuster
  2003-12-16 13:51   ` F. Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Jesper Harder @ 2003-12-15 12:37 UTC (permalink / raw)


Joerg Schuster <js@cis.uni-muenchen.de> writes:

> grammar-mode works fine except for one thing: It uses to mark
> strings of a certain form as expressions of type X, although I did
> not define type X anywhere in the code of grammar-mode. (Example:
> Strings that are enclosed in quotes are displayed with
> font-lock-string-face. Yet, in the type of files which I use
> grammar-mode for, strings of the form '^".*"$' are not wellformed
> expressions of any type.) How can I prevent this?

This is called syntactic fontification -- as opposed to keyword
fontification.

You can either turn of syntactic fontification in your mode (this will
also inhibit font locking of comments) or modify the syntax table of
the mode.

> Another question: Is there a (not too complicated) way to replace
> the face names like "font-lock-type-face" and so on by more direct
> descriptions of the face (e.g. "blue")?

I think the cleanest way is to define new faces for the mode with
`defface'.

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

* Re: write your own emacs mode
  2003-12-15 12:37 ` Jesper Harder
@ 2003-12-16 10:05   ` Joerg Schuster
  2003-12-16 12:37     ` Jesper Harder
  2003-12-16 13:51   ` F. Schaefer
  1 sibling, 1 reply; 7+ messages in thread
From: Joerg Schuster @ 2003-12-16 10:05 UTC (permalink / raw)


Jesper Harder <harder@myrealbox.com> writes:

> You can either turn of syntactic fontification in your mode (this will
> also inhibit font locking of comments) or modify the syntax table of
> the mode.

I tried to do this. But I don't quite understand the relation of
modify-syntax-entry and define-generic-mode. 

Does the meaning of the regexes (like in ;;1) depend on the 
syntax-table? 

Why do the regexes ;;a and ;;b match parts of the same "word" (where
word is any string that doesn't contain \s characters)? 

According to C-h f define-generic-modeI, ;;2 is a FUNCTION-LIST
argument. Why isn't it possible to write '((modify-syntax-entry ?/
"w")) at this place?


Jörg


;; grammar-mode
(define-generic-mode 'grammar-mode
  '("%")
  '(
    "adj"
    "adj4"
    "adj5"
    )
  '(                                                                  ;;1
    ("\\([\\*\\+\\?]\\)"          1 'font-lock-function-name-face)
    ("\\([:]\\)"                  1 'font-lock-warning-face)
    ("\\(/[^\\s]+\\)"             1 'font-lock-string-face)           ;;a
    ("\\([A-Z][A-Za-z0-9]*\\)"    1 'font-lock-type-face)             ;;b
    )
  '("\\.syn\\'")
  nil                                                                 ;;2
  "Major mode for editing grammar files as used by pm and skonk.")

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

* Re: write your own emacs mode
  2003-12-16 10:05   ` Joerg Schuster
@ 2003-12-16 12:37     ` Jesper Harder
  2003-12-16 13:06       ` Joerg Schuster
  0 siblings, 1 reply; 7+ messages in thread
From: Jesper Harder @ 2003-12-16 12:37 UTC (permalink / raw)


Joerg Schuster <js@cis.uni-muenchen.de> writes:

> Jesper Harder <harder@myrealbox.com> writes:
>
>> You can either turn of syntactic fontification in your mode (this
>> will also inhibit font locking of comments) or modify the syntax
>> table of the mode.
>
> Does the meaning of the regexes (like in ;;1) depend on the
> syntax-table?

I don't think any of your _specific_ regexps depend on the syntax.

But in general regexps can depend on the syntax table since we have
backlash constructs such as \w which matches characters with
word-constituent syntax, or \b which matches the beginning or end of a
word.

> Why do the regexes ;;a and ;;b match parts of the same "word" (where
> word is any string that doesn't contain \s characters)? 

I'm not quite sure about what you intend to do.  But I'll recommend
the very handy tool `M-x re-builder' for crafting some suitable
regexps.

> According to C-h f define-generic-modeI, ;;2 is a FUNCTION-LIST
> argument. Why isn't it possible to write '((modify-syntax-entry ?/
> "w")) at this place?

(modify-syntax-entry ...) is a function call, not a function.  You
can use something like:

    '((lambda () (modify-syntax-entry ?\" "w")))

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

* Re: write your own emacs mode
  2003-12-16 12:37     ` Jesper Harder
@ 2003-12-16 13:06       ` Joerg Schuster
  0 siblings, 0 replies; 7+ messages in thread
From: Joerg Schuster @ 2003-12-16 13:06 UTC (permalink / raw)


Jesper Harder <harder@myrealbox.com> writes:

> I'm not quite sure about what you intend to do.  But I'll recommend
> the very handy tool `M-x re-builder' for crafting some suitable
> regexps.

Thanks a lot. It turned out that my problems had a really trivial
reason: I wasn't aware of some differences between Emacs regexps and
other regexps. I had often used those parts of Emacs regexps that are
like python or perl regexps before and so it didn't occur to me that
this could be the point.

> (modify-syntax-entry ...) is a function call, not a function.  You
> can use something like:
> 
>     '((lambda () (modify-syntax-entry ?\" "w")))

I see. Thanks. 

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

* Re: write your own emacs mode
  2003-12-15 12:37 ` Jesper Harder
  2003-12-16 10:05   ` Joerg Schuster
@ 2003-12-16 13:51   ` F. Schaefer
  2003-12-16 14:21     ` Joerg Schuster
  1 sibling, 1 reply; 7+ messages in thread
From: F. Schaefer @ 2003-12-16 13:51 UTC (permalink / raw)


Since you're talking about it: I need to get 
brackets such as ')' and a '|' at the beginning
or end of a pattern in generic mode. This never
works well. I used the "\b" but that did not 
serve any purpose.

Regards,

Frank.

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

* Re: write your own emacs mode
  2003-12-16 13:51   ` F. Schaefer
@ 2003-12-16 14:21     ` Joerg Schuster
  0 siblings, 0 replies; 7+ messages in thread
From: Joerg Schuster @ 2003-12-16 14:21 UTC (permalink / raw)


drfransch@netscape.net (F. Schaefer) writes:

> Since you're talking about it: I need to get 
> brackets such as ')' and a '|' at the beginning
> or end of a pattern in generic mode. 

I am not sure if I really understand what you want, but the following
expression matches expressions that are surrounded by '(' and ')'.


"\\(\([^\)]*\)\\)"

Mode:

(define-generic-mode 'test-mode
  '("%")
  nil
  '(
    ("\\(\([^\)]*\)\\)"  1 'font-lock-warning-face)   ; bracketed expression
    )
  nil
  nil
  "Mode for testing mode definitions.")

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

end of thread, other threads:[~2003-12-16 14:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-15 10:06 write your own emacs mode Joerg Schuster
2003-12-15 12:37 ` Jesper Harder
2003-12-16 10:05   ` Joerg Schuster
2003-12-16 12:37     ` Jesper Harder
2003-12-16 13:06       ` Joerg Schuster
2003-12-16 13:51   ` F. Schaefer
2003-12-16 14:21     ` Joerg Schuster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).