all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Oliver Scholz <alkibiades@gmx.de>
Subject: Re: How do I do syntax highlighting when writing a major mode
Date: Fri, 23 May 2003 19:07:05 +0200	[thread overview]
Message-ID: <uznldbnie.fsf@ID-87814.user.dfncis.de> (raw)
In-Reply-To: mailman.6644.1053703895.21513.help-gnu-emacs@gnu.org

"John Massingham" <johnm@tensilica.com> writes:

[...]
> If I am going to be flamed please do it quickly....

Ts, ts, are we monsters? :-)

[...]
> I have a number of key words (equivilent to int / char / etc) and it is quite
> a limited list

[keywords]  

> These I can search for and set in the keyword face but I am unsure
> how to find the second word, whatever it may be, and I obviously
> dont want to highlight every second word!!

You can use subexpressions for this. Group parts of your regexp with
"\\(" and "\\)" and reference them by number (0 stands for the whole
expression).

(defvar jm-example-font-lock-keywords
  '(("\\(\\<iclass\\>\\)\\s-+\\([[:alnum:]]+\\)?" 
     (1 font-lock-keyword-face)
     (2 font-lock-function-name-face))))

(define-derived-mode jm-example-mode text-mode "EXAMPLE"
  "Major mode to demonstrate & test font-lock-keywords."
  (setq font-lock-defaults '(jm-example-font-lock-keywords)))

[...]
> I dont know lisp, I am just hacking about, looking at various modes,
> perl, make, etc and cutting and pasting untill it seems to work!
> However I suspec a syntax table or something has to be built up but
> with my lack of lisp knowledge I cant follow whats actually going on

Have a look at some web ressources for writing major modes:

    - Tutorial
      http://two-wugs.net/emacs/mode-tutorial.html

    - Generic mode: for simple modes
      http://www.emacswiki.org/cgi-bin/wiki.pl?GenericMode

    - derived modes
      http://www.emacswiki.org/cgi-bin/wiki.pl?DerivedMode

[...]
> ;; Here we define some variables that all major modes should define
> ;;
> (defvar tie-mode-hook nil)
> (defvar tie-mode-map  nil
>   "Keymap for TIE major mode")

> ;; Here we're defining a default keymap if the user doesn't already have one
> ;;
> (if tie-mode-map nil
>   (setq tie-mode-map (make-keymap)))

(defvar tie-mode-map (make-keymap))

Or (if you are going to define something in it):

(defvar tie-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map ....)
    (define-key map ....)
    ...
    map)
  "Keymap for TIE major mode")


  
[...]
> ;;
> ;; And now to launch the major mode....
> ;;
> (defun tie-mode ()
>   "Major mode for editing TIE files."
>   (interactive)
>   (kill-all-local-variables)
>   (make-local-variable 'font-lock-defaults)
>   (setq font-lock-defaults
>  '(tie-font-lock-keywords))
>
>  
>
>   (setq major-mode 'tie-mode)
>   (setq mode-name "Tie")
>   (run-hooks 'tie-mode-hooks))
[...]

(define-derived-mode tie-mode fundamental-mode "TIE"
  "Major mode for editing TIE files."
  (setq font-lock-defaults '(tie-font-lock-keywords)))

    Oliver
-- 
4 Prairial an 211 de la Révolution
Liberté, Egalité, Fraternité!

       reply	other threads:[~2003-05-23 17:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6644.1053703895.21513.help-gnu-emacs@gnu.org>
2003-05-23 17:07 ` Oliver Scholz [this message]
2003-05-23 15:04 How do I do syntax highlighting when writing a major mode John Massingham

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=uznldbnie.fsf@ID-87814.user.dfncis.de \
    --to=alkibiades@gmx.de \
    /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.