]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-mode.el
release: 1.5.23
[lilypond.git] / lilypond-mode.el
1 ;;;
2 ;;; lilypond-mode.el --- Major mode for editing GNU LilyPond music scores
3 ;;;
4 ;;; source file of the GNU LilyPond music typesetter
5 ;;; 
6 ;;; (c) 1999--2001 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; 
8 ;;; Changed 2001 Heikki Junes <heikki.junes@hut.fi>
9 ;;;    * Add PS-compilation, PS-viewing and MIDI-play (29th Aug 2001)
10 ;;;    * Keyboard shortcuts (12th Sep 2001)
11 ;;;    * Inserting tags, inspired on sgml-mode (11th Oct 2001)
12
13 ;;; Inspired on auctex
14
15 ;;;
16 ;;; Add this to your ~/.emacs or ~/.emacs.el
17 ;;;     (load-library "lilypond-mode.el")
18 ;;;     (setq auto-mode-alist
19 ;;;      (append '(("\\.ly$" . LilyPond-mode) auto-mode-alist)))
20 ;;; 
21
22 (load-library "lilypond-font-lock")
23
24 (require 'easymenu)
25 (require 'compile)
26
27 (defconst LilyPond-version "1.3.143"
28   "`LilyPond-mode' version number.")
29
30 (defconst LilyPond-help-address "bug-gnu-music@gnu.org"
31   "Address accepting submission of bug reports.")
32
33 (defvar LilyPond-mode-hook nil
34   "*Hook called by `LilyPond-mode'.")
35
36 (defvar LilyPond-kick-xdvi nil
37   "If true, no simultaneous xdvi's are started, but reload signal is sent.")
38
39 (defvar LilyPond-command-history nil
40   "Command history list.")
41         
42 (defvar LilyPond-regexp-alist
43   '(("\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
44   "Regexp used to match LilyPond errors.  See `compilation-error-regexp-alist'.")
45
46 (defcustom LilyPond-include-path ".:/tmp"
47   "* LilyPond include path."
48   :type 'string
49   :group 'LilyPond)
50
51
52 (defun LilyPond-check-files (derived originals extensions)
53   "Check that DERIVED is newer than any of the ORIGINALS.
54 Try each original with each member of EXTENSIONS, in all directories
55 in LilyPond-include-path."
56   (let ((found nil)
57         (regexp (concat "\\`\\("
58                         (mapconcat (function (lambda (dir)
59                                       (regexp-quote (expand-file-name dir))))
60                                    LilyPond-include-path "\\|")
61                         "\\).*\\("
62                         (mapconcat 'regexp-quote originals "\\|")
63                         "\\)\\.\\("
64                         (mapconcat 'regexp-quote extensions "\\|")
65                         "\\)\\'"))
66         (buffers (buffer-list)))
67     (while buffers
68       (let* ((buffer (car buffers))
69              (name (buffer-file-name buffer)))
70         (setq buffers (cdr buffers))
71         (if (and name (string-match regexp name))
72             (progn
73               (and (buffer-modified-p buffer)
74                    (or (not LilyPond-save-query)
75                        (y-or-n-p (concat "Save file "
76                                          (buffer-file-name buffer)
77                                          "? ")))
78                    (save-excursion (set-buffer buffer) (save-buffer)))
79               (if (file-newer-than-file-p name derived)
80                   (setq found t))))))
81     found))
82
83 (defun LilyPond-running ()
84   (let ((process (get-process "lilypond")))
85   (and process
86        (eq (process-status process) 'run))))
87
88 (defun LilyPond-kill-job ()
89   "Kill the currently running LilyPond job."
90   (interactive)
91   ;; What bout TeX, Xdvi?
92   (quit-process (get-process "lilypond") t))
93
94 ;; URG, should only run LilyPond-compile for LilyPond
95 ;; not for tex,xdvi (ly2dvi?)
96 (defun LilyPond-compile-file (command name)
97   ;; We maybe should know what we run here (Lily, ly2dvi, tex)
98   ;; and adjust our error-matching regex ?
99   (compile-internal command "No more errors" name ))
100
101 ;; do we still need this, now that we're using compile-internal?
102 (defun LilyPond-save-buffer ()
103   (if (buffer-modified-p) (save-buffer)))
104
105 ;;; return (dir base ext)
106 (defun split-file-name (name)
107   (let* ((i (string-match "[^/]*$" name))
108          (dir (if (> i 0) (substring name 0 i) "./"))
109          (file (substring name i (length name)))
110          (i (string-match "[^.]*$" file)))
111     (if (and
112          (> i 0)
113          (< i (length file)))
114         (list dir (substring file 0 (- i 1)) (substring file i (length file)))
115       (list dir file ""))))
116
117
118 ;; Should check whether in command-alist?
119 (defcustom LilyPond-command-default "LilyPond"
120   "Default command. Must identify a member of LilyPond-command-alist."
121
122   :group 'LilyPond
123   :type 'string)
124 ;;;(make-variable-buffer-local 'LilyPond-command-last)
125
126 (defvar LilyPond-command-current 'LilyPond-command-master)
127 ;;;(make-variable-buffer-local 'LilyPond-command-master)
128
129
130 ;; If non-nil, LilyPond-command-query will return the value of this
131 ;; variable instead of quering the user. 
132 (defvar LilyPond-command-force nil)
133
134 (defcustom LilyPond-xdvi-command "xdvik"
135   "Command used to display DVI files."
136
137   :group 'LilyPond
138   :type 'string)
139
140 (defcustom LilyPond-gv-command "gv -watch"
141   "Command used to display PS files."
142
143   :group 'LilyPond
144   :type 'string)
145
146 (defcustom LilyPond-midi-command "timidity"
147   "Command used to play MIDI files."
148
149   :group 'LilyPond
150   :type 'string)
151
152 (defcustom LilyPond-gv-command "gv -watch"
153   "Command used to display PS files."
154
155   :group 'LilyPond
156   :type 'string)
157
158 (defcustom LilyPond-midi-command "timidity"
159   "Command used to play MIDI files."
160
161   :group 'LilyPond
162   :type 'string)
163
164 ;; This is the major configuration variable.
165 (defcustom LilyPond-command-alist
166   `(
167     ("LilyPond" . ("lilypond %s" . "TeX"))
168     ("TeX" . ("tex '\\nonstopmode\\input %t'" . "View"))
169
170     ("2Dvi" . ("ly2dvi %s" . "View"))
171     ("2PS" . ("ly2dvi -P %s" . "View"))
172
173     ("Book" . ("lilypond-book %x" . "LaTeX"))
174     ("LaTeX" . ("latex '\\nonstopmode\\input %l'" . "View"))
175
176     ;; point-n-click (arg: exits upop USR1)
177     ("SmartView" . ("xdvi %d" . "LilyPond"))
178     
179     ;; refreshes when kicked USR1
180     ("View" . (,(concat LilyPond-xdvi-command " %d") . "LilyPond"))
181
182     ("ViewPS" . (,(concat LilyPond-gv-command " %p") . "LilyPond"))
183
184     ("Midi" . (,(concat LilyPond-midi-command " %m") . "LilyPond"))
185     )
186
187   "AList of commands to execute on the current document.
188
189 The key is the name of the command as it will be presented to the
190 user, the value is a cons of the command string handed to the shell
191 after being expanded, and the next command to be executed upon
192 success.  The expansion is done using the information found in
193 LilyPond-expand-list.
194 "
195   :group 'LilyPond
196   :type '(repeat (cons :tag "Command Item"
197                        (string :tag "Key")
198                        (cons :tag "How"
199                         (string :tag "Command")
200                         (string :tag "Next Key")))))
201
202 ;; drop this?
203 (defcustom LilyPond-file-extensions '(".ly" ".sly" ".fly")
204   "*File extensions used by manually generated TeX files."
205   :group 'LilyPond
206   :type '(repeat (string :format "%v")))
207
208
209 (defcustom LilyPond-expand-alist 
210   '(
211     ("%s" . ".ly")
212     ("%t" . ".tex")
213     ("%d" . ".dvi")
214     ("%p" . ".ps")
215     ("%l" . ".latex")
216     ("%x" . ".tely")
217     ("%m" . ".midi")
218     )
219     
220   "Alist of expansion strings for LilyPond command names."
221   :group 'LilyPond
222   :type '(repeat (cons :tag "Alist item"
223                   (string :tag "Symbol")
224                   (string :tag "Expansion")))) 
225
226
227 (defcustom LilyPond-command-Show "View"
228   "*The default command to show (view or print) a LilyPond file.
229 Must be the car of an entry in `LilyPond-command-alist'."
230   :group 'LilyPond
231   :type 'string)
232   (make-variable-buffer-local 'LilyPond-command-Show)
233
234 (defcustom LilyPond-command-Print "Print"
235   "The name of the Print entry in LilyPond-command-Print."
236   :group 'LilyPond
237   :type 'string)
238
239 (defun xLilyPond-compile-sentinel (process msg)
240   (if (and process
241            (= 0 (process-exit-status process)))
242       (setq LilyPond-command-default
243               (cddr (assoc LilyPond-command-default LilyPond-command-alist)))))
244
245 ;; FIXME: shouldn't do this for stray View/xdvi
246 (defun LilyPond-compile-sentinel (buffer msg)
247   (if (string-match "^finished" msg)
248       (setq LilyPond-command-default
249             (cddr (assoc LilyPond-command-default LilyPond-command-alist)))))
250
251 ;;(make-variable-buffer-local 'compilation-finish-function)
252 (setq compilation-finish-function 'LilyPond-compile-sentinel)
253
254 (defun LilyPond-command-query (name)
255   "Query the user for what LilyPond command to use."
256   (let* ((default (cond ((if (string-equal name "emacs-lily")
257                              (LilyPond-check-files (concat name ".tex")
258                                                    (list name)
259                                                    LilyPond-file-extensions)
260                            ;; FIXME
261                            (LilyPond-save-buffer)
262                            ;;"LilyPond"
263                            LilyPond-command-default))
264                         (t LilyPond-command-default)))
265          
266          (answer (or LilyPond-command-force
267                      (completing-read
268                       (concat "Command: (default " default ") ")
269                       LilyPond-command-alist nil t nil 'LilyPond-command-history))))
270
271     ;; If the answer is "LilyPond" it will not be expanded to "LilyPond"
272     (let ((answer (car-safe (assoc answer LilyPond-command-alist))))
273       (if (and answer
274                (not (string-equal answer "")))
275           answer
276         default))))
277
278
279 ;; FIXME: find ``\score'' in buffers / make settable?
280 (defun LilyPond-master-file ()
281   ;; duh
282   (buffer-file-name))
283
284 (defun LilyPond-command-master ()
285   "Run command on the current document."
286   (interactive)
287   (LilyPond-command (LilyPond-command-query (LilyPond-master-file))
288                     'LilyPond-master-file))
289
290 (defun LilyPond-command-formatdvi ()
291   "Format the dvi output of the current document."
292   (interactive)
293   (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file)
294 )
295
296 (defun LilyPond-command-formatps ()
297   "Format the ps output of the current document."
298   (interactive)
299   (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file)
300 )
301
302 (defun LilyPond-command-smartview ()
303   "View the dvi output of current document."
304   (interactive)
305   (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file)
306 )
307
308 (defun LilyPond-command-view ()
309   "View the dvi output of current document."
310   (interactive)
311   (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file)
312 )
313
314 (defun LilyPond-command-viewps ()
315   "View the ps output of current document."
316   (interactive)
317   (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
318 )
319
320 (defun LilyPond-command-midi ()
321   "View the ps output of current document."
322   (interactive)
323   (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file)
324 )
325
326 (defun LilyPond-command-formatdvi ()
327   "Format the dvi output of the current document."
328   (interactive)
329   (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file)
330 )
331
332 (defun LilyPond-command-formatps ()
333   "Format the ps output of the current document."
334   (interactive)
335   (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file)
336 )
337
338 (defun LilyPond-command-smartview ()
339   "View the dvi output of current document."
340   (interactive)
341   (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file)
342 )
343
344 (defun LilyPond-command-view ()
345   "View the dvi output of current document."
346   (interactive)
347   (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file)
348 )
349
350 (defun LilyPond-command-viewps ()
351   "View the ps output of current document."
352   (interactive)
353   (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
354 )
355
356 (defun LilyPond-command-midi ()
357   "View the ps output of current document."
358   (interactive)
359   (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file)
360 )
361
362 ;; FIXME, this is broken
363 (defun LilyPond-region-file (begin end)
364   (let (
365         ;; (dir "/tmp/")
366         ;; urg
367         (dir "./")
368         (base "emacs-lily")
369         ;; Hmm
370         (ext (if (string-match "^[\\]score" (buffer-substring begin end))
371                  ".ly"
372                (if (< 50 (abs (- begin end)))
373                    ".fly"
374                  ".sly"))))
375     (concat dir base ext)))
376
377 (defun LilyPond-command-region (begin end)
378   "Run LilyPond on the current region."
379   (interactive "r")
380   (write-region begin end (LilyPond-region-file begin end) nil 'nomsg)
381   (LilyPond-command (LilyPond-command-query
382                      (LilyPond-region-file begin end))
383                     '(lambda () (LilyPond-region-file begin end))))
384
385 (defun LilyPond-command-buffer ()
386   "Run LilyPond on buffer."
387   (interactive)
388   (LilyPond-command-region (point-min) (point-max)))
389
390 (defun LilyPond-command-expand (string file)
391   (let ((case-fold-search nil))
392     (if (string-match "%" string)
393         (let* ((b (match-beginning 0))
394                (e (+ b 2))
395                (l (split-file-name file))
396                (dir (car l))
397                (base (cadr l)))
398           (LilyPond-command-expand
399            (concat (substring string 0 b)
400                    dir
401                    base
402                    (let ((entry (assoc (substring string b e)
403                                        LilyPond-expand-alist)))
404                      (if entry (cdr entry) ""))
405                    (substring string e))
406            file))
407       string)))
408
409 (defun LilyPond-shell-process (name buffer command)
410   (let ((old (current-buffer)))
411     (switch-to-buffer-other-window buffer)
412     ;; If we empty the buffer don't see messages scroll by.
413     ;; (erase-buffer)
414     
415     (start-process-shell-command name buffer command)
416     (switch-to-buffer-other-window old)))
417   
418
419 (defun LilyPond-command (name file)
420   "Run command NAME on the file you get by calling FILE.
421
422 FILE is a function return a file name.  It has one optional argument,
423 the extension to use on the file.
424
425 Use the information in LilyPond-command-alist to determine how to run the
426 command."
427   
428   (let ((entry (assoc name LilyPond-command-alist)))
429     (if entry
430         (let ((command (LilyPond-command-expand (cadr entry)
431                                                 (apply file nil))))
432           (if (string-equal name "View")
433               (let ((buffer-xdvi (get-buffer-create "*view*")))
434                 (if LilyPond-kick-xdvi
435                   (let ((process-xdvi (get-buffer-process buffer-xdvi)))
436                     (if process-xdvi
437                         (signal-process (process-id process-xdvi) 'SIGUSR1)
438                       (LilyPond-shell-process name buffer-xdvi command)))
439                   (LilyPond-shell-process name buffer-xdvi command)))
440             (progn
441               (setq LilyPond-command-default name)
442               (LilyPond-compile-file command name)))))))
443           
444 ;; XEmacs stuff
445 ;; Sadly we need this for a macro in Emacs 19.
446 (eval-when-compile
447   ;; Imenu isn't used in XEmacs, so just ignore load errors.
448   (condition-case ()
449       (require 'imenu)
450     (error nil)))
451
452
453 ;;; Keymap
454
455 (defvar LilyPond-mode-map ()
456   "Keymap used in `LilyPond-mode' buffers.")
457
458 ;; Note:  if you make changes to the map, you must do
459 ;;    M-x set-variable LilyPond-mode-map nil
460 ;;    M-x eval-buffer
461 ;;    M-x LilyPond-mode
462 ;; to let the changest take effect
463
464 (if LilyPond-mode-map
465     ()
466   (setq LilyPond-mode-map (make-sparse-keymap))
467   (define-key LilyPond-mode-map "\C-c\C-r" 'LilyPond-command-region)
468   (define-key LilyPond-mode-map "\C-c\C-b" 'LilyPond-command-buffer)
469   (define-key LilyPond-mode-map "\C-c\C-k" 'LilyPond-kill-job)
470   (define-key LilyPond-mode-map "\C-c\C-c" 'LilyPond-command-master)
471   (define-key LilyPond-mode-map "\C-c\C-d" 'LilyPond-command-formatdvi)
472   (define-key LilyPond-mode-map "\C-c\C-f" 'LilyPond-command-formatps)
473   (define-key LilyPond-mode-map "\C-c\C-s" 'LilyPond-command-smartview)
474   (define-key LilyPond-mode-map "\C-c\C-v" 'LilyPond-command-view)
475   (define-key LilyPond-mode-map "\C-c\C-p" 'LilyPond-command-viewps)
476   (define-key LilyPond-mode-map "\C-c\C-m" 'LilyPond-command-midi)
477   (define-key LilyPond-mode-map "\C-cn" 'lilypond-notes)
478   (define-key LilyPond-mode-map "\C-cs" 'lilypond-score)
479   )
480
481 ;;; Menu Support
482
483 (define-skeleton lilypond-notes
484   "Lilypond notes tag."
485   nil
486 ;  (if (bolp) nil ?\n)
487   "\\notes"
488   (if (y-or-n-p "Set \"\\relative\" attribute? ")
489       (concat " \\relative " (skeleton-read "Relative: " "" str)))
490   " { " _ " }")
491
492 (define-skeleton lilypond-score
493   "Lilypond score tag."
494   nil
495   (if (bolp) nil ?\n)
496   "\\score {\n"
497   "   " _ "\n"
498   "   \\paper {  }\n"
499   (if (y-or-n-p "Insert \"\\header\" field? ")
500       (concat "   \\header {\n      " 
501               (skeleton-read "Piece: " "piece = " str) "\n"
502               (if (y-or-n-p "Insert \"opus\" field? ")
503                   (concat "      " (skeleton-read "Opus: " "opus = " str) "\n"))
504               "   }\n"))
505   (if (y-or-n-p "Insert \"\\midi\" field? ")
506       (concat "   \\midi { " 
507               (skeleton-read "Midi: " "\\tempo 4 = " str)  
508               " }\n"))
509   "}\n")
510
511 (defun LilyPond-command-menu-entry (entry)
512   ;; Return LilyPond-command-alist ENTRY as a menu item.
513   (let ((name (car entry)))
514     (cond ((and (string-equal name LilyPond-command-Print)
515                 LilyPond-printer-list)
516            (let ((command LilyPond-print-command)
517                  (lookup 1))
518              (append (list LilyPond-command-Print)
519                      (mapcar 'LilyPond-command-menu-printer-entry
520                              LilyPond-printer-list))))
521           (t
522            (vector name (list 'LilyPond-command-menu name) t)))))
523
524
525 (easy-menu-define LilyPond-mode-menu
526     LilyPond-mode-map
527     "Menu used in LilyPond mode."
528   (append '("Command")
529           '(("Command on"
530              [ "Master File" LilyPond-command-select-master
531                :keys "C-c C-c" :style radio
532                :selected (eq LilyPond-command-current 'LilyPond-command-master) ]
533              [ "Buffer" LilyPond-command-select-buffer
534                :keys "C-c C-b" :style radio
535                :selected (eq LilyPond-command-current 'LilyPond-command-buffer) ]
536              [ "Region" LilyPond-command-select-region
537                :keys "C-c C-r" :style radio
538                :selected (eq LilyPond-command-current 'LilyPond-command-region) ]))
539           '(("Insert"
540              [ "\\notes..."  lilypond-notes
541                :keys "C-c n" ]
542              [ "\\score..."  lilypond-score
543                :keys "C-c s" ]
544              ))
545 ;         (let ((file 'LilyPond-command-on-current))
546 ;           (mapcar 'LilyPond-command-menu-entry LilyPond-command-alist))
547 ;;; Some kind of mapping which includes :keys might be more elegant
548           '([ "LilyPond" (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file) ])
549           '([ "TeX" (LilyPond-command (LilyPond-command-menu "TeX") 'LilyPond-master-file) ])
550           '([ "2Dvi" (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file) :keys "C-c C-d"])
551           '([ "2PS" (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file) :keys "C-c C-f"])
552           '([ "Book" (LilyPond-command (LilyPond-command-menu "Book") 'LilyPond-master-file) ])
553           '([ "LaTeX" (LilyPond-command (LilyPond-command-menu "LaTeX") 'LilyPond-master-file) ])
554           '([ "SmartView" (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file) :keys "C-c C-s"])
555           '([ "View" (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file) :keys "C-c C-v"])
556           '([ "ViewPS" (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file) :keys "C-c C-p"])
557           '([ "Midi" (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file) :keys "C-c C-m"])
558           ))
559
560 (defconst LilyPond-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
561   "Regexp matching Identifier definitions.")
562
563 (defvar LilyPond-imenu-generic-expression
564   (list (list nil LilyPond-imenu-generic-re 1))
565   "Expression for imenu")
566
567 (defun LilyPond-command-select-master ()
568   (interactive)
569   (message "Next command will be on the master file")
570   (setq LilyPond-command-current 'LilyPond-command-master))
571
572 (defun LilyPond-command-select-buffer ()
573   (interactive)
574   (message "Next command will be on the buffer")
575   (setq LilyPond-command-current 'LilyPond-command-buffer))
576
577 (defun LilyPond-command-select-region ()
578   (interactive)
579   (message "Next command will be on the region")
580   (setq LilyPond-command-current 'LilyPond-command-region))
581
582 (defun LilyPond-command-menu (name)
583   ;; Execute LilyPond-command-alist NAME from a menu.
584   (let ((LilyPond-command-force name))
585     (funcall LilyPond-command-current)))
586
587 (defun LilyPond-mode ()
588   "Major mode for editing LilyPond music files.
589
590 This mode knows about LilyPond keywords and line comments, not about
591 indentation or block comments.  It features easy compilation, error
592 finding and viewing of a LilyPond source buffer or region.
593
594 COMMANDS
595 \\{LilyPond-mode-map}
596 VARIABLES
597
598 LilyPond-command-alist\t\talist from name to command
599 LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
600   (interactive)
601   ;; set up local variables
602   (kill-all-local-variables)
603
604   (make-local-variable 'font-lock-defaults)
605   (setq font-lock-defaults '(LilyPond-font-lock-keywords))
606
607   (make-local-variable 'paragraph-separate)
608   (setq paragraph-separate "^[ \t]*$")
609
610   (make-local-variable 'paragraph-start)
611   (setq paragraph-start "^[ \t]*$")
612
613   (make-local-variable 'comment-start)
614   (setq comment-start "%")
615
616   (make-local-variable 'comment-start-skip)
617   (setq comment-start-skip "%{? *")
618
619   (make-local-variable 'comment-end)
620   (setq comment-end "")
621
622   (make-local-variable 'block-comment-start)
623   (setq block-comment-start "%{")
624
625   (make-local-variable 'block-comment-end)  
626   (setq block-comment-end   "%}")
627
628   (make-local-variable 'indent-line-function)
629   (setq indent-line-function 'indent-relative-maybe)
630  
631     (set-syntax-table LilyPond-mode-syntax-table)
632   (setq major-mode 'LilyPond-mode)
633   (setq mode-name "LilyPond")
634   (setq local-abbrev-table LilyPond-mode-abbrev-table)
635   (use-local-map LilyPond-mode-map)
636
637   (make-local-variable 'imenu-generic-expression)
638   (setq imenu-generic-expression LilyPond-imenu-generic-expression)
639   (imenu-add-to-menubar "Index")
640
641     ;; run the mode hook. LilyPond-mode-hook use is deprecated
642   (run-hooks 'LilyPond-mode-hook))
643
644 (defun LilyPond-version ()
645   "Echo the current version of `LilyPond-mode' in the minibuffer."
646   (interactive)
647   (message "Using `LilyPond-mode' version %s" LilyPond-version))
648
649 (provide 'lilypond-mode)
650 ;;; lilypond-mode.el ends here
651