i want to write a major mode for emacs which should do syntax highlighting for mml (music macro language) keywords. I followed this tutorial:
http://ergoemacs.org/emacs/elisp_syntax_coloring.html
here is my current code (under x-events there are still placeholders, and x-functions I haven't adjusted yet and took over from the tutorial):
;;
;; to install this mode, put the following lines
;; (add-to-list 'load-path "~/.emacs.d/lisp/")
;; (load "mml-mode.el")
;; into your init.el file and activate it with
;; ALT+X mml-mode RET
;;
;; create the list for font-lock.
;; each category of keyword is given a particular face
(setq mml-font-lock-keywords
(let* (
;; define several category of keywords
(x-keywords '("#author" "#title" "#game" "#comment"))
(x-types '("&" "?" "/" "=" "[" "]" "^" "<" ">"))
(x-constants '("w" "t" "o" "@" "v" "y" "h" "q" "p" "n" "*" "!"))
(x-events '("@" "@@" "ooo" "oooo"))
(x-functions '("llAbs" "llAcos" "llAddToLandBanList"
"llAddToLandPassList"))
;; generate regex string for each category of keywords
(x-keywords-regexp (regexp-opt x-keywords 'words))
(x-types-regexp (regexp-opt x-types 'words))
(x-constants-regexp (regexp-opt x-constants 'words))
(x-events-regexp (regexp-opt x-events 'words))
(x-functions-regexp (regexp-opt x-functions 'words)))
`(
(,x-types-regexp . font-lock-type-face)
(,x-constants-regexp . font-lock-constant-face)
(,x-events-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
)))
;;;###autoload
(define-derived-mode mml-mode text-mode "mml mode"
"Major mode for editing mml (Music Macro Language)"
;; code for syntax highlighting
(setq font-lock-defaults '((mml-font-lock-keywords))))
;; add the mode to the `features' list
(provide 'mml-mode)
But now there are two problems:
First, I have several keywords that start with a # (e.g. #author). But the # doesn't seem to work, because if I leave it out, it works.
(x-keywords '("#author"))
does not work.
(x-keywords '("author"))
works, but the # is not colored. The same problem also occurs with the @. Possibly also with others, but I'll try to get them working one by one.
second, a keyword seems to need at least two letters.
(x-keywords '("o"))
does not work.
(x-keywords '("oo"))
works.
But I have several "keywords" which are followed by only one letter and two (arbitrary) hex numbers (0-F) (e.g. o7D)
How can I specify that these one letter keywords are found? (preferably together with the number, but no must).