help-gnu-emacs
[Top][All Lists]
Advanced

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

Derived Mode 101 HOWTO


From: Tim Johnson
Subject: Derived Mode 101 HOWTO
Date: Mon, 06 Mar 2006 17:59:01 -0000
User-agent: slrn/0.9.8.0 (Linux)

This builds on the topic from another thread.
  "Restricting 'add-hook to a specific file extension"
Here's the goal:
  From the simple (and non-working) example using 'add-hook,
  create a derived mode using 'scheme-mode and a supporting the newlisp
  programming language which is based on lisp.
 AND
1)Add two *new* faces, one for user libraries, and another for
  multi-line strings.
2)Override two existing faces and re-populate with newlisp-specific
syntax.
3)Add a menu
4)Add keybinding.
Compatibility:
  Must be usable by both forks. Xemacs *does not* support
  font-lock-add-keywords. Must use a menuing approach compatible to both
  emacs and Xemacs.

HISTORICALLY: Much of these goals have been implemented albeit crudely, using
'font-lock-add-faces and the 'add-hook approach. Compatible to GNU emacs only.

When finished, I'll add in the keyword-based help system I've built, I'm
actually kind of proud of it. Definitely is useful.

Sample code follows. First thing to tackle is syntax highlighting. I'm
big on that 'cuz my vision sucks. 
;; Results thus far: This file is loaded without error, but
;;  The syntax highlight scheme does not work.

(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")
(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")
(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"))))
(provide 'newlisp++) ;; highlight doesn't work...

Looking forward to input.
-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com


reply via email to

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