lilypond-1.0.13
[lilypond.git] / mudela-mode.el
blob53c8104d9340f9350119efdef99726df1fa6b942
1 ;;; mudela-mode.el --- Major mode for editing Mudela programs
4 ;; Copyright (C) 1992,1993,1994 Tim Peters
6 ;; Author: 1997: Han-Wen Nienhuys
7 ;; Author: 1995-1996 Barry A. Warsaw
8 ;; 1992-1994 Tim Peters
9 ;; Created: Feb 1992
10 ;; Version: 0.0
11 ;; Last Modified: 12SEP97
12 ;; Keywords: mudela languages music
14 ;; This software is provided as-is, without express or implied
15 ;; warranty. Permission to use, copy, modify, distribute or sell this
16 ;; software, without fee, for any purpose and by any individual or
17 ;; organization, is hereby granted, provided that the above copyright
18 ;; notice and this paragraph appear in all copies.
22 ;; Kyrie Eleison; it is my first real Elisp file
23 ;; This is a cannabalised version of python-mode.el (HWN)
25 ;; TODO:
26 ;; * should handle block comments too.
27 ;; * handle lexer modes (\header, \melodic, \lyric) etc.
28 ;; * indentation
29 ;; * notenames?
30 ;; * fontlock: \melodic \melodic
31 ;;
33 (defconst mudela-font-lock-keywords
34 (let* ((keywords '(
35 "accepts" "accidentals" "break" "bar" "cadenza"
36 "clef" "cm" "consists" "contains" "duration" "absdynamic"
37 "in" "translator" "type" "lyric" "key" "maininput" "notes"
38 "musical_pitch" "time" "midi" "mm" "header"
39 "notenames" "octave" "output" "partial" "paper" "plet"
40 "property" "pt" "shape" "relative" "include" "score"
41 "script" "skip" "table" "spandynamic" "symboltables"
42 "tempo" "texid" "textstyle" "transpose" "version" "grouping"
44 (kwregex (mapconcat (lambda (x) (concat "\\\\" x)) keywords "\\|")))
46 (list
47 (cons (concat ".\\(" kwregex "\\)[^a-zA-Z]") 1)
48 (cons (concat "^\\(" kwregex "\\)[^a-zA-Z]") 1)
49 '(".\\(\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-variable-name-face)
50 '("^[\t ]*\\([a-zA-Z][_a-zA-Z]*\\) *=" 1 font-lock-variable-name-face)
52 "Additional expressions to highlight in Mudela mode.")
54 ;; define a mode-specific abbrev table for those who use such things
55 (defvar mudela-mode-abbrev-table nil
56 "Abbrev table in use in `mudela-mode' buffers.")
58 (define-abbrev-table 'mudela-mode-abbrev-table nil)
60 (defvar mudela-mode-hook nil
61 "*Hook called by `mudela-mode'.")
63 (defvar mu-mode-map ()
64 "Keymap used in `mudela-mode' buffers.")
66 (defun mu-newline-and-indent ()
67 (interactive)
68 (newline)
69 (indent-relative-maybe)
70 "Newline and copy previous indentation")
72 (if mu-mode-map
74 (setq mu-mode-map (make-sparse-keymap))
76 (mapcar (function (lambda (key)
77 (define-key
78 mu-mode-map key 'mu-newline-and-indent)))
79 (where-is-internal 'newline-and-indent))
81 (mapcar (function
82 (lambda (x)
83 (define-key mu-mode-map (car x) (cdr x))))
84 '(("\C-c\C-c" . mu-foo-bar)
86 ;; should do all keybindings this way
87 (define-key mu-mode-map [RET] 'mu-newline-and-indent)
90 (defvar mu-mode-syntax-table nil
91 "Syntax table used in `mudela-mode' buffers.")
94 (if mu-mode-syntax-table
96 (setq mu-mode-syntax-table (make-syntax-table))
97 (mapcar (function
98 (lambda (x) (modify-syntax-entry
99 (car x) (cdr x) mu-mode-syntax-table)))
100 '(( ?\( . "()" ) ( ?\) . ")(" )
101 ( ?\[ . "(]" ) ( ?\] . ")[" )
102 ( ?\{ . "(}" ) ( ?\} . "){" )
103 ( ?\< . "(>" )( ?\> . ")>")
104 ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
105 ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." )
106 ( ?\/ . "." ) ( ?\= . "." )
107 ( ?\| . "." ) (?\\ . "\\" )
108 ( ?\_ . "." )
109 ( ?\' . "w")
110 ( ?\" . "\"" )
111 ( ?\% . "<")
112 ( ?\n . ">")
114 ; FIXME
115 ; ( ?% . ". 124b" )
116 ; ( ?{ . ". 23" )
121 (defconst mu-stringlit-re
122 "\"\\([^\"\n\\]\\|\\\\.\\)*\"" ; double-quoted
123 "Regexp matching a Mudela string literal.")
126 (defconst mu-blank-or-comment-re "[ \t]*\\($\\|%\\)"
127 "Regexp matching blank or comment lines.")
129 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
130 "Regexp matching Identifier definitions.")
132 ;; Sadly we need this for a macro in Emacs 19.
133 (eval-when-compile
134 ;; Imenu isn't used in XEmacs, so just ignore load errors.
135 (condition-case ()
136 (require 'imenu)
137 (error nil)))
139 (defvar mu-imenu-generic-expression
140 (list (list nil mu-imenu-generic-re 1))
141 "Expression for imenu")
143 (defun mudela-mode ()
144 "Major mode for editing Mudela files."
146 (interactive)
147 ;; set up local variables
148 (kill-all-local-variables)
149 (make-local-variable 'font-lock-defaults)
150 (make-local-variable 'paragraph-separate)
151 (make-local-variable 'paragraph-start)
152 (make-local-variable 'require-final-newline)
153 (make-local-variable 'comment-start)
154 (setq comment-start "% ")
155 (setq comment-end "")
156 (make-local-variable 'comment-end)
157 (make-local-variable 'comment-start-skip)
158 (setf comment-start-skip "%{")
159 (make-local-variable 'comment-column)
160 (make-local-variable 'imenu-generic-expression)
161 (setq imenu-generic-expression mu-imenu-generic-expression)
162 (make-local-variable 'indent-line-function)
165 (set-syntax-table mu-mode-syntax-table)
166 (setq major-mode 'mudela-mode
167 mode-name "Mudela"
168 local-abbrev-table mudela-mode-abbrev-table
169 font-lock-defaults '(mudela-font-lock-keywords)
170 paragraph-separate "^[ \t]*$"
171 paragraph-start "^[ \t]*$"
172 require-final-newline t
173 comment-start "% "
174 comment-start-skip "% *"
175 comment-column 40
176 indent-line-function 'indent-relative-maybe
178 (use-local-map mu-mode-map)
180 ;; run the mode hook. mu-mode-hook use is deprecated
181 (if mudela-mode-hook
182 (run-hooks 'mudela-mode-hook)
183 (run-hooks 'mu-mode-hook)))
185 (defun mu-keep-region-active ()
186 ;; do whatever is necessary to keep the region active in XEmacs.
187 ;; Ignore byte-compiler warnings you might see. Also note that
188 ;; FSF's Emacs 19 does it differently and doesn't its policy doesn't
189 ;; require us to take explicit action.
190 (and (boundp 'zmacs-region-stays)
191 (setq zmacs-region-stays t)))
194 (defun mu-comment-region (beg end &optional arg)
195 "Like `comment-region' but uses double hash (`#') comment starter."
196 (interactive "r\nP")
197 (let ((comment-start mu-block-comment-prefix))
198 (comment-region beg end arg)))
200 (defconst mu-version "0.0.1"
201 "`mudela-mode' version number.")
202 (defconst mu-help-address "hanwen@cs.uu.nl"
203 "Address accepting submission of bug reports.")
205 (defun mu-version ()
206 "Echo the current version of `mudela-mode' in the minibuffer."
207 (interactive)
208 (message "Using `mudela-mode' version %s" mu-version)
209 (mu-keep-region-active))
211 (provide 'mu-mode)
212 ;;; mudela-mode.el ends here