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
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)
26 ;; * should handle block comments too.
27 ;; * handle lexer modes (\header, \melodic, \lyric) etc.
30 ;; * fontlock: \melodic \melodic
33 (defconst mu-version
"1.2.16-dk1"
34 "`mudela-mode' version number.")
36 (defconst mu-help-address
"hanwen@cs.uu.nl"
37 "Address accepting submission of bug reports.")
39 (defconst mudela-font-lock-keywords
40 (let* ((keywords '("spanrequest" "simultaneous" "sequential" "accepts"
41 "alternative" "bar" "breathe"
42 "cadenza" "chordmodifiers" "chords" "clef" "cm" "consists"
43 "consistsend" "context"
44 "duration" "font" "grace" "header" "in" "lyrics"
45 "key" "keysignature" "mark" "musicalpitch"
46 "time" "times" "midi" "mm" "name" "notenames"
47 "notes" "partial" "paper" "penalty" "property" "pt"
48 "relative" "remove" "repeat" "repetitions" "addlyrics"
49 "scm" "scmfile" "score" "script"
50 "shape" "skip" "textscript" "tempo" "translator" "transpose"
53 (kwregex (mapconcat (lambda (x) (concat "\\\\" x
)) keywords
"\\|")))
56 (concat ".\\(" kwregex
"\\)[^a-zA-Z]")
57 (concat "^\\(" kwregex
"\\)[^a-zA-Z]")
58 '(".\\(\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-variable-name-face
)
59 '("^[\t ]*\\([a-zA-Z][_a-zA-Z]*\\) *=" 1 font-lock-variable-name-face
)
61 "Additional expressions to highlight in Mudela mode.")
63 ;; define a mode-specific abbrev table for those who use such things
64 (defvar mudela-mode-abbrev-table nil
65 "Abbrev table in use in `mudela-mode' buffers.")
67 (define-abbrev-table 'mudela-mode-abbrev-table nil
)
69 (defvar mudela-mode-hook nil
70 "*Hook called by `mudela-mode'.")
72 (defvar mu-mode-map
()
73 "Keymap used in `mudela-mode' buffers.")
77 (setq mu-mode-map
(make-sparse-keymap))
78 ;; (define-key mu-mode-map "\C-c\C-c" 'mu-foo-bar)
81 (defvar mu-mode-syntax-table nil
82 "Syntax table used in `mudela-mode' buffers.")
85 (if mu-mode-syntax-table
87 (setq mu-mode-syntax-table
(make-syntax-table))
89 (lambda (x) (modify-syntax-entry
90 (car x
) (cdr x
) mu-mode-syntax-table
)))
91 '(( ?\
( .
"." ) ( ?\
) .
"." )
92 ( ?\
[ .
"." ) ( ?\
] .
"." )
93 ( ?\
{ .
"(}" ) ( ?\
} .
"){" )
94 ( ?\
< .
"(>" )( ?\
> .
")>")
95 ( ?\$ .
"." ) ( ?\% .
"." ) ( ?\
& .
"." )
96 ( ?\
* .
"." ) ( ?\
+ .
"." ) ( ?\- .
"." )
97 ( ?\
/ .
"." ) ( ?\
= .
"." )
98 ( ?\| .
"." ) (?
\\ .
"\\" )
112 (defconst mu-imenu-generic-re
"^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
113 "Regexp matching Identifier definitions.")
115 ;; Sadly we need this for a macro in Emacs 19.
117 ;; Imenu isn't used in XEmacs, so just ignore load errors.
122 (defvar mu-imenu-generic-expression
123 (list (list nil mu-imenu-generic-re
1))
124 "Expression for imenu")
126 (defun mudela-mode ()
127 "Major mode for editing Mudela files."
129 ;; set up local variables
130 (kill-all-local-variables)
132 (make-local-variable 'font-lock-defaults
)
133 (setq font-lock-defaults
'(mudela-font-lock-keywords))
135 (make-local-variable 'paragraph-separate
)
136 (setq paragraph-separate
"^[ \t]*$")
138 (make-local-variable 'paragraph-start
)
139 (setq paragraph-start
"^[ \t]*$")
141 (make-local-variable 'comment-start
)
142 (setq comment-start
"%")
144 (make-local-variable 'comment-start-skip
)
145 (setq comment-start-skip
"%{? *")
147 (make-local-variable 'comment-end
)
148 (setq comment-end
"\n")
150 (make-local-variable 'block-comment-start
)
151 (setq block-comment-start
"%{")
153 (make-local-variable 'block-comment-end
)
154 (setq block-comment-end
"%}")
156 ;; (make-local-variable 'comment-column)
157 ;; (setq comment-column 40)
159 (make-local-variable 'imenu-generic-expression
)
160 (setq imenu-generic-expression mu-imenu-generic-expression
)
162 (make-local-variable 'indent-line-function
)
163 (setq indent-line-function
'indent-relative-maybe
)
166 (set-syntax-table mu-mode-syntax-table
)
167 (setq major-mode
'mudela-mode
)
168 (setq mode-name
"Mudela")
169 (setq local-abbrev-table mudela-mode-abbrev-table
)
170 (use-local-map mu-mode-map
)
172 ;; run the mode hook. mu-mode-hook use is deprecated
173 (run-hooks 'mudela-mode-hook
))
176 (defun mu-keep-region-active ()
177 ;; do whatever is necessary to keep the region active in XEmacs.
178 ;; Ignore byte-compiler warnings you might see. Also note that
179 ;; FSF's Emacs 19 does it differently and doesn't its policy doesn't
180 ;; require us to take explicit action.
181 (and (boundp 'zmacs-region-stays
)
182 (setq zmacs-region-stays t
)))
185 ;;(defun mu-comment-region (beg end &optional arg)
186 ;; "Like `comment-region' but uses double hash (`#') comment starter."
187 ;; (interactive "r\nP")
188 ;; (let ((comment-start mu-block-comment-prefix))
189 ;; (comment-region beg end arg)))
192 "Echo the current version of `mudela-mode' in the minibuffer."
194 (message "Using `mudela-mode' version %s" mu-version
)
195 (mu-keep-region-active))
198 ;;; mudela-mode.el ends here