all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tim Johnson <tim@johnsons-web.com>
Subject: Derived Mode 102 Keybindings and Menu
Date: Fri, 17 Mar 2006 22:56:33 -0000	[thread overview]
Message-ID: <slrne1me0c.o2s.tim@linus.johnson.com> (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

             reply	other threads:[~2006-03-17 22:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-17 22:56 Tim Johnson [this message]
2006-03-21 17:01 ` Derived Mode 102 Keybindings and Menu 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=slrne1me0c.o2s.tim@linus.johnson.com \
    --to=tim@johnsons-web.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.