lilypond-1.1.10
[lilypond.git] / mudela-mode.el
blob3d949865fa6896660b4ce412b3aba2243036780a
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 "scm" "scmfile"
42 "script" "skip" "table" "times" "spandynamic" "symboltables"
43 "tempo" "texid" "textstyle" "transpose" "version" "grouping"
45 (kwregex (mapconcat (lambda (x) (concat "\\\\" x)) keywords "\\|")))
47 (list
48 (concat ".\\(" kwregex "\\)[^a-zA-Z]")
49 (concat "^\\(" kwregex "\\)[^a-zA-Z]")
50 '(".\\(\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-variable-name-face)
51 '("^[\t ]*\\([a-zA-Z][_a-zA-Z]*\\) *=" 1 font-lock-variable-name-face)
53 "Additional expressions to highlight in Mudela mode.")
55 ;; define a mode-specific abbrev table for those who use such things
56 (defvar mudela-mode-abbrev-table nil
57 "Abbrev table in use in `mudela-mode' buffers.")
59 (define-abbrev-table 'mudela-mode-abbrev-table nil)
61 (defvar mudela-mode-hook nil
62 "*Hook called by `mudela-mode'.")
64 (defvar mu-mode-map ()
65 "Keymap used in `mudela-mode' buffers.")
67 (defun mu-newline-and-indent ()
68 (interactive)
69 (newline)
70 (indent-relative-maybe)
71 "Newline and copy previous indentation")
73 (if mu-mode-map
75 (setq mu-mode-map (make-sparse-keymap))
77 (mapcar (function (lambda (key)
78 (define-key
79 mu-mode-map key 'mu-newline-and-indent)))
80 (where-is-internal 'newline-and-indent))
82 (mapcar (function
83 (lambda (x)
84 (define-key mu-mode-map (car x) (cdr x))))
85 '(("\C-c\C-c" . mu-foo-bar)
87 ;; should do all keybindings this way
88 (define-key mu-mode-map [RET] 'mu-newline-and-indent)
91 (defvar mu-mode-syntax-table nil
92 "Syntax table used in `mudela-mode' buffers.")
95 (if mu-mode-syntax-table
97 (setq mu-mode-syntax-table (make-syntax-table))
98 (mapcar (function
99 (lambda (x) (modify-syntax-entry
100 (car x) (cdr x) mu-mode-syntax-table)))
101 '(( ?\( . "." ) ( ?\) . "." )
102 ( ?\[ . "." ) ( ?\] . "." )
103 ( ?\{ . "(}" ) ( ?\} . "){" )
104 ( ?\< . "(>" )( ?\> . ")>")
105 ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
106 ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." )
107 ( ?\/ . "." ) ( ?\= . "." )
108 ( ?\| . "." ) (?\\ . "\\" )
109 ( ?\_ . "." )
110 ( ?\' . "w")
111 ( ?\" . "\"" )
112 ( ?\% . "<")
113 ( ?\n . ">")
115 ; FIXME
116 ; ( ?% . ". 124b" )
117 ; ( ?{ . ". 23" )
122 (defconst mu-blank-or-comment-re "[ \t]*\\($\\|%\\)"
123 "Regexp matching blank or comment lines.")
125 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
126 "Regexp matching Identifier definitions.")
128 ;; Sadly we need this for a macro in Emacs 19.
129 (eval-when-compile
130 ;; Imenu isn't used in XEmacs, so just ignore load errors.
131 (condition-case ()
132 (require 'imenu)
133 (error nil)))
135 (defvar mu-imenu-generic-expression
136 (list (list nil mu-imenu-generic-re 1))
137 "Expression for imenu")
139 (defun mudela-mode ()
140 "Major mode for editing Mudela files."
142 (interactive)
143 ;; set up local variables
144 (kill-all-local-variables)
145 (make-local-variable 'font-lock-defaults)
146 (make-local-variable 'paragraph-separate)
147 (make-local-variable 'paragraph-start)
148 (make-local-variable 'require-final-newline)
149 (make-local-variable 'comment-start)
150 (make-local-variable 'block-comment-start)
151 (make-local-variable 'block-comment-end)
153 (setq comment-end "\n"
154 comment-start "%"
155 comment-start-skip "%{? *"
156 block-comment-start "%{"
157 block-comment-end "%}"
159 (make-local-variable 'comment-end)
160 (make-local-variable 'comment-start-skip)
161 (setf comment-start-skip "%{")
162 (make-local-variable 'comment-column)
163 (make-local-variable 'imenu-generic-expression)
164 (setq imenu-generic-expression mu-imenu-generic-expression)
165 (make-local-variable 'indent-line-function)
168 (set-syntax-table mu-mode-syntax-table)
169 (setq major-mode 'mudela-mode
170 mode-name "Mudela"
171 local-abbrev-table mudela-mode-abbrev-table
172 font-lock-defaults '(mudela-font-lock-keywords)
173 paragraph-separate "^[ \t]*$"
174 paragraph-start "^[ \t]*$"
175 require-final-newline t
176 comment-column 40
177 indent-line-function 'indent-relative-maybe
179 (use-local-map mu-mode-map)
181 ;; run the mode hook. mu-mode-hook use is deprecated
182 (run-hooks 'mudela-mode-hook)
186 (defun mu-keep-region-active ()
187 ;; do whatever is necessary to keep the region active in XEmacs.
188 ;; Ignore byte-compiler warnings you might see. Also note that
189 ;; FSF's Emacs 19 does it differently and doesn't its policy doesn't
190 ;; require us to take explicit action.
191 (and (boundp 'zmacs-region-stays)
192 (setq zmacs-region-stays t)))
195 (defun mu-comment-region (beg end &optional arg)
196 "Like `comment-region' but uses double hash (`#') comment starter."
197 (interactive "r\nP")
198 (let ((comment-start mu-block-comment-prefix))
199 (comment-region beg end arg)))
201 (defconst mu-version "0.0.1"
202 "`mudela-mode' version number.")
203 (defconst mu-help-address "hanwen@cs.uu.nl"
204 "Address accepting submission of bug reports.")
206 (defun mu-version ()
207 "Echo the current version of `mudela-mode' in the minibuffer."
208 (interactive)
209 (message "Using `mudela-mode' version %s" mu-version)
210 (mu-keep-region-active))
212 (provide 'mu-mode)
213 ;;; mudela-mode.el ends here