]> git.donarmstrong.com Git - lilypond.git/blob - mudela-mode.el
release: 0.1.54
[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 (defconst mudela-font-lock-keywords
33   (let* ((keywords '(
34                    "accepts" "break" "bar" "cadenza" "clear" "clef" "cm" "consists" "contains"
35                    "duration" "absdynamic" "in" "translator" "type" "lyric" "key"
36                    "melodic" "melodic_request" "meter" "midi" "mm" "multi" "header"
37                    "notenames" "octave" "output" "partial" "paper" "plet" "property" "pt" "shape"
38                    "include"
39                    "score" "script" "skip" "staff" "table" "spandynamic" "symboltables"
40                    "tempo" "texid" "textstyle" "transpose" "version" "grouping"
41                    ))
42        (kwregex (mapconcat (lambda (x) (concat "\\\\" x))  keywords "\\|")))
43
44     (list 
45      (cons (concat ".\\(" kwregex "\\)[^a-zA-Z]") 1)
46      (cons (concat "^\\(" kwregex "\\)[^a-zA-Z]") 1)
47      '(".\\(\\\\[a-zA-Z][a-zA-Z]*\\)" 1 font-lock-variable-name-face)
48      '("^[\t ]*\\([a-zA-Z][_a-zA-Z]*\\) *=" 1 font-lock-variable-name-face)     
49     ))
50   "Additional expressions to highlight in Mudela mode.")
51
52 ;; define a mode-specific abbrev table for those who use such things
53 (defvar mudela-mode-abbrev-table nil
54   "Abbrev table in use in `mudela-mode' buffers.")
55
56 (define-abbrev-table 'mudela-mode-abbrev-table nil)
57
58 (defvar mudela-mode-hook nil
59   "*Hook called by `mudela-mode'.")
60
61 (defvar mu-mode-map ()
62   "Keymap used in `mudela-mode' buffers.")
63
64 (defun mu-newline-and-indent ()
65   (interactive)
66   (newline)
67   (indent-relative-maybe)
68   "Newline and copy previous indentation")
69
70 (if mu-mode-map
71     ()
72   (setq mu-mode-map (make-sparse-keymap))
73
74   (mapcar (function (lambda (key)
75                       (define-key
76                         mu-mode-map key 'mu-newline-and-indent)))
77    (where-is-internal 'newline-and-indent))
78
79   (mapcar (function
80            (lambda (x)
81              (define-key mu-mode-map (car x) (cdr x))))
82           '(("\C-c\C-c"  . mu-foo-bar)
83             ))
84   ;; should do all keybindings this way
85   (define-key mu-mode-map [RET] 'mu-newline-and-indent)
86   ) 
87
88 (defvar mu-mode-syntax-table nil
89   "Syntax table used in `mudela-mode' buffers.")
90
91 ;;
92 (if mu-mode-syntax-table
93     ()
94   (setq mu-mode-syntax-table (make-syntax-table))
95   (mapcar (function
96            (lambda (x) (modify-syntax-entry
97                         (car x) (cdr x) mu-mode-syntax-table)))
98           '(( ?\( . "()" ) ( ?\) . ")(" )
99             ( ?\[ . "(]" ) ( ?\] . ")[" )
100             ( ?\{ . "(}" ) ( ?\} . "){" )
101             ( ?\< . "(>" )( ?\> . ")>") 
102             ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
103             ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." )
104             ( ?\/ . "." )  ( ?\= . "." )
105             ( ?\| . "." ) (?\\ . "\\" )
106             ( ?\_ . "." )       
107             ( ?\' . "w")        
108             ( ?\" . "\"" )
109             ( ?\% . "<")        
110             ( ?\n . ">")
111             
112             ))) 
113
114 (defconst mu-stringlit-re
115    "\"\\([^\"\n\\]\\|\\\\.\\)*\""       ; double-quoted
116   "Regexp matching a Mudela string literal.")
117
118
119 (defconst mu-blank-or-comment-re "[ \t]*\\($\\|%\\)"
120   "Regexp matching blank or comment lines.")
121
122 (defconst mu-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
123   "Regexp matching Identifier definitions.")
124
125 ;; Sadly we need this for a macro in Emacs 19.
126 (eval-when-compile
127   ;; Imenu isn't used in XEmacs, so just ignore load errors.
128   (condition-case ()
129       (require 'imenu)
130     (error nil)))
131
132 (defvar mu-imenu-generic-expression
133   (list (list nil mu-imenu-generic-re 1))
134   "Expression for imenu")
135
136 (defun mudela-mode ()
137   "Major mode for editing Mudela files."
138
139   (interactive)
140   ;; set up local variables
141   (kill-all-local-variables)
142   (make-local-variable 'font-lock-defaults)
143   (make-local-variable 'paragraph-separate)
144   (make-local-variable 'paragraph-start)
145   (make-local-variable 'require-final-newline)
146   (make-local-variable 'comment-start)
147   (setq comment-start "% ")
148   (setq comment-end "")
149   (make-local-variable 'comment-end)
150   (make-local-variable 'comment-start-skip)
151   (setf comment-start-skip "%{")
152   (make-local-variable 'comment-column)
153   (make-local-variable 'imenu-generic-expression)
154   (setq imenu-generic-expression mu-imenu-generic-expression)
155   (make-local-variable 'indent-line-function)
156  
157   ;;
158   (set-syntax-table mu-mode-syntax-table)
159   (setq major-mode             'mudela-mode
160         mode-name              "Mudela"
161         local-abbrev-table     mudela-mode-abbrev-table
162         font-lock-defaults     '(mudela-font-lock-keywords)
163         paragraph-separate     "^[ \t]*$"
164         paragraph-start        "^[ \t]*$"
165         require-final-newline  t
166         comment-start          "% "
167         comment-start-skip     "% *"
168         comment-column         40
169         indent-line-function    'indent-relative-maybe
170         )
171   (use-local-map mu-mode-map)
172
173   ;; run the mode hook. mu-mode-hook use is deprecated
174   (if mudela-mode-hook
175       (run-hooks 'mudela-mode-hook)
176     (run-hooks 'mu-mode-hook)))
177
178 (defun mu-keep-region-active ()
179   ;; do whatever is necessary to keep the region active in XEmacs.
180   ;; Ignore byte-compiler warnings you might see.  Also note that
181   ;; FSF's Emacs 19 does it differently and doesn't its policy doesn't
182   ;; require us to take explicit action.
183   (and (boundp 'zmacs-region-stays)
184        (setq zmacs-region-stays t)))
185
186
187 (defun mu-comment-region (beg end &optional arg)
188   "Like `comment-region' but uses double hash (`#') comment starter."
189   (interactive "r\nP")
190   (let ((comment-start mu-block-comment-prefix))
191     (comment-region beg end arg)))
192 \f
193 (defconst mu-version "0.0.1"
194   "`mudela-mode' version number.")
195 (defconst mu-help-address "hanwen@cs.ruu.nl"
196   "Address accepting submission of bug reports.")
197
198 (defun mu-version ()
199   "Echo the current version of `mudela-mode' in the minibuffer."
200   (interactive)
201   (message "Using `mudela-mode' version %s" mu-version)
202   (mu-keep-region-active))
203
204 (provide 'mu-mode)
205 ;;; mudela-mode.el ends here