unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Derived Mode 101 HOWTO
@ 2006-03-06 17:59 Tim Johnson
  2006-03-07 18:01 ` Stefan Monnier
  0 siblings, 1 reply; 16+ messages in thread
From: Tim Johnson @ 2006-03-06 17:59 UTC (permalink / raw)


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

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

end of thread, other threads:[~2006-03-13 23:57 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-06 17:59 Derived Mode 101 HOWTO Tim Johnson
2006-03-07 18:01 ` Stefan Monnier
2006-03-08  2:58   ` Tim Johnson
2006-03-08  5:46     ` Stefan Monnier
2006-03-08 16:58       ` Tim Johnson
2006-03-11 17:15         ` Stefan Monnier
2006-03-12  0:57           ` Tim Johnson
2006-03-12 13:49             ` Stefan Monnier
2006-03-13  1:48               ` Tim Johnson
2006-03-13 10:10                 ` Johan Bockgård
2006-03-13 17:57                   ` Tim Johnson
2006-03-13 21:35                     ` Johan Bockgård
2006-03-13 23:57                       ` Tim Johnson
2006-03-12  5:29     ` Johan Bockgård
2006-03-12 17:50       ` Tim Johnson
2006-03-12 18:14         ` Johan Bockgård

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).