]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-mode.el
''
[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 (load-library "lilypond-indent")
24
25 (require 'easymenu)
26 (require 'compile)
27
28 (defconst LilyPond-version "1.5.28"
29   "`LilyPond-mode' version number.")
30
31 (defconst LilyPond-help-address "bug-lilypond@gnu.org"
32   "Address accepting submission of bug reports.")
33
34 (defvar LilyPond-mode-hook nil
35   "*Hook called by `LilyPond-mode'.")
36
37 (defvar LilyPond-kick-xdvi nil
38   "If true, no simultaneous xdvi's are started, but reload signal is sent.")
39
40 (defvar LilyPond-command-history nil
41   "Command history list.")
42         
43 (defvar LilyPond-regexp-alist
44   '(("\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
45   "Regexp used to match LilyPond errors.  See `compilation-error-regexp-alist'.")
46
47 (defcustom LilyPond-include-path ".:/tmp"
48   "* LilyPond include path."
49   :type 'string
50   :group 'LilyPond)
51
52
53 (defun LilyPond-check-files (derived originals extensions)
54   "Check that DERIVED is newer than any of the ORIGINALS.
55 Try each original with each member of EXTENSIONS, in all directories
56 in LilyPond-include-path."
57   (let ((found nil)
58         (regexp (concat "\\`\\("
59                         (mapconcat (function (lambda (dir)
60                                       (regexp-quote (expand-file-name dir))))
61                                    LilyPond-include-path "\\|")
62                         "\\).*\\("
63                         (mapconcat 'regexp-quote originals "\\|")
64                         "\\)\\.\\("
65                         (mapconcat 'regexp-quote extensions "\\|")
66                         "\\)\\'"))
67         (buffers (buffer-list)))
68     (while buffers
69       (let* ((buffer (car buffers))
70              (name (buffer-file-name buffer)))
71         (setq buffers (cdr buffers))
72         (if (and name (string-match regexp name))
73             (progn
74               (and (buffer-modified-p buffer)
75                    (or (not LilyPond-save-query)
76                        (y-or-n-p (concat "Save file "
77                                          (buffer-file-name buffer)
78                                          "? ")))
79                    (save-excursion (set-buffer buffer) (save-buffer)))
80               (if (file-newer-than-file-p name derived)
81                   (setq found t))))))
82     found))
83
84 (defun LilyPond-running ()
85   (let ((process (get-process "lilypond")))
86   (and process
87        (eq (process-status process) 'run))))
88
89 (defun Midi-running ()
90   (let ((process (get-process "midi")))
91   (and process
92        (eq (process-status process) 'run))))
93
94 (defun LilyPond-kill-job ()
95   "Kill the currently running LilyPond job."
96   (interactive)
97   ;; What bout TeX, Xdvi?
98   (quit-process (get-process "lilypond") t))
99
100 ;; URG, should only run LilyPond-compile for LilyPond
101 ;; not for tex,xdvi (ly2dvi?)
102 (defun LilyPond-compile-file (command name)
103   ;; We maybe should know what we run here (Lily, ly2dvi, tex)
104   ;; and adjust our error-matching regex ?
105   (compile-internal command "No more errors" name ))
106
107 ;; do we still need this, now that we're using compile-internal?
108 (defun LilyPond-save-buffer ()
109   (if (buffer-modified-p) (save-buffer)))
110
111 ;;; return (dir base ext)
112 (defun split-file-name (name)
113   (let* ((i (string-match "[^/]*$" name))
114          (dir (if (> i 0) (substring name 0 i) "./"))
115          (file (substring name i (length name)))
116          (i (string-match "[^.]*$" file)))
117     (if (and
118          (> i 0)
119          (< i (length file)))
120         (list dir (substring file 0 (- i 1)) (substring file i (length file)))
121       (list dir file ""))))
122
123
124 ;; Should check whether in command-alist?
125 (defcustom LilyPond-command-default "LilyPond"
126   "Default command. Must identify a member of LilyPond-command-alist."
127
128   :group 'LilyPond
129   :type 'string)
130 ;;;(make-variable-buffer-local 'LilyPond-command-last)
131
132 (defvar LilyPond-command-current 'LilyPond-command-master)
133 ;;;(make-variable-buffer-local 'LilyPond-command-master)
134
135
136 ;; If non-nil, LilyPond-command-query will return the value of this
137 ;; variable instead of quering the user. 
138 (defvar LilyPond-command-force nil)
139
140 (defcustom LilyPond-xdvi-command "xdvik"
141   "Command used to display DVI files."
142
143   :group 'LilyPond
144   :type 'string)
145
146 (defcustom LilyPond-gv-command "gv -watch"
147   "Command used to display PS 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          (completion-ignore-case t)
267          
268          (answer (or LilyPond-command-force
269                      (completing-read
270                       (concat "Command: (default " default ") ")
271                       LilyPond-command-alist nil t nil 'LilyPond-command-history))))
272
273     ;; If the answer is "LilyPond" it will not be expanded to "LilyPond"
274     (let ((answer (car-safe (assoc answer LilyPond-command-alist))))
275       (if (and answer
276                (not (string-equal answer "")))
277           answer
278         default))))
279
280
281 ;; FIXME: find ``\score'' in buffers / make settable?
282 (defun LilyPond-master-file ()
283   ;; duh
284   (buffer-file-name))
285
286 (defun LilyPond-command-master ()
287   "Run command on the current document."
288   (interactive)
289   (LilyPond-command (LilyPond-command-query (LilyPond-master-file))
290                     'LilyPond-master-file))
291
292 (defun LilyPond-command-lilypond ()
293   "Run lilypond for the current document."
294   (interactive)
295   (LilyPond-command (LilyPond-command-menu "LilyPond") 'LilyPond-master-file)
296 )
297
298 (defun LilyPond-command-formatdvi ()
299   "Format the dvi output of the current document."
300   (interactive)
301   (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file)
302 )
303
304 (defun LilyPond-command-formatps ()
305   "Format the ps output of the current document."
306   (interactive)
307   (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file)
308 )
309
310 (defun LilyPond-command-smartview ()
311   "View the dvi output of current document."
312   (interactive)
313   (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file)
314 )
315
316 (defun LilyPond-command-view ()
317   "View the dvi output of current document."
318   (interactive)
319   (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file)
320 )
321
322 (defun LilyPond-command-viewps ()
323   "View the ps output of current document."
324   (interactive)
325   (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
326 )
327
328 (defun LilyPond-command-midi ()
329   "Play midi corresponding to the current document."
330   (interactive)
331   (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file)
332 )
333
334 (defun count-rexp (start end rexp)
335   "Print number of found regular expressions in the region."
336   (interactive "r")
337   (save-excursion
338     (save-restriction
339       (narrow-to-region start end)
340       (goto-char (point-min))
341       (count-matches rexp))))
342
343 (defun count-midi-words ()
344   "Print number of scores before the curser."
345   (interactive)
346   (count-rexp (point-min) (point-max) "\\\\midi"))
347  
348 (defun count-midi-words-backwards ()
349   "Print number of scores before the curser."
350   (interactive)
351   (count-rexp (point-min) (point) "\\\\midi"))
352  
353 (defun LilyPond-command-next-midi ()
354   "Play next midi score of the current document."
355   (interactive)
356   (if (Midi-running)
357       (quit-process (get-process "midi") t)
358     (LilyPond-compile-file 
359      (let ((fname (LilyPond-master-file))
360            (allcount (string-to-number (substring (count-midi-words) 0 -12)))
361            (count (string-to-number (substring (count-midi-words-backwards) 0 -12))))
362        (concat  LilyPond-midi-command " "
363                 (substring fname 0 -3) ; suppose ".ly"
364                 (if (and (> allcount 1) (> count 0)) ; not first score
365                     (if (eq count allcount)          ; last score
366                         (concat "-" (number-to-string (+ count -1)))
367                       (concat "-" (number-to-string count))))
368                 ".midi"))
369      "Midi")))
370
371 ;; FIXME, this is broken
372 (defun LilyPond-region-file (begin end)
373   (let (
374         ;; (dir "/tmp/")
375         ;; urg
376         (dir "./")
377         (base "emacs-lily")
378         ;; Hmm
379         (ext (if (string-match "^[\\]score" (buffer-substring begin end))
380                  ".ly"
381                (if (< 50 (abs (- begin end)))
382                    ".fly"
383                  ".sly"))))
384     (concat dir base ext)))
385
386 (defun LilyPond-command-region (begin end)
387   "Run LilyPond on the current region."
388   (interactive "r")
389   (write-region begin end (LilyPond-region-file begin end) nil 'nomsg)
390   (LilyPond-command (LilyPond-command-query
391                      (LilyPond-region-file begin end))
392                     '(lambda () (LilyPond-region-file begin end))))
393
394 (defun LilyPond-command-buffer ()
395   "Run LilyPond on buffer."
396   (interactive)
397   (LilyPond-command-region (point-min) (point-max)))
398
399 (defun LilyPond-command-expand (string file)
400   (let ((case-fold-search nil))
401     (if (string-match "%" string)
402         (let* ((b (match-beginning 0))
403                (e (+ b 2))
404                (l (split-file-name file))
405                (dir (car l))
406                (base (cadr l)))
407           (LilyPond-command-expand
408            (concat (substring string 0 b)
409                    dir
410                    base
411                    (let ((entry (assoc (substring string b e)
412                                        LilyPond-expand-alist)))
413                      (if entry (cdr entry) ""))
414                    (substring string e))
415            file))
416       string)))
417
418 (defun LilyPond-shell-process (name buffer command)
419   (let ((old (current-buffer)))
420     (switch-to-buffer-other-window buffer)
421     ;; If we empty the buffer don't see messages scroll by.
422     ;; (erase-buffer)
423     
424     (start-process-shell-command name buffer command)
425     (switch-to-buffer-other-window old)))
426   
427
428 (defun LilyPond-command (name file)
429   "Run command NAME on the file you get by calling FILE.
430
431 FILE is a function return a file name.  It has one optional argument,
432 the extension to use on the file.
433
434 Use the information in LilyPond-command-alist to determine how to run the
435 command."
436   
437   (let ((entry (assoc name LilyPond-command-alist)))
438     (if entry
439         (let ((command (LilyPond-command-expand (cadr entry)
440                                                 (apply file nil))))
441           (if (string-equal name "View")
442               (let ((buffer-xdvi (get-buffer-create "*view*")))
443                 (if LilyPond-kick-xdvi
444                   (let ((process-xdvi (get-buffer-process buffer-xdvi)))
445                     (if process-xdvi
446                         (signal-process (process-id process-xdvi) 'SIGUSR1)
447                       (LilyPond-shell-process name buffer-xdvi command)))
448                   (LilyPond-shell-process name buffer-xdvi command)))
449             (progn
450               (setq LilyPond-command-default name)
451               (LilyPond-compile-file command name)))))))
452           
453 ;; XEmacs stuff
454 ;; Sadly we need this for a macro in Emacs 19.
455 (eval-when-compile
456   ;; Imenu isn't used in XEmacs, so just ignore load errors.
457   (condition-case ()
458       (require 'imenu)
459     (error nil)))
460
461
462 ;;; Keymap
463
464 (defvar LilyPond-mode-map ()
465   "Keymap used in `LilyPond-mode' buffers.")
466
467 ;; Note:  if you make changes to the map, you must do
468 ;;    M-x set-variable LilyPond-mode-map nil
469 ;;    M-x eval-buffer
470 ;;    M-x LilyPond-mode
471 ;; to let the changest take effect
472
473 (if LilyPond-mode-map
474     ()
475   (setq LilyPond-mode-map (make-sparse-keymap))
476   (define-key LilyPond-mode-map "\C-c\C-l" 'LilyPond-command-lilypond)
477   (define-key LilyPond-mode-map "\C-c\C-r" 'LilyPond-command-region)
478   (define-key LilyPond-mode-map "\C-c\C-b" 'LilyPond-command-buffer)
479   (define-key LilyPond-mode-map "\C-c\C-k" 'LilyPond-kill-job)
480   (define-key LilyPond-mode-map "\C-c\C-c" 'LilyPond-command-master)
481   (define-key LilyPond-mode-map "\C-c\C-d" 'LilyPond-command-formatdvi)
482   (define-key LilyPond-mode-map "\C-c\C-f" 'LilyPond-command-formatps)
483   (define-key LilyPond-mode-map "\C-c\C-s" 'LilyPond-command-smartview)
484   (define-key LilyPond-mode-map "\C-c\C-v" 'LilyPond-command-view)
485   (define-key LilyPond-mode-map "\C-c\C-p" 'LilyPond-command-viewps)
486   (define-key LilyPond-mode-map "\C-c\C-m" 'LilyPond-command-next-midi)
487   (define-key LilyPond-mode-map "\C-cn" 'LilyPond-insert-tag-notes)
488   (define-key LilyPond-mode-map "\C-cs" 'LilyPond-insert-tag-score)
489   (define-key LilyPond-mode-map "\C-c;" 'comment-region)
490   )
491
492 ;;; Menu Support
493
494 (define-skeleton LilyPond-insert-tag-notes
495   "LilyPond notes tag."
496   nil
497 ;  (if (bolp) nil ?\n)
498   "\\notes"
499   (if (y-or-n-p "Set \"\\relative\" attribute? ")
500       (concat " \\relative " (skeleton-read "Relative: " "" str)))
501   " { " _ " }")
502
503 (define-skeleton LilyPond-insert-tag-score
504   "LilyPond score tag."
505   nil
506   (if (bolp) nil ?\n)
507   "\\score {\n"
508   "   " _ "\n"
509   "   \\paper {  }\n"
510   (if (y-or-n-p "Insert \"\\header\" field? ")
511       (concat "   \\header {\n      " 
512               (skeleton-read "Piece: " "piece = " str) "\n"
513               (if (y-or-n-p "Insert \"opus\" field? ")
514                   (concat "      " (skeleton-read "Opus: " "opus = " str) "\n"))
515               "   }\n"))
516   (if (y-or-n-p "Insert \"\\midi\" field? ")
517       (concat "   \\midi { " 
518               (skeleton-read "Midi: " "\\tempo 4 = " str)  
519               " }\n"))
520   "}\n")
521
522 (defun LilyPond-command-menu-entry (entry)
523   ;; Return LilyPond-command-alist ENTRY as a menu item.
524   (let ((name (car entry)))
525     (cond ((and (string-equal name LilyPond-command-Print)
526                 LilyPond-printer-list)
527            (let ((command LilyPond-print-command)
528                  (lookup 1))
529              (append (list LilyPond-command-Print)
530                      (mapcar 'LilyPond-command-menu-printer-entry
531                              LilyPond-printer-list))))
532           (t
533            (vector name (list 'LilyPond-command-menu name) t)))))
534
535
536 (easy-menu-define LilyPond-mode-menu
537     LilyPond-mode-map
538     "Menu used in LilyPond mode."
539   (append '("Command")
540           '(("Command on"
541              [ "Master File" LilyPond-command-select-master
542                :keys "C-c C-c" :style radio
543                :selected (eq LilyPond-command-current 'LilyPond-command-master) ]
544              [ "Buffer" LilyPond-command-select-buffer
545                :keys "C-c C-b" :style radio
546                :selected (eq LilyPond-command-current 'LilyPond-command-buffer) ]
547              [ "Region" LilyPond-command-select-region
548                :keys "C-c C-r" :style radio
549                :selected (eq LilyPond-command-current 'LilyPond-command-region) ]))
550           '(("Insert"
551              [ "\\notes..."  LilyPond-insert-tag-notes
552                :keys "C-c n" ]
553              [ "\\score..."  LilyPond-insert-tag-score
554                :keys "C-c s" ]
555              ))
556 ;         (let ((file 'LilyPond-command-on-current))
557 ;           (mapcar 'LilyPond-command-menu-entry LilyPond-command-alist))
558 ;;; Some kind of mapping which includes :keys might be more elegant
559           '([ "LilyPond" (LilyPond-command (LilyPond-command-menu "LilyPond") 'LilyPond-master-file) :keys "C-c C-l"])
560           '([ "TeX" (LilyPond-command (LilyPond-command-menu "TeX") 'LilyPond-master-file) ])
561           '([ "2Dvi" (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file) :keys "C-c C-d"])
562           '([ "2PS" (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file) :keys "C-c C-f"])
563           '([ "Book" (LilyPond-command (LilyPond-command-menu "Book") 'LilyPond-master-file) ])
564           '([ "LaTeX" (LilyPond-command (LilyPond-command-menu "LaTeX") 'LilyPond-master-file) ])
565           '([ "SmartView" (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file) :keys "C-c C-s"])
566           '([ "View" (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file) :keys "C-c C-v"])
567           '([ "ViewPS" (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file) :keys "C-c C-p"])
568           '([ "Midi (off)" (LilyPond-command-next-midi) :keys "C-c C-m"])
569           ))
570
571 (defconst LilyPond-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
572   "Regexp matching Identifier definitions.")
573
574 (defvar LilyPond-imenu-generic-expression
575   (list (list nil LilyPond-imenu-generic-re 1))
576   "Expression for imenu")
577
578 (defun LilyPond-command-select-master ()
579   (interactive)
580   (message "Next command will be on the master file")
581   (setq LilyPond-command-current 'LilyPond-command-master))
582
583 (defun LilyPond-command-select-buffer ()
584   (interactive)
585   (message "Next command will be on the buffer")
586   (setq LilyPond-command-current 'LilyPond-command-buffer))
587
588 (defun LilyPond-command-select-region ()
589   (interactive)
590   (message "Next command will be on the region")
591   (setq LilyPond-command-current 'LilyPond-command-region))
592
593 (defun LilyPond-command-menu (name)
594   ;; Execute LilyPond-command-alist NAME from a menu.
595   (let ((LilyPond-command-force name))
596     (funcall LilyPond-command-current)))
597
598 (defun LilyPond-mode ()
599   "Major mode for editing LilyPond music files.
600
601 This mode knows about LilyPond keywords and line comments, not about
602 indentation or block comments.  It features easy compilation, error
603 finding and viewing of a LilyPond source buffer or region.
604
605 COMMANDS
606 \\{LilyPond-mode-map}
607 VARIABLES
608
609 LilyPond-command-alist\t\talist from name to command
610 LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
611   (interactive)
612   ;; set up local variables
613   (kill-all-local-variables)
614
615   (make-local-variable 'font-lock-defaults)
616   (setq font-lock-defaults '(LilyPond-font-lock-keywords))
617
618   (make-local-variable 'paragraph-separate)
619   (setq paragraph-separate "^[ \t]*$")
620
621   (make-local-variable 'paragraph-start)
622   (setq paragraph-start "^[ \t]*$")
623
624   (make-local-variable 'comment-start)
625   (setq comment-start "%")
626
627   (make-local-variable 'comment-start-skip)
628   (setq comment-start-skip "%{? *")
629
630   (make-local-variable 'comment-end)
631   (setq comment-end "")
632
633   (make-local-variable 'block-comment-start)
634   (setq block-comment-start "%{")
635
636   (make-local-variable 'block-comment-end)  
637   (setq block-comment-end   "%}")
638
639   (make-local-variable 'indent-line-function)
640   (setq indent-line-function 'LilyPond-indent-line)
641
642     (set-syntax-table LilyPond-mode-syntax-table)
643   (setq major-mode 'LilyPond-mode)
644   (setq mode-name "LilyPond")
645   (setq local-abbrev-table LilyPond-mode-abbrev-table)
646   (use-local-map LilyPond-mode-map)
647
648   (make-local-variable 'imenu-generic-expression)
649   (setq imenu-generic-expression LilyPond-imenu-generic-expression)
650   (imenu-add-to-menubar "Index")
651
652     ;; run the mode hook. LilyPond-mode-hook use is deprecated
653   (run-hooks 'LilyPond-mode-hook))
654
655 (defun LilyPond-version ()
656   "Echo the current version of `LilyPond-mode' in the minibuffer."
657   (interactive)
658   (message "Using `LilyPond-mode' version %s" LilyPond-version))
659
660 (provide 'lilypond-mode)
661 ;;; lilypond-mode.el ends here
662