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