From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim Johnson Newsgroups: gmane.emacs.help Subject: Derived Mode 102 Keybindings and Menu Date: Fri, 17 Mar 2006 22:56:33 -0000 Organization: Alaska Internet Solutions Message-ID: Reply-To: tim@johnsons-web.com NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1142638832 15065 80.91.229.2 (17 Mar 2006 23:40:32 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 17 Mar 2006 23:40:32 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 18 00:40:31 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FKOYV-0000mb-M6 for geh-help-gnu-emacs@m.gmane.org; Sat, 18 Mar 2006 00:40:27 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FKOYV-0002qL-4D for geh-help-gnu-emacs@m.gmane.org; Fri, 17 Mar 2006 18:40:27 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!sn-xt-sjc-03!sn-xt-sjc-08!sn-post-01!supernews.com!news.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: slrn/0.9.8.0 (Linux) Original-X-Complaints-To: abuse@supernews.com Original-Lines: 109 Original-Xref: shelby.stanford.edu gnu.emacs.help:138249 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:33868 Archived-At: 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 http://www.alaska-internet-solutions.com