lilypond-1.1.5
[lilypond.git] / mudela-mode.el
blob2bbc8bbddc35a8a9a2f768aba18d3d87a3d36c64
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 (concat ".\\(" kwregex "\\)[^a-zA-Z]")
48 (concat "^\\(" kwregex "\\)[^a-zA-Z]")
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-blank-or-comment-re "[ \t]*\\($\\|%\\)"
122 "Regexp matching blank or comment lines.")
124 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
125 "Regexp matching Identifier definitions.")
127 ;; Sadly we need this for a macro in Emacs 19.
128 (eval-when-compile
129 ;; Imenu isn't used in XEmacs, so just ignore load errors.
130 (condition-case ()
131 (require 'imenu)
132 (error nil)))
134 (defvar mu-imenu-generic-expression
135 (list (list nil mu-imenu-generic-re 1))
136 "Expression for imenu")
138 (defun mudela-mode ()
139 "Major mode for editing Mudela files."
141 (interactive)
142 ;; set up local variables
143 (kill-all-local-variables)
144 (make-local-variable 'font-lock-defaults)
145 (make-local-variable 'paragraph-separate)
146 (make-local-variable 'paragraph-start)
147 (make-local-variable 'require-final-newline)
148 (make-local-variable 'comment-start)
149 (make-local-variable 'block-comment-start)
150 (make-local-variable 'block-comment-end)
152 (setq comment-end "\n"
153 comment-start "%"
154 comment-start-skip "%{? *"
155 block-comment-start "%{"
156 block-comment-end "%}"
158 (make-local-variable 'comment-end)
159 (make-local-variable 'comment-start-skip)
160 (setf comment-start-skip "%{")
161 (make-local-variable 'comment-column)
162 (make-local-variable 'imenu-generic-expression)
163 (setq imenu-generic-expression mu-imenu-generic-expression)
164 (make-local-variable 'indent-line-function)
167 (set-syntax-table mu-mode-syntax-table)
168 (setq major-mode 'mudela-mode
169 mode-name "Mudela"
170 local-abbrev-table mudela-mode-abbrev-table
171 font-lock-defaults '(mudela-font-lock-keywords)
172 paragraph-separate "^[ \t]*$"
173 paragraph-start "^[ \t]*$"
174 require-final-newline t
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 (run-hooks 'mudela-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