+ (setq LilyPond-mode-map (make-sparse-keymap))
+ (define-key LilyPond-mode-map "\C-c\C-r" 'LilyPond-command-region)
+ (define-key LilyPond-mode-map "\C-c\C-b" 'LilyPond-command-buffer)
+ (define-key LilyPond-mode-map "\C-c\C-k" 'LilyPond-kill-job)
+ (define-key LilyPond-mode-map "\C-c\C-c" 'LilyPond-command-master)
+ )
+
+;;; Menu Support
+
+(defun LilyPond-command-menu-entry (entry)
+ ;; Return LilyPond-command-alist ENTRY as a menu item.
+ (let ((name (car entry)))
+ (cond ((and (string-equal name LilyPond-command-Print)
+ LilyPond-printer-list)
+ (let ((command LilyPond-print-command)
+ (lookup 1))
+ (append (list LilyPond-command-Print)
+ (mapcar 'LilyPond-command-menu-printer-entry
+ LilyPond-printer-list))))
+ (t
+ (vector name (list 'LilyPond-command-menu name) t)))))
+
+
+(easy-menu-define LilyPond-mode-menu
+ LilyPond-mode-map
+ "Menu used in LilyPond mode."
+ (append '("Command")
+ '(("Command on"
+ [ "Master File" LilyPond-command-select-master
+ :keys "C-c C-c" :style radio
+ :selected (eq LilyPond-command-current 'LilyPond-command-master) ]
+ [ "Buffer" LilyPond-command-select-buffer
+ :keys "C-c C-b" :style radio
+ :selected (eq LilyPond-command-current 'LilyPond-command-buffer) ]
+ [ "Region" LilyPond-command-select-region
+ :keys "C-c C-r" :style radio
+ :selected (eq LilyPond-command-current 'LilyPond-command-region) ]))
+ (let ((file 'LilyPond-command-on-current))
+ (mapcar 'LilyPond-command-menu-entry LilyPond-command-alist))))
+
+
+(defconst LilyPond-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="
+ "Regexp matching Identifier definitions.")
+
+(defvar LilyPond-imenu-generic-expression
+ (list (list nil LilyPond-imenu-generic-re 1))
+ "Expression for imenu")
+
+(defun LilyPond-command-select-master ()
+ (interactive)
+ (message "Next command will be on the master file")
+ (setq LilyPond-command-current 'LilyPond-command-master))
+
+(defun LilyPond-command-select-buffer ()
+ (interactive)
+ (message "Next command will be on the buffer")
+ (setq LilyPond-command-current 'LilyPond-command-buffer))
+
+(defun LilyPond-command-select-region ()
+ (interactive)
+ (message "Next command will be on the region")
+ (setq LilyPond-command-current 'LilPond-command-region))
+
+(defun LilyPond-command-menu (name)
+ ;; Execute LilyPond-command-alist NAME from a menu.
+ (let ((LilyPond-command-force name))
+ (funcall LilyPond-command-current)))
+
+(defun LilyPond-mode ()
+ "Major mode for editing LilyPond music files.
+
+This mode knows about LilyPond keywords and line comments, not about
+indentation or block comments. It features easy compilation, error
+finding and viewing of a LilyPond source buffer or region.
+
+COMMANDS
+\\{LilyPond-mode-map}
+VARIABLES
+
+LilyPond-command-alist\t\talist from name to command
+LilyPond-xdvi-command\t\tcommand to display dvi files -- bit superfluous"