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