]> git.donarmstrong.com Git - lilypond.git/blob - mudela-mode.el
release: 1.3.10
[lilypond.git] / mudela-mode.el
1 ;;; mudela-mode.el --- Major mode for editing Mudela programs
2
3
4 ;; Copyright (C) 1992,1993,1994  Tim Peters
5
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
13
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.
19
20
21
22 ;; Kyrie Eleison; it is my first real Elisp file
23 ;; This is a cannabalised version of python-mode.el (HWN)
24 ;;
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 ;; 
32
33 (defconst mu-version "1.2.16-dk1"
34   "`mudela-mode' version number.")
35
36 (defconst mu-help-address "hanwen@cs.uu.nl"
37   "Address accepting submission of bug reports.")
38
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"
51                      "type" "version" 
52                      ))
53        (kwregex (mapconcat (lambda (x) (concat "\\\\" x))  keywords "\\|")))
54
55     (list 
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)     
60     ))
61   "Additional expressions to highlight in Mudela mode.")
62
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.")
66
67 (define-abbrev-table 'mudela-mode-abbrev-table nil)
68
69 (defvar mudela-mode-hook nil
70   "*Hook called by `mudela-mode'.")
71
72 (defvar mu-mode-map ()
73   "Keymap used in `mudela-mode' buffers.")
74
75 (if mu-mode-map
76     ()
77   (setq mu-mode-map (make-sparse-keymap))
78   ;; (define-key mu-mode-map "\C-c\C-c" 'mu-foo-bar)
79   ) 
80
81 (defvar mu-mode-syntax-table nil
82   "Syntax table used in `mudela-mode' buffers.")
83
84 ;;
85 (if mu-mode-syntax-table
86     ()
87   (setq mu-mode-syntax-table (make-syntax-table))
88   (mapcar (function
89            (lambda (x) (modify-syntax-entry
90                         (car x) (cdr x) mu-mode-syntax-table)))
91           '(( ?\( . "." ) ( ?\) . "." )
92             ( ?\[ . "." ) ( ?\] . "." )
93             ( ?\{ . "(}" ) ( ?\} . "){" )
94             ( ?\< . "(>" )( ?\> . ")>") 
95             ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
96             ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." )
97             ( ?\/ . "." )  ( ?\= . "." )
98             ( ?\| . "." ) (?\\ . "\\" )
99             ( ?\_ . "." )       
100             ( ?\' . "w")        
101             ( ?\" . "\"" )
102             ( ?\% . "<")
103             ( ?\n . ">")
104
105 ; FIXME
106 ;           ( ?%  .  ". 124b" )
107 ;           ( ?{  .  ". 23" )
108             ))
109
110   )     
111
112 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
113   "Regexp matching Identifier definitions.")
114
115 ;; Sadly we need this for a macro in Emacs 19.
116 (eval-when-compile
117   ;; Imenu isn't used in XEmacs, so just ignore load errors.
118   (condition-case ()
119       (require 'imenu)
120     (error nil)))
121
122 (defvar mu-imenu-generic-expression
123   (list (list nil mu-imenu-generic-re 1))
124   "Expression for imenu")
125
126 (defun mudela-mode ()
127   "Major mode for editing Mudela files."
128   (interactive)
129   ;; set up local variables
130   (kill-all-local-variables)
131
132   (make-local-variable 'font-lock-defaults)
133   (setq font-lock-defaults '(mudela-font-lock-keywords))
134
135   (make-local-variable 'paragraph-separate)
136   (setq paragraph-separate "^[ \t]*$")
137
138   (make-local-variable 'paragraph-start)
139   (setq paragraph-start "^[ \t]*$")
140
141   (make-local-variable 'comment-start)
142   (setq comment-start "%")
143
144   (make-local-variable 'comment-start-skip)
145   (setq comment-start-skip "%{? *")
146
147   (make-local-variable 'comment-end)
148   (setq comment-end "\n")
149
150   (make-local-variable 'block-comment-start)
151   (setq block-comment-start "%{")
152
153   (make-local-variable 'block-comment-end)  
154   (setq block-comment-end   "%}")
155
156   ;; (make-local-variable 'comment-column)
157   ;; (setq comment-column 40)
158
159   (make-local-variable 'imenu-generic-expression)
160   (setq imenu-generic-expression mu-imenu-generic-expression)
161
162   (make-local-variable 'indent-line-function)
163   (setq indent-line-function 'indent-relative-maybe)
164  
165   ;;
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)
171
172   ;; run the mode hook. mu-mode-hook use is deprecated
173   (run-hooks 'mudela-mode-hook))
174
175
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)))
183
184
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)))
190 \f
191 (defun mu-version ()
192   "Echo the current version of `mudela-mode' in the minibuffer."
193   (interactive)
194   (message "Using `mudela-mode' version %s" mu-version)
195   (mu-keep-region-active))
196
197 (provide 'mu-mode)
198 ;;; mudela-mode.el ends here