[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Derived Mode 102 Keybindings and Menu
From: |
Tim Johnson |
Subject: |
Derived Mode 102 Keybindings and Menu |
Date: |
Fri, 17 Mar 2006 22:56:33 -0000 |
User-agent: |
slrn/0.9.8.0 (Linux) |
This is the continuation of the Derived Mode 101 HOWTO thread.
Johan and Stefan were able to help me to set up syntax highlighting.
The following file extends the derived mode by adding keymaps, bindings
and a menu.
It seems to work for me on both emacs and XEmacs. I would welcome
comments and observations. My idea for this is to then change the
substring "newlisp" to something like "dmode" and (require 'scheme)
to (require 'parent-mode) and then we would have a derived-mode template
that could be used to pretty much derive for any programming mode.
Documentary comments would also be included.
;; code follows:
(require 'scheme)
;; ==========================================================================
(defface font-lock-newlisp-keywords-face
'((((class color) (background dark)) (:foreground "yellow"))
(((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)
;; ==========================================================================
(defface font-lock-newlisp-user-keywords-face
'((((class color) (background dark)) (:foreground "red"))
(((class color) (background light)) (:foreground "darkred"))
(((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
user keywords for Newlisp programming language."
:group 'font-lock-faces)
;; ==========================================================================
(defconst
newlisp-keywords ;; just a few
(regexp-opt '(
"acos" "add" "and" "append" "append" "apply" "args" "array"
)))
;; ==========================================================================
(defconst
newlisp-user-keywords ;; just a few
(regexp-opt '(
"mysql" "oracle" "html" "gtk"
)))
;; ==========================================================================
(defvar newlisp-font-lock-keywords
`(,@scheme-font-lock-keywords
(,(concat "\\<\\(" newlisp-keywords "\\)\\>")
0 'font-lock-newlisp-keywords-face)
(,(concat "\\<\\(" newlisp-user-keywords"\\)\\>")
0 'font-lock-newlisp-user-keywords-face))
"List of newlisp keywords and faces")
;; ==========================================================================
(defun test-fun ()
"test function"
(interactive)
(message-box "OK. It works"))
;; ==========================================================================
(defvar newlisp-menu-var nil "Newlisp Menu Definition")
(defun newlisp-menu-emacs ()
"Newlisp Menu for GNU emacs"
(interactive)
(easy-menu-add-item
nil nil
(easy-menu-create-menu ;; XEmacs does not recognize
"Newlisp"
'(["Test" test-fun :active t]))))
;; ==========================================================================
(defun newlisp-menu ()
"Newlisp Menu for XEmacs"
(interactive)
(easy-menu-define
newlisp-menu-var newlisp-keymap "Newlisp Mode Menu"
'("Newlisp"
["Test" test-fun]))
(easy-menu-add-item nil nil newlisp-menu-var))
;; ==========================================================================
(defun newlisp-set-keymap ()
(defvar newlisp-keymap (make-sparse-keymap) "Newlisp mode keymap")
(defcustom newlisp-keymap-prefix [(control c) (control c)]
"*Keymap prefix string for newlisp-keymap"
:type 'string
:group 'newlisp-mode)
(local-set-key newlisp-keymap-prefix newlisp-keymap)
(define-key newlisp-keymap "b" 'test-fun))
;; ==========================================================================
(define-derived-mode newlisp-mode scheme-mode "newlisp"
"A major mode for Newlisp."
(newlisp-set-keymap)
(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"))
((?+ . "w") (?- . "w") (?* . "w")
(?/ . "w")
(?. . "w") (?< . "w") (?> . "w")
(?= . "w")
(?? . "w") (?$ . "w") (?% . "w") (?_ . "w")
(?& . "w") (?~ . "w") (?^ . "w") (?: . "w"))))))
(newlisp-menu)
(message "Newlisp Derived Mode Loaded!"))
;; end
--
Tim Johnson <tim@johnsons-web.com>
http://www.alaska-internet-solutions.com
- Derived Mode 102 Keybindings and Menu,
Tim Johnson <=