]> git.donarmstrong.com Git - lilypond.git/blob - mudela-mode.el
release: 1.0.8
[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 mudela-font-lock-keywords
34   (let* ((keywords '(
35                      "accepts" "accidentals" "break" "bar" "cadenza" "clear" 
36                      "clef" "cm" "consists" "contains" "duration" "absdynamic" 
37                      "in" "translator" "type" "lyric" "key" "maininput" "melodic"
38                      "musical_pitch" "meter" "midi" "mm" "multi" "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"
43                      ))
44        (kwregex (mapconcat (lambda (x) (concat "\\\\" x))  keywords "\\|")))
45
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)     
51     ))
52   "Additional expressions to highlight in Mudela mode.")
53
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.")
57
58 (define-abbrev-table 'mudela-mode-abbrev-table nil)
59
60 (defvar mudela-mode-hook nil
61   "*Hook called by `mudela-mode'.")
62
63 (defvar mu-mode-map ()
64   "Keymap used in `mudela-mode' buffers.")
65
66 (defun mu-newline-and-indent ()
67   (interactive)
68   (newline)
69   (indent-relative-maybe)
70   "Newline and copy previous indentation")
71
72 (if mu-mode-map
73     ()
74   (setq mu-mode-map (make-sparse-keymap))
75
76   (mapcar (function (lambda (key)
77                       (define-key
78                         mu-mode-map key 'mu-newline-and-indent)))
79    (where-is-internal 'newline-and-indent))
80
81   (mapcar (function
82            (lambda (x)
83              (define-key mu-mode-map (car x) (cdr x))))
84           '(("\C-c\C-c"  . mu-foo-bar)
85             ))
86   ;; should do all keybindings this way
87   (define-key mu-mode-map [RET] 'mu-newline-and-indent)
88   ) 
89
90 (defvar mu-mode-syntax-table nil
91   "Syntax table used in `mudela-mode' buffers.")
92
93 ;;
94 (if mu-mode-syntax-table
95     ()
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 . ">")
113
114 ; FIXME
115 ;           ( ?%  .  ". 124b" )
116 ;           ( ?{  .  ". 23" )
117             ))
118
119   )     
120
121 (defconst mu-stringlit-re
122    "\"\\([^\"\n\\]\\|\\\\.\\)*\""       ; double-quoted
123   "Regexp matching a Mudela string literal.")
124
125
126 (defconst mu-blank-or-comment-re "[ \t]*\\($\\|%\\)"
127   "Regexp matching blank or comment lines.")
128
129 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
130   "Regexp matching Identifier definitions.")
131
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)))
138
139 (defvar mu-imenu-generic-expression
140   (list (list nil mu-imenu-generic-re 1))
141   "Expression for imenu")
142
143 (defun mudela-mode ()
144   "Major mode for editing Mudela files."
145
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)
163  
164   ;;
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
177         )
178   (use-local-map mu-mode-map)
179
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)))
184
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)))
192
193
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)))
199 \f
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.")
204
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))
210
211 (provide 'mu-mode)
212 ;;; mudela-mode.el ends here