[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Derived Mode 101 HOWTO

From: Stefan Monnier
Subject: Re: Derived Mode 101 HOWTO
Date: Tue, 07 Mar 2006 13:01:02 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Place at the beginning of your newlisp.el file:

  (require 'scheme)

> (defface font-lock-newlisp-keywords-face
>   '((((class color) (background dark)) (:foreground "tan"))
>     (((class color) (background light)) (:foreground "green4"))
>     (((class grayscale) (background light)) (:foreground "DimGray" :italic t))
>     (((class grayscale) (background dark)) (:foreground "LightGray" :italic 
> t))
>     (t (:bold t)))
>   "Font Lock mode face used to highlight 
>    keywords for Newlisp programming language."
>   :group 'font-lock-faces)
> (defvar font-lock-newlisp-keywords-face 'font-lock-newlisp-keywords-face)
> (defconst word-begin "\\b\\(")
> (defconst word-end "\\)\\b")

Every global name you define should use the "newlisp-" prefix.

> (defconst 
>   newlisp-keywords ;; just a few
>    (regexp-opt '( 
>     "acos" "add" "and" "append" "append" "apply" "args" "array"
>     ) ) )

> (defvar newlisp-font-lock-keywords nil "List of newlisp keywords and faces")

Initialize it directly:

  (defvar newlisp-font-lock-keywords
      (,(concat "\\<\\(" newlisp-keywords "\\)\\>")
       . font-lock-newlisp-keywords-face))
    "List of newlisp keywords and faces")

> (add-hook 'scheme-mode-hook
>       (lambda ()
>        (progn
>         (require 'font-lock)
>         (setq newlisp-font-lock-keywords
>           (list
>             '((concat word-begin newlisp-keywords word-end)
>               font-lock-newlisp-keywords-face )
>             ))
>         (setq scheme-font-lock-keywords
>           (append scheme-font-lock-keywords newlisp-font-lock-keywords))
>         (message "Newlisp extensions added for Xemacs"))))

Replace by define-derived-mode:

  (define-derived-mode newlisp-mode scheme-mode "Newlisp"
    "A major mode for Newlisp."
    (set (make-local-variable 'font-lock-defaults)
         (cons newlisp-font-lock-keywords
               ;; Copy the rest of font-lock-defaults from
               ;; scheme-mode if available.
               (or (cdr font-lock-defaults)
                   '(nil t (("+-*/.<>=!?$%_&~^:" . "w")))))))

Also check (again?) sample-mode.el.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]