all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Derived Mode 102 Keybindings and Menu
@ 2006-03-17 22:56 Tim Johnson
  2006-03-21 17:01 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Tim Johnson @ 2006-03-17 22:56 UTC (permalink / raw)


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

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

end of thread, other threads:[~2006-03-22  3:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-17 22:56 Derived Mode 102 Keybindings and Menu Tim Johnson
2006-03-21 17:01 ` Stefan Monnier
2006-03-21 20:55   ` Tim Johnson
2006-03-21 22:13     ` Stefan Monnier
2006-03-22  1:55       ` Tim Johnson
2006-03-22  3:55         ` Tim Johnson

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.