]> git.donarmstrong.com Git - lilypond.git/blob - lilypond-mode.el
rename generated file lilypond.words to lilypond.words.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--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 ;;; 
8 ;;; Changed 2001--2003 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 ;;;    * Autocompletion & Info (23rd Nov 2002)
13
14 ;;; Inspired on auctex
15
16 ;;; Look lilypond-init.el or Documentation/topdocs/INSTALL.texi
17 ;;; for installing instructions.
18
19 (require 'easymenu)
20 (require 'compile)
21
22 (defconst LilyPond-version "1.8.0"
23   "`LilyPond-mode' version number.")
24
25 (defconst LilyPond-help-address "bug-lilypond@gnu.org"
26   "Address accepting submission of bug reports.")
27
28 (defvar LilyPond-mode-hook nil
29   "*Hook called by `LilyPond-mode'.")
30
31 (defvar LilyPond-region-file-prefix "emacs-lily"
32   "File prefix for commands on buffer or region.")
33
34 ;; FIXME: find ``\score'' in buffers / make settable?
35 (defun LilyPond-master-file ()
36   ;; duh
37   (buffer-file-name))
38
39 (defvar LilyPond-kick-xdvi nil
40   "If true, no simultaneous xdvi's are started, but reload signal is sent.")
41
42 (defvar LilyPond-command-history nil
43   "Command history list.")
44         
45 (defvar LilyPond-regexp-alist
46   '(("\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2))
47   "Regexp used to match LilyPond errors.  See `compilation-error-regexp-alist'.")
48
49 (defvar LilyPond-imenu nil
50   "A flag to tell whether LilyPond-imenu is turned on.")
51 (make-variable-buffer-local 'LilyPond-imenu)
52
53 (defcustom LilyPond-include-path ".:/tmp"
54   "* LilyPond include path."
55   :type 'string
56   :group 'LilyPond)
57
58 (defun LilyPond-words-filename ()
59   "The file containing LilyPond \keywords \Identifiers and ReservedWords.
60 Finds file lilypond-words.el from load-path."
61   (let ((fn nil)
62         (lp load-path)
63         (words-file "lilypond.words.el"))
64     (while (and (> (length lp) 0) (not fn))
65       (setq fn (concat (car lp) "/" words-file))
66       (if (not (file-readable-p fn)) 
67           (progn (setq fn nil) (setq lp (cdr lp)))))
68     (if (not fn)
69         (progn (message "Warning: `lilypond.words.el' not found in `load-path'. See `lilypond-init.el'.")
70                (sit-for 5 0)))
71     fn))
72
73 (defun LilyPond-add-dictionary-word (x)
74   "Contains all words: \keywords \Identifiers and ReservedWords."
75   (nconc '(("" . 1)) x))
76
77 ;; creates dictionary if empty
78 (if (and (eq (length (LilyPond-add-dictionary-word ())) 1)
79          (not (eq (LilyPond-words-filename) nil)))
80     (progn
81       (setq b (find-file-noselect (LilyPond-words-filename) t t))
82       (setq m (set-marker (make-marker) 1 (get-buffer b)))
83       (setq i 1)
84       (while (> (buffer-size b) (marker-position m))
85         (setq i (+ i 1))
86         (setq copy (copy-alist (list (eval (symbol-name (read m))))))
87         (setcdr copy i)
88         (LilyPond-add-dictionary-word (list copy)))
89       (kill-buffer b)))
90
91 (defvar LilyPond-insert-tag-current ""
92   "The last command selected from the LilyPond-Insert -menu.")
93
94 (defconst LilyPond-menu-keywords 
95   (let ((wordlist '())
96         (co (all-completions "" (LilyPond-add-dictionary-word ())))
97         (currword ""))
98     (progn
99       (while (> (length co) 0)
100         (setq currword (car co))
101         (if (string-equal "-" (car (setq co (cdr co))))
102             (progn
103               (add-to-list 'wordlist currword)
104               (while (and (> (length co) 0)
105                           (not (string-equal "-" (car (setq co (cdr co))))))))))
106       (reverse wordlist)))
107   "Keywords inserted from LilyPond-Insert-menu.")
108
109 (defconst LilyPond-keywords
110   (let ((wordlist '("\\score"))
111         (co (all-completions "" (LilyPond-add-dictionary-word ())))
112         (currword ""))
113     (progn
114       (while (> (length co) 0)
115         (setq currword (car co))
116         (if (> (length currword) 1)
117             (if (and (string-equal "\\" (substring currword 0 1))
118                      (progn (string-match "[a-z-]+" currword)
119                             (= (match-end 0) (length currword)))
120                      (not (string-equal "\\longa" currword))
121                      (not (string-equal "\\breve" currword))
122                      (not (string-equal "\\maxima" currword))
123                      (string-equal (downcase currword) currword))
124                 (add-to-list 'wordlist currword)))
125         (if (string-equal "-" (car (setq co (cdr co))))
126             (while (and (> (length co) 0)
127                         (not (string-equal "-" (car (setq co (cdr co)))))))))
128       wordlist))
129   "LilyPond \\keywords")
130
131 (defconst LilyPond-identifiers 
132   (let ((wordlist '("\\voiceOne"))
133         (co (all-completions "" (LilyPond-add-dictionary-word ()))))
134     (progn
135       (while (> (length co) 0)
136         (setq currword (car co))
137         (if (> (length currword) 1)
138             (if (and (string-equal "\\" (substring currword 0 1))
139                      (progn (string-match "[a-zA-Z-]+" currword)
140                             (= (match-end 0) (length currword)))
141                      (not (string-equal (downcase currword) currword)))
142                 (add-to-list 'wordlist currword)))
143         (if (string-equal "-" (car (setq co (cdr co))))
144             (while (and (> (length co) 0)
145                         (not (string-equal "-" (car (setq co (cdr co)))))))))
146       wordlist))
147   "LilyPond \\Identifiers")
148
149 (defconst LilyPond-Capitalized-Reserved-Words 
150   (let ((wordlist '("Staff"))
151         (co (all-completions "" (LilyPond-add-dictionary-word ()))))
152     (progn
153       (while (> (length co) 0)
154         (setq currword (car co))
155         (if (> (length currword) 0)
156             (if (and (progn (string-match "[a-zA-Z_]+" currword)
157                             (= (match-end 0) (length currword)))
158                      (not (string-equal (downcase currword) currword)))
159                 (add-to-list 'wordlist currword)))
160         (if (string-equal "-" (car (setq co (cdr co))))
161             (while (and (> (length co) 0)
162                         (not (string-equal "-" (car (setq co (cdr co)))))))))
163       wordlist))
164   "LilyPond ReservedWords")
165
166 (defconst LilyPond-non-capitalized-reserved-words
167   (let ((wordlist '("c"))
168         (co (all-completions "" (LilyPond-add-dictionary-word ()))))
169     (progn
170       (while (> (length co) 0)
171         (setq currword (car co))
172         (if (> (length currword) 0)
173             (if (and (progn (string-match "[a-z]+" currword)
174                             (= (match-end 0) (length currword)))
175                      (string-equal (downcase currword) currword))
176                 (add-to-list 'wordlist currword)))
177         (if (string-equal "-" (car (setq co (cdr co))))
178             (while (and (> (length co) 0)
179                         (not (string-equal "-" (car (setq co (cdr co)))))))))
180       wordlist))
181   "LilyPond ReservedWords")
182
183 (defun LilyPond-check-files (derived originals extensions)
184   "Check that DERIVED is newer than any of the ORIGINALS.
185 Try each original with each member of EXTENSIONS, in all directories
186 in LilyPond-include-path."
187   (let ((found nil)
188         (regexp (concat "\\`\\("
189                         (mapconcat (function (lambda (dir)
190                                       (regexp-quote (expand-file-name dir))))
191                                    LilyPond-include-path "\\|")
192                         "\\).*\\("
193                         (mapconcat 'regexp-quote originals "\\|")
194                         "\\)\\.\\("
195                         (mapconcat 'regexp-quote extensions "\\|")
196                         "\\)\\'"))
197         (buffers (buffer-list)))
198     (while buffers
199       (let* ((buffer (car buffers))
200              (name (buffer-file-name buffer)))
201         (setq buffers (cdr buffers))
202         (if (and name (string-match regexp name))
203             (progn
204               (and (buffer-modified-p buffer)
205                    (or (not LilyPond-save-query)
206                        (y-or-n-p (concat "Save file "
207                                          (buffer-file-name buffer)
208                                          "? ")))
209                    (save-excursion (set-buffer buffer) (save-buffer)))
210               (if (file-newer-than-file-p name derived)
211                   (setq found t))))))
212     found))
213
214 (defun LilyPond-running ()
215   "Check the currently running LilyPond compiling jobs."
216   (let ((process-names (list "lilypond" "tex" "2dvi" "2ps" "2midi" 
217                              "book" "latex"))
218         (running nil))
219     (while (setq process-name (pop process-names))
220       (setq process (get-process process-name))
221       (if (and process 
222                (eq (process-status process) 'run))
223           (push process-name running)))
224     running)) ; return the running jobs
225
226 (defun LilyPond-midi-running ()
227   "Check the currently running Midi processes."
228   (let ((process-names (list "midi" "midiall"))
229         (running nil))
230     (while (setq process-name (pop process-names))
231       (setq process (get-process process-name))
232       (if (and process 
233                (eq (process-status process) 'run))
234           (push process-name running)))
235     running)) ; return the running jobs
236
237 (defun LilyPond-kill-jobs ()
238   "Kill the currently running LilyPond compiling jobs."
239   (interactive)
240   (let ((process-names (LilyPond-running))
241         (killed nil))
242     (while (setq process-name (pop process-names))
243       (quit-process (get-process process-name) t)
244       (push process-name killed))
245     killed)) ; return the killed jobs
246
247 (defun LilyPond-kill-midi ()
248   "Kill the currently running midi processes."
249   (let ((process-names (LilyPond-midi-running))
250         (killed nil))
251     (while (setq process-name (pop process-names))
252       (quit-process (get-process process-name) t)
253       (push process-name killed))
254     killed)) ; return the killed jobs
255
256 ;; URG, should only run LilyPond-compile for LilyPond
257 ;; not for tex,xdvi (ly2dvi?)
258 (defun LilyPond-compile-file (command name)
259   ;; We maybe should know what we run here (Lily, ly2dvi, tex)
260   ;; and adjust our error-matching regex ?
261   (compile-internal
262    (if (eq LilyPond-command-current 'LilyPond-command-master)
263        command
264      ;; use temporary directory for Commands on Buffer/Region
265      ;; hm.. the directory is set twice, first to default-dir
266      (concat "cd " (LilyPond-temp-directory) "; " command))
267    "No more errors" name))
268
269 ;; do we still need this, now that we're using compile-internal?
270 (defun LilyPond-save-buffer ()
271   "Save buffer and set default command for compiling."
272   (interactive)
273   (if (buffer-modified-p)
274       (progn (save-buffer)
275              (setq LilyPond-command-default "LilyPond"))))
276
277 ;;; return (dir base ext)
278 (defun split-file-name (name)
279   (let* ((i (string-match "[^/]*$" name))
280          (dir (if (> i 0) (substring name 0 i) "./"))
281          (file (substring name i (length name)))
282          (i (string-match "[^.]*$" file)))
283     (if (and
284          (> i 0)
285          (< i (length file)))
286         (list dir (substring file 0 (- i 1)) (substring file i (length file)))
287       (list dir file ""))))
288
289
290 ;; Should check whether in command-alist?
291 (defcustom LilyPond-command-default "LilyPond"
292   "Default command. Must identify a member of LilyPond-command-alist."
293
294   :group 'LilyPond
295   :type 'string)
296 ;;;(make-variable-buffer-local 'LilyPond-command-last)
297
298 (defvar LilyPond-command-current 'LilyPond-command-master)
299 ;;;(make-variable-buffer-local 'LilyPond-command-master)
300
301
302 ;; If non-nil, LilyPond-command-query will return the value of this
303 ;; variable instead of quering the user. 
304 (defvar LilyPond-command-force nil)
305
306 (defcustom LilyPond-xdvi-command "xdvi"
307   "Command used to display DVI files."
308
309   :group 'LilyPond
310   :type 'string)
311
312 (defcustom LilyPond-gv-command "gv -watch"
313   "Command used to display PS files."
314
315   :group 'LilyPond
316   :type 'string)
317
318 (defcustom LilyPond-midi-command "timidity"
319   "Command used to play MIDI files."
320
321   :group 'LilyPond
322   :type 'string)
323
324 (defcustom LilyPond-all-midi-command "timidity -ia"
325   "Command used to play MIDI files."
326
327   :group 'LilyPond
328   :type 'string)
329
330 (defun LilyPond-command-current-midi ()
331   "Play midi corresponding to the current document."
332   (interactive)
333   (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file))
334
335 (defun LilyPond-command-all-midi ()
336   "Play midi corresponding to the current document."
337   (interactive)
338   (LilyPond-command (LilyPond-command-menu "MidiAll") 'LilyPond-master-file))
339
340 (defun count-rexp (start end rexp)
341   "Print number of found regular expressions in the region."
342   (interactive "r")
343   (save-excursion
344     (save-restriction
345       (narrow-to-region start end)
346       (goto-char (point-min))
347       (count-matches rexp))))
348
349 (defun count-midi-words ()
350   "Check number of midi-scores before the curser."
351   (if (eq LilyPond-command-current 'LilyPond-command-region)
352       (count-rexp (mark t) (point) "\\\\midi")
353     (count-rexp (point-min) (point-max) "\\\\midi")))
354  
355 (defun count-midi-words-backwards ()
356   "Check number of midi-scores before the curser."
357   (if (eq LilyPond-command-current 'LilyPond-command-region)
358       (count-rexp (mark t) (point) "\\\\midi")
359     (count-rexp (point-min) (point) "\\\\midi")))
360  
361 (defun LilyPond-string-current-midi ()
362   "Check the midi file of the following midi-score in the current document."
363   (let ((fnameprefix (if (eq LilyPond-command-current 'LilyPond-command-master)
364                          (substring (LilyPond-master-file) 0 -3); suppose ".ly"
365                        LilyPond-region-file-prefix))
366         (allcount (string-to-number (substring (count-midi-words) 0 -12)))
367         (count (string-to-number (substring (count-midi-words-backwards) 0 -12))))
368     (concat  fnameprefix
369              (if (and (> allcount 1) (> count 0)) ; not first score
370                  (if (eq count allcount)          ; last score
371                      (concat "-" (number-to-string (+ count -1)))
372                    (concat "-" (number-to-string count))))
373              ".midi")))
374
375 (defun LilyPond-string-all-midi ()
376   "Return the midi files of the current document in ascending order."
377   (let ((fnameprefix (if (eq LilyPond-command-current 'LilyPond-command-master)
378                          (substring (LilyPond-master-file) 0 -3); suppose ".ly"
379                        LilyPond-region-file-prefix))
380         (allcount (string-to-number (substring (count-midi-words) 0 -12))))
381     (concat (if (> allcount 0)  ; at least one midi-score
382                 (concat fnameprefix ".midi "))
383             (if (> allcount 1)  ; more than one midi-score
384                 (concat fnameprefix "-[1-9].midi "))
385             (if (> allcount 9)  ; etc.
386                 (concat fnameprefix "-[1-9][0-9].midi"))
387             (if (> allcount 99) ; not first score
388                 (concat fnameprefix "-[1-9][0-9][0-9].midi")))))
389
390 ;; This is the major configuration variable.
391 (defcustom LilyPond-command-alist
392   ;; Should expand this to include possible keyboard shortcuts which
393   ;; could then be mapped to define-key and menu.
394   `(
395     ("Raw LilyPond" . ("lilypond-bin %s" . "LaTeX"))
396     ("TeX" . ("tex '\\nonstopmode\\input %t'" . "View"))
397
398     ("2Dvi" . ("lilypond %s" . "View"))
399     ("2PS" . ("lilypond -P %s" . "ViewPS"))
400     ("2Midi" . ("lilypond -m %s" . "View"))
401
402     ("Book" . ("lilypond-book %x" . "LaTeX"))
403     ("LaTeX" . ("latex '\\nonstopmode\\input %l'" . "View"))
404
405     ;; point-n-click (arg: exits upop USR1)
406     ("SmartView" . ("xdvi %d" . "LilyPond"))
407
408     ;; refreshes when kicked USR1
409     ("View" . (,(concat LilyPond-xdvi-command " %d") . "LilyPond"))
410     ("ViewPS" . (,(concat LilyPond-gv-command " %p") . "LilyPond"))
411
412     ;; The following are refreshed in LilyPond-command:
413     ;; - current-midi depends on cursor position and
414     ("Midi" . (,(concat LilyPond-midi-command " " (LilyPond-string-current-midi)) . "LilyPond" )) ; 
415     ;; - all-midi depends on number of midi-score.
416     ("MidiAll" . (,(concat LilyPond-all-midi-command " " (LilyPond-string-all-midi)) . "LilyPond"))
417     )
418
419   "AList of commands to execute on the current document.
420
421 The key is the name of the command as it will be presented to the
422 user, the value is a cons of the command string handed to the shell
423 after being expanded, and the next command to be executed upon
424 success.  The expansion is done using the information found in
425 LilyPond-expand-list.
426 "
427   :group 'LilyPond
428   :type '(repeat (cons :tag "Command Item"
429                        (string :tag "Key")
430                        (cons :tag "How"
431                         (string :tag "Command")
432                         (string :tag "Next Key")))))
433
434 ;; drop this?
435 (defcustom LilyPond-file-extension ".ly"
436   "*File extension used in LilyPond sources."
437   :group 'LilyPond
438   :type 'string)
439
440
441 (defcustom LilyPond-expand-alist 
442   '(
443     ("%s" . ".ly")
444     ("%t" . ".tex")
445     ("%d" . ".dvi")
446     ("%p" . ".ps")
447     ("%l" . ".tex")
448     ("%x" . ".tely")
449     ("%m" . ".midi")
450     )
451     
452   "Alist of expansion strings for LilyPond command names."
453   :group 'LilyPond
454   :type '(repeat (cons :tag "Alist item"
455                   (string :tag "Symbol")
456                   (string :tag "Expansion")))) 
457
458
459 (defcustom LilyPond-command-Show "View"
460   "*The default command to show (view or print) a LilyPond file.
461 Must be the car of an entry in `LilyPond-command-alist'."
462   :group 'LilyPond
463   :type 'string)
464   (make-variable-buffer-local 'LilyPond-command-Show)
465
466 (defcustom LilyPond-command-Print "Print"
467   "The name of the Print entry in LilyPond-command-Print."
468   :group 'LilyPond
469   :type 'string)
470
471 (defun xLilyPond-compile-sentinel (process msg)
472   (if (and process
473            (= 0 (process-exit-status process)))
474       (setq LilyPond-command-default
475               (cddr (assoc LilyPond-command-default LilyPond-command-alist)))))
476
477 ;; FIXME: shouldn't do this for stray View/xdvi
478 (defun LilyPond-compile-sentinel (buffer msg)
479   (if (string-match "^finished" msg)
480       (setq LilyPond-command-default
481             (cddr (assoc LilyPond-command-default LilyPond-command-alist)))))
482
483 ;;(make-variable-buffer-local 'compilation-finish-function)
484 (setq compilation-finish-function 'LilyPond-compile-sentinel)
485
486 (defun LilyPond-command-query (name)
487   "Query the user for what LilyPond command to use."
488   (let* ((default (cond ((if (string-equal name LilyPond-region-file-prefix)
489                              (LilyPond-check-files (concat name ".tex")
490                                                    (list name)
491                                                    (list LilyPond-file-extension))
492                            (if (verify-visited-file-modtime (current-buffer))
493                                (if (buffer-modified-p)
494                                    (if (y-or-n-p "Save buffer before next command? ")
495                                        (LilyPond-save-buffer)))
496                              (if (y-or-n-p "The command will be invoked to an already saved buffer. Revert it? ")
497                                  (revert-buffer t t)))
498                            ;;"LilyPond"
499                            LilyPond-command-default))
500                         (t LilyPond-command-default)))
501
502          (completion-ignore-case t)
503          
504          (answer (or LilyPond-command-force
505                      (completing-read
506                       (concat "Command: (default " default ") ")
507                       LilyPond-command-alist nil t nil 'LilyPond-command-history))))
508
509     ;; If the answer is "LilyPond" it will not be expanded to "LilyPond"
510     (let ((answer (car-safe (assoc answer LilyPond-command-alist))))
511       (if (and answer
512                (not (string-equal answer "")))
513           answer
514         default))))
515
516 (defun LilyPond-command-master ()
517   "Run command on the current document."
518   (interactive)
519   (LilyPond-command-select-master)
520   (LilyPond-command (LilyPond-command-query (LilyPond-master-file))
521                     'LilyPond-master-file))
522
523 (defun LilyPond-command-lilypond ()
524   "Run lilypond for the current document."
525   (interactive)
526   (LilyPond-command (LilyPond-command-menu "LilyPond") 'LilyPond-master-file)
527 )
528
529 (defun LilyPond-command-formatdvi ()
530   "Format the dvi output of the current document."
531   (interactive)
532   (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file)
533 )
534
535 (defun LilyPond-command-formatps ()
536   "Format the ps output of the current document."
537   (interactive)
538   (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file)
539 )
540
541 (defun LilyPond-command-formatmidi ()
542   "Format the midi output of the current document."
543   (interactive)
544   (LilyPond-command (LilyPond-command-menu "2Midi") 'LilyPond-master-file)
545 )
546
547 (defun LilyPond-command-smartview ()
548   "View the dvi output of current document."
549   (interactive)
550   (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file)
551 )
552
553 (defun LilyPond-command-view ()
554   "View the dvi output of current document."
555   (interactive)
556   (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file)
557 )
558
559 (defun LilyPond-command-viewps ()
560   "View the ps output of current document."
561   (interactive)
562   (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
563 )
564
565 ;; FIXME, this is broken
566 (defun LilyPond-region-file (begin end)
567   (let (
568         ;; (dir "./")
569         (dir (LilyPond-temp-directory))
570         (base LilyPond-region-file-prefix)
571         (ext LilyPond-file-extension))
572     (concat dir base ext)))
573
574 ;;; Commands on Region work if there is an appropriate '\score'.
575 (defun LilyPond-command-region (begin end)
576   "Run LilyPond on the current region."
577   (interactive "r")
578   (if (or (> begin (point-min)) (< end (point-max)))
579       (LilyPond-command-select-region))
580   (write-region begin end (LilyPond-region-file begin end) nil 'nomsg)
581   (LilyPond-command (LilyPond-command-query
582                      (LilyPond-region-file begin end))
583                     '(lambda () (LilyPond-region-file begin end)))
584   ;; Region may deactivate even if buffer was intact, reactivate?
585   ;; Currently, also deactived regions are used.
586   )
587
588 (defun LilyPond-command-buffer ()
589   "Run LilyPond on buffer."
590   (interactive)
591   (LilyPond-command-select-buffer)
592   (LilyPond-command-region (point-min) (point-max)))
593
594 (defun LilyPond-command-expand (string file)
595   (let ((case-fold-search nil))
596     (if (string-match "%" string)
597         (let* ((b (match-beginning 0))
598                (e (+ b 2))
599                (l (split-file-name file))
600                (dir (car l))
601                (base (cadr l)))
602           (LilyPond-command-expand
603            (concat (substring string 0 b)
604                    dir
605                    base
606                    (let ((entry (assoc (substring string b e)
607                                        LilyPond-expand-alist)))
608                      (if entry (cdr entry) ""))
609                    (substring string e))
610            file))
611       string)))
612
613 (defun LilyPond-shell-process (name buffer command)
614   (let ((old (current-buffer)))
615     (switch-to-buffer-other-window buffer)
616     ;; If we empty the buffer don't see messages scroll by.
617     ;; (erase-buffer)
618     
619     (start-process-shell-command name buffer command)
620     (switch-to-buffer-other-window old)))
621   
622
623 (defun LilyPond-command (name file)
624   "Run command NAME on the file you get by calling FILE.
625
626 FILE is a function return a file name.  It has one optional argument,
627 the extension to use on the file.
628
629 Use the information in LilyPond-command-alist to determine how to run the
630 command."
631   
632   (let ((entry (assoc name LilyPond-command-alist)))
633     (if entry
634         (let ((command (LilyPond-command-expand (cadr entry)
635                                                 (apply file nil)))
636               (jobs nil)
637               (job-string "no jobs"))
638           (if (member name (list "View" "ViewPS"))
639               ;; is USR1 a right signal for viewps?
640               (let ((buffer-xdvi (get-buffer-create (concat "*" name "*"))))
641                 (if LilyPond-kick-xdvi
642                   (let ((process-xdvi (get-buffer-process buffer-xdvi)))
643                     (if process-xdvi
644                         (signal-process (process-id process-xdvi) 'SIGUSR1)
645                       (LilyPond-shell-process name buffer-xdvi command)))
646                   (LilyPond-shell-process name buffer-xdvi command)))
647             (progn
648               (if (string-equal name "Midi")
649                   (progn
650                     (setq command (concat LilyPond-midi-command " " (LilyPond-string-current-midi)))
651                     (if (LilyPond-kill-midi)
652                         (setq job-string nil)))) ; either stop or start playing
653               (if (string-equal name "MidiAll")
654                   (progn
655                     (setq command (concat LilyPond-all-midi-command " " (LilyPond-string-all-midi)))
656                     (LilyPond-kill-midi))) ; stop and start playing
657               (if (and (member name (list "Midi" "MidiAll")) job-string)
658                   (if (file-newer-than-file-p
659                        (LilyPond-master-file)
660                        (concat (substring (LilyPond-master-file) 0 -3) ".midi"))
661                       (if (y-or-n-p "Midi older than source. Reformat midi?")
662                           (progn
663                             (LilyPond-command-formatmidi)
664                             (while (LilyPond-running)
665                               (message "Starts playing midi once it is built.")
666                               (sit-for 0 100))))))
667               (if (member name (list "LilyPond" "TeX" "2Midi" "2PS" "2Dvi" 
668                                      "Book" "LaTeX"))
669                   (if (setq jobs (LilyPond-running))
670                       (progn
671                         (setq job-string "Process") ; could also suggest compiling after process has ended
672                         (while jobs
673                           (setq job-string (concat job-string " \"" (pop jobs) "\"")))
674                         (setq job-string (concat job-string " is already running; kill it to proceed "))
675                         (if (y-or-n-p job-string)
676                             (progn
677                               (setq job-string "no jobs")
678                               (LilyPond-kill-jobs)
679                               (while (LilyPond-running)
680                                 (sit-for 0 100)))
681                           (setq job-string nil)))))
682
683               (setq LilyPond-command-default name)
684               (if (string-equal job-string "no jobs")
685                   (LilyPond-compile-file command name))))))))
686           
687 (defun LilyPond-mark-active ()
688   "Check if there is an active mark."
689   (and transient-mark-mode
690        (if (string-match "XEmacs\\|Lucid" emacs-version) (mark) mark-active)))
691
692 (defun LilyPond-temp-directory ()
693   "Temporary file directory for Commands on Region."
694   (interactive)
695   (if (string-match "XEmacs\\|Lucid" emacs-version)
696       (concat (temp-directory) "/")
697     temporary-file-directory))
698
699 ;;; Keymap
700
701 (defvar LilyPond-mode-map ()
702   "Keymap used in `LilyPond-mode' buffers.")
703
704 ;; Note:  if you make changes to the map, you must do
705 ;;    M-x set-variable LilyPond-mode-map nil
706 ;;    M-x eval-buffer
707 ;;    M-x LilyPond-mode
708 ;; to let the changest take effect
709
710 (if LilyPond-mode-map
711     ()
712   (setq LilyPond-mode-map (make-sparse-keymap))
713   ;; Put keys to LilyPond-command-alist and fetch them from there somehow.
714   (define-key LilyPond-mode-map "\C-c\C-l" 'LilyPond-command-lilypond)
715   (define-key LilyPond-mode-map "\C-c\C-r" 'LilyPond-command-region)
716   (define-key LilyPond-mode-map "\C-c\C-b" 'LilyPond-command-buffer)
717   (define-key LilyPond-mode-map "\C-c\C-k" 'LilyPond-kill-jobs)
718   (define-key LilyPond-mode-map "\C-c\C-c" 'LilyPond-command-master)
719   (define-key LilyPond-mode-map "\C-cm" 'LilyPond-command-formatmidi)
720   (define-key LilyPond-mode-map "\C-c\C-d" 'LilyPond-command-formatdvi)
721   (define-key LilyPond-mode-map "\C-c\C-f" 'LilyPond-command-formatps)
722   (define-key LilyPond-mode-map "\C-c\C-s" 'LilyPond-command-smartview)
723   (define-key LilyPond-mode-map "\C-c\C-v" 'LilyPond-command-view)
724   (define-key LilyPond-mode-map "\C-c\C-p" 'LilyPond-command-viewps)
725   (define-key LilyPond-mode-map [(control c) return] 'LilyPond-command-current-midi)
726   (define-key LilyPond-mode-map [(control c) (control return)] 'LilyPond-command-all-midi)
727   (define-key LilyPond-mode-map "\C-x\C-s" 'LilyPond-save-buffer)
728   (define-key LilyPond-mode-map "\C-cf" 'font-lock-fontify-buffer)
729   (define-key LilyPond-mode-map "\C-ci" 'LilyPond-insert-tag-current)
730   ;; the following will should be overriden by Lilypond Quick Insert Mode
731   (define-key LilyPond-mode-map "\C-cq" 'LilyPond-quick-insert-mode)
732   (define-key LilyPond-mode-map "\C-c;" 'LilyPond-comment-region)
733   (define-key LilyPond-mode-map ")" 'LilyPond-electric-close-paren)
734   (define-key LilyPond-mode-map ">" 'LilyPond-electric-close-paren)
735   (define-key LilyPond-mode-map "}" 'LilyPond-electric-close-paren)
736   (define-key LilyPond-mode-map "]" 'LilyPond-electric-close-paren)
737   (if (string-match "XEmacs\\|Lucid" emacs-version)
738       (define-key LilyPond-mode-map [iso-left-tab] 'LilyPond-autocompletion)
739     (define-key LilyPond-mode-map [iso-lefttab] 'LilyPond-autocompletion))
740   (define-key LilyPond-mode-map "\C-c\t" 'LilyPond-info-index-search)
741   )
742
743 ;;; Menu Support
744
745 ;;; This mode was originally LilyPond-quick-note-insert by Heikki Junes.
746 ;;; The original version has been junked since CVS-1.97,
747 ;;; in order to merge the efforts done by Nicolas Sceaux.
748 ;;; LilyPond Quick Insert Mode is a major mode, toggled by C-c q.
749 (defun LilyPond-quick-insert-mode ()
750   "Insert notes with fewer key strokes by using a simple keyboard piano."
751   (interactive)
752   (progn 
753     (message "Invoke (C-c q) from keyboard. If you still see this message,") (sit-for 5 0)
754     (message "then you have not installed LilyPond Quick Insert Mode (lyqi).") (sit-for 5 0)
755     (message "Download lyqi from http://nicolas.sceaux.free.fr/lilypond/lyqi.html,") (sit-for 5 0)
756     (message "see installation instructions from lyqi's README -file.") (sit-for 5 0)
757     (message "You need also eieio (Enhanced Integration of Emacs Interpreted Objects).") (sit-for 5 0)
758     (message "Download eieio from http://cedet.sourceforge.net/eieio.shtml,") (sit-for 5 0)
759     (message "see installation instructions from eieio's INSTALL -file.") (sit-for 5 0)
760     (message "")
761     ))    
762
763 (defun LilyPond-pre-word-search ()
764   "Fetch the alphabetic characters and \\ in front of the cursor."
765   (let ((pre "")
766         (prelen 0)
767         (ch (char-before (- (point) 0))))
768     (while (and ch (or (and (>= ch 65) (<= ch 90))  ; not bolp, A-Z
769                        (and (>= ch 97) (<= ch 122)) ; a-z
770                        (= ch 92)))                  ; \\
771       (setq pre (concat (char-to-string ch) pre))
772       (setq prelen (+ prelen 1))
773       (setq ch (char-before (- (point) prelen))))
774     pre))
775
776 (defun LilyPond-post-word-search ()
777   "Fetch the alphabetic characters behind the cursor."
778   (let ((post "")
779         (postlen 0)
780         (ch (char-after (+ (point) 0))))
781     (while (and ch (or (and (>= ch 65) (<= ch 90))    ; not eolp, A-Z
782                        (and (>= ch 97) (<= ch 122)))) ; a-z
783       (setq post (concat post (char-to-string ch)))
784       (setq postlen (+ postlen 1))
785       (setq ch (char-after (+ (point) postlen))))
786     post))
787
788 (defun LilyPond-autocompletion ()
789   "Show completions in mini-buffer for the given word."
790   (interactive)
791   (let ((pre (LilyPond-pre-word-search))
792         (post (LilyPond-post-word-search))
793         (compsstr ""))
794     ;; insert try-completion and show all-completions
795     (if (> (length pre) 0)
796         (progn
797           (setq trycomp (try-completion pre (LilyPond-add-dictionary-word ())))
798           (if (char-or-string-p trycomp)
799               (if (string-equal (concat pre post) trycomp)
800                   (goto-char (+ (point) (length post)))
801                 (progn
802                   (delete-region (point) (+ (point) (length post)))
803                   (insert (substring trycomp (length pre) nil))))
804             (progn
805               (delete-region (point) (+ (point) (length post)))
806               (font-lock-fontify-buffer))) ; only inserting fontifies
807         
808         (setq complist (all-completions pre (LilyPond-add-dictionary-word ())))
809         (while (> (length complist) 0)
810           (setq compsstr (concat compsstr "\"" (car complist) "\" "))
811           (setq complist (cdr complist)))
812         (message compsstr) 
813         (sit-for 0 100)))))
814
815 (defun LilyPond-info ()
816   "Launch Info for lilypond."
817   (interactive)
818   (info "lilypond"))
819   
820 (defun LilyPond-music-glossary-info ()
821   "Launch Info for music-glossary."
822   (interactive)
823   (info "music-glossary"))
824
825 (defun LilyPond-internals-info ()
826   "Launch Info for lilypond-internals."
827   (interactive)
828   (info "lilypond-internals"))
829   
830 (defun LilyPond-info-index-search ()
831   "In `*info*'-buffer, launch `info lilypond --index-search word-under-cursor'"
832   (interactive)
833   (let ((str (concat (LilyPond-pre-word-search) (LilyPond-post-word-search))))
834     (if (and (> (length str) 0) 
835              (string-equal (substring str 0 1) "\\"))
836         (setq str (substring str 1 nil)))
837     (LilyPond-info)
838     (Info-index str)))
839
840 (defun LilyPond-insert-tag-current (&optional word)
841   "Set the current tag to be inserted."
842   (interactive)
843   (if word
844       (setq LilyPond-insert-tag-current word))
845   (if (memq LilyPond-insert-tag-current LilyPond-menu-keywords)
846       (LilyPond-insert-tag)
847     (message "No tag was selected from LilyPond->Insert tag-menu.")))
848
849 (defun LilyPond-insert-tag ()
850   "Insert syntax for given tag. The definitions are in LilyPond-words-filename."
851   (interactive)
852   (setq b (find-file-noselect (LilyPond-words-filename) t t))
853   (let ((word LilyPond-insert-tag-current)
854         (found nil)
855         (p nil)
856         (query nil)
857         (m (set-marker (make-marker) 1 (get-buffer b)))
858         (distance (if (LilyPond-mark-active)
859                       (abs (- (mark-marker) (point-marker))) 0))
860        )
861    ;; find the place first
862    (if (LilyPond-mark-active)
863        (goto-char (min (mark-marker) (point-marker))))
864    (while (and (not found) (> (buffer-size b) (marker-position m)))
865     (setq copy (car (copy-alist (list (eval (symbol-name (read m)))))))
866     (if (string-equal word copy) (setq found t)))
867    (if found (insert word))
868    (if (> (buffer-size b) (marker-position m))
869        (setq copy (car (copy-alist (list (eval (symbol-name (read m))))))))
870    (if (not (string-equal "-" copy)) 
871        (setq found nil))
872    (while (and found (> (buffer-size b) (marker-position m)))
873     ;; find next symbol
874     (setq copy (car (copy-alist (list (eval (symbol-name (read m)))))))
875     ;; check whether it is the word, or the word has been found
876     (cond 
877      ((string-equal "-" copy) (setq found nil))
878      ((string-equal "%" copy) (insert " " (read-string "Give Arguments: ")))
879      ((string-equal "_" copy) 
880       (progn 
881        (setq p (point))
882        (goto-char (+ p distance))))
883      ((string-equal "\?" copy) (setq query t))
884      ((string-equal "\!" copy) (setq query nil))
885      ((string-equal "\\n" copy) 
886       (if (not query)
887        (progn (LilyPond-indent-line) (insert "\n") (LilyPond-indent-line))))
888      ((string-equal "{" copy) 
889       (if (not query) 
890           (progn (insert " { "))))
891      ((string-equal "}" copy)
892       (if (not query)
893        (progn (insert " } ") (setq query nil) )))
894      ((not query)
895       (insert copy))
896      (query
897       (if (y-or-n-p (concat "Proceed with `" copy "'? "))
898        (progn (insert copy) (setq query nil))))
899    ))
900    (if p (goto-char p))
901    (kill-buffer b))
902 )
903
904 (defun LilyPond-command-menu-entry (entry)
905   ;; Return LilyPond-command-alist ENTRY as a menu item.
906   (let ((name (car entry)))
907     (cond ((and (string-equal name LilyPond-command-Print)
908                 LilyPond-printer-list)
909            (let ((command LilyPond-print-command)
910                  (lookup 1))
911              (append (list LilyPond-command-Print)
912                      (mapcar 'LilyPond-command-menu-printer-entry
913                              LilyPond-printer-list))))
914           (t
915            (vector name (list 'LilyPond-command-menu name) t)))))
916
917
918 (easy-menu-define LilyPond-command-menu
919   LilyPond-mode-map
920   "Menu used in LilyPond mode."
921   (append '("Command")
922           '(("Command on"
923              [ "Master File" LilyPond-command-select-master
924                :keys "C-c C-c" :style radio
925                :selected (eq LilyPond-command-current 'LilyPond-command-master) ]
926              [ "Buffer" LilyPond-command-select-buffer
927                :keys "C-c C-b" :style radio
928                :selected (eq LilyPond-command-current 'LilyPond-command-buffer) ]
929              [ "Region" LilyPond-command-select-region
930                :keys "C-c C-r" :style radio
931                :selected (eq LilyPond-command-current 'LilyPond-command-region) ]))
932 ;;;       (let ((file 'LilyPond-command-on-current))
933 ;;;         (mapcar 'LilyPond-command-menu-entry LilyPond-command-alist))
934 ;;; Some kind of mapping which includes :keys might be more elegant
935 ;;; Put keys to LilyPond-command-alist and fetch them from there somehow.
936           '([ "LilyPond" LilyPond-command-lilypond t])
937           '([ "TeX" (LilyPond-command (LilyPond-command-menu "TeX") 'LilyPond-master-file) ])
938           '([ "2Dvi" LilyPond-command-formatdvi t])
939           '([ "2PS" LilyPond-command-formatps t])
940           '([ "2Midi" LilyPond-command-formatmidi t])
941           '([ "Book" (LilyPond-command (LilyPond-command-menu "Book") 'LilyPond-master-file) ])
942           '([ "LaTeX" (LilyPond-command (LilyPond-command-menu "LaTeX") 'LilyPond-master-file) ])
943           '([ "Kill jobs" LilyPond-kill-jobs t])
944           '("-----")
945           '([ "SmartView" LilyPond-command-smartview t])
946           '([ "View" LilyPond-command-view t])
947           '([ "ViewPS" LilyPond-command-viewps t])
948           '("-----")
949           '([ "Midi (toggle)" LilyPond-command-current-midi t])
950           '([ "Midi all" LilyPond-command-all-midi t])
951           ))
952
953 (defun LilyPond-menu-keywords-item (arg)
954   "Make vector for LilyPond-mode-keywords."
955   (vector arg (list 'LilyPond-insert-tag-current arg) :style 'radio :selected (list 'eq 'LilyPond-insert-tag-current arg)))
956
957 (defun LilyPond-menu-keywords ()
958   "Make Insert Tag menu. 
959
960 The Insert Tag -menu is splitted into parts if it is long enough."
961
962   (let ((li (mapcar 'LilyPond-menu-keywords-item LilyPond-menu-keywords))
963         (w (round (sqrt (length LilyPond-menu-keywords))))
964         (splitted '())
965         (imin 0) imax lw rw)
966     (while (< imin (length LilyPond-menu-keywords))
967       (setq imax (- (min (+ imin w) (length LilyPond-menu-keywords)) 1))
968       (setq lw (nth imin LilyPond-menu-keywords)) 
969       (setq rw (nth imax LilyPond-menu-keywords))
970       (add-to-list 'splitted
971          (let ((l (list (concat (substring lw 0 (min 7 (length lw))) 
972                                 " ... " 
973                                 (substring rw 0 (min 7 (length rw)))))))
974            (while (<= imin imax)
975              (add-to-list 'l (nth imin li))
976              (setq imin (1+ imin)))
977            (reverse l))))
978     (if (> (length LilyPond-menu-keywords) 12) (reverse splitted) li)))
979
980 ;;; LilyPond-mode-menu should not be interactive, via "M-x LilyPond-<Tab>"
981 (easy-menu-define LilyPond-mode-menu
982   LilyPond-mode-map
983   "Menu used in LilyPond mode."
984   (append '("LilyPond")
985           '(["Add index menu" LilyPond-add-imenu-menu])
986           (list (cons "Insert tag" 
987                 (cons ["Previously selected" LilyPond-insert-tag-current t] 
988                 (cons "-----"
989                       (LilyPond-menu-keywords)))))
990           '(("Miscellaneous"
991              ["Autocompletion"   LilyPond-autocompletion t]
992              ["(Un)comment Region" LilyPond-comment-region t]
993              ["Refontify buffer" font-lock-fontify-buffer t]
994              "-----"
995              ["Quick Insert Mode"  LilyPond-quick-insert-mode :keys "C-c q"]
996              ))
997           '(("Info"
998              ["LilyPond" LilyPond-info t]
999              ["LilyPond index-search" LilyPond-info-index-search t]
1000              ["Music Glossary" LilyPond-music-glossary-info t]
1001              ["LilyPond internals" LilyPond-internals-info t]
1002              ))
1003           ))
1004
1005 (defconst LilyPond-imenu-generic-re "^\\([a-zA-Z]+\\) *="
1006   "Regexp matching Identifier definitions.")
1007
1008 (defvar LilyPond-imenu-generic-expression
1009   (list (list nil LilyPond-imenu-generic-re 1))
1010   "Expression for imenu")
1011
1012 (defun LilyPond-command-select-master ()
1013   (interactive)
1014   (message "Next command will be on the master file")
1015   (setq LilyPond-command-current 'LilyPond-command-master))
1016
1017 (defun LilyPond-command-select-buffer ()
1018   (interactive)
1019   (message "Next command will be on the buffer")
1020   (setq LilyPond-command-current 'LilyPond-command-buffer))
1021
1022 (defun LilyPond-command-select-region ()
1023   (interactive)
1024   (message "Next command will be on the region")
1025   (setq LilyPond-command-current 'LilyPond-command-region))
1026
1027 (defun LilyPond-command-menu (name)
1028   ;; Execute LilyPond-command-alist NAME from a menu.
1029   (let ((LilyPond-command-force name))
1030     (if (eq LilyPond-command-current 'LilyPond-command-region)
1031         (if (eq (mark t) nil)
1032             (progn (message "The mark is not set now") (sit-for 0 500))
1033           (progn (if (not (not (LilyPond-mark-active)))
1034                      (progn (message "Region is not active, using region between inactive mark and current point.") (sit-for 0 500)))
1035                  (LilyPond-command-region (mark t) (point))))
1036       (funcall LilyPond-command-current))))
1037
1038 (defun LilyPond-add-imenu-menu ()
1039   (interactive)
1040   "Add an imenu menu to the menubar."
1041   (if (not LilyPond-imenu)
1042       (progn
1043         (imenu-add-to-menubar "Index")
1044         (redraw-frame (selected-frame))
1045         (setq LilyPond-imenu t))
1046     (message "%s" "LilyPond-imenu already exists.")))
1047 (put 'LilyPond-add-imenu-menu 'menu-enable '(not LilyPond-imenu))
1048
1049 (defun LilyPond-mode ()
1050   "Major mode for editing LilyPond music files.
1051
1052 This mode knows about LilyPond keywords and line comments, not about
1053 indentation or block comments.  It features easy compilation, error
1054 finding and viewing of a LilyPond source buffer or region.
1055
1056 COMMANDS
1057 \\{LilyPond-mode-map}
1058 VARIABLES
1059
1060 LilyPond-command-alist\t\talist from name to command
1061 LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"
1062   (interactive)
1063   ;; set up local variables
1064   (kill-all-local-variables)
1065
1066   (make-local-variable 'font-lock-defaults)
1067   (setq font-lock-defaults '(LilyPond-font-lock-keywords))
1068
1069   ;; string and comments are fontified explicitly
1070   (make-local-variable 'font-lock-keywords-only)
1071   (setq font-lock-keywords-only t)
1072
1073   ;; Multi-line font-locking needs Emacs 21.1 or newer.
1074   ;; For older versions there is hotkey "C-c f".
1075   (make-local-variable 'font-lock-multiline) 
1076   (setq font-lock-multiline t) 
1077
1078   (make-local-variable 'paragraph-separate)
1079   (setq paragraph-separate "^[ \t]*$")
1080
1081   (make-local-variable 'paragraph-start)
1082   (setq paragraph-start "^[ \t]*$")
1083
1084   (make-local-variable 'comment-start)
1085   (setq comment-start "%")
1086
1087   (make-local-variable 'comment-start-skip)
1088   (setq comment-start-skip "%{? *")
1089
1090   (make-local-variable 'comment-end)
1091   (setq comment-end "")
1092
1093   (make-local-variable 'block-comment-start)
1094   (setq block-comment-start "%{")
1095
1096   (make-local-variable 'block-comment-end)  
1097   (setq block-comment-end   "%}")
1098
1099   (make-local-variable 'indent-line-function)
1100   (setq indent-line-function 'LilyPond-indent-line)
1101
1102   (LilyPond-mode-set-syntax-table '(?\< ?\> ?\{ ?\}))
1103   (setq major-mode 'LilyPond-mode)
1104   (setq mode-name "LilyPond")
1105   (setq local-abbrev-table LilyPond-mode-abbrev-table)
1106   (use-local-map LilyPond-mode-map)
1107
1108   ;; In XEmacs imenu was synched up with: FSF 20.4
1109   (make-local-variable 'imenu-generic-expression)
1110   (setq imenu-generic-expression LilyPond-imenu-generic-expression)
1111   ;; (imenu-add-to-menubar "Index") ; see LilyPond-add-imenu-menu
1112
1113   ;; In XEmacs one needs to use 'easy-menu-add'.
1114   (if (string-match "XEmacs\\|Lucid" emacs-version)
1115       (progn
1116         (easy-menu-add LilyPond-mode-menu)
1117         (easy-menu-add LilyPond-command-menu)))
1118
1119   ;; Use Command on Region even for inactive mark (region).
1120   (if (string-match "XEmacs\\|Lucid" emacs-version)
1121       (setq zmacs-regions nil)
1122     (setq mark-even-if-inactive t))
1123
1124   ;; Context dependent syntax tables in LilyPond-mode
1125   (make-local-hook 'post-command-hook) ; XEmacs requires
1126   (add-hook 'post-command-hook 'LilyPond-mode-context-set-syntax-table nil t)
1127
1128   ;; Turn on paren-mode buffer-locally, i.e., in LilyPond-mode
1129   (if (string-match "XEmacs\\|Lucid" emacs-version)
1130       (progn
1131         (make-local-variable 'paren-mode)
1132         (paren-set-mode 'paren)
1133         (make-local-variable 'blink-matching-paren)
1134         (setq blink-matching-paren t)
1135         )
1136     (progn
1137       (make-local-variable 'blink-matching-paren-on-screen)
1138       (setq blink-matching-paren-on-screen t)
1139      ))
1140
1141   ;; run the mode hook. LilyPond-mode-hook use is deprecated
1142   (run-hooks 'LilyPond-mode-hook))
1143
1144 (defun LilyPond-version ()
1145   "Echo the current version of `LilyPond-mode' in the minibuffer."
1146   (interactive)
1147   (message "Using `LilyPond-mode' version %s" LilyPond-version))
1148
1149 (load-library "lilypond-font-lock")
1150 (load-library "lilypond-indent")
1151
1152 (provide 'lilypond-mode)
1153 ;;; lilypond-mode.el ends here
1154