]> git.donarmstrong.com Git - lilypond.git/blobdiff - lilypond-mode.el
patch::: 1.3.37.jcn1
[lilypond.git] / lilypond-mode.el
index 962659fe25a1b721d3a6fe37d870da92c5fce585..8a4c7ccf6fa0c5419c6403b68fd8e3e67ff073ad 100644 (file)
 ;; organization, is hereby granted, provided that the above copyright
 ;; notice and this paragraph appear in all copies.
 
-;; Sigh
-
-;; This is a cannabalised version of python-mode.el (HWN)
-;; Added lily-eval-buffer -- jcn
+;; This started out as a cannabalised version of python-mode.el, by hwn
+;; For changes see the LilyPond ChangeLog
 ;;
 ;; TODO: 
 ;; * lily/ly/lilypond?
-;; * fix lily-keymap 
-;; * mail Tim Peters about silly copyright (notice)?
 ;; * syntax
 ;;   - should handle block comments too.
 ;;   - handle lexer modes (\header, \melodic, \lyric) etc.
   "Run LilyPond on buffer."
   (interactive)
   (let ((buffer (buffer-name)))
-    (if buffer-file-name
+    (if (buffer-file-name)
        (progn
          (lily-save-buffer)
-         (lily-compile-file lily-command lily-parameters buffer))
+         (lily-compile-file lily-command lily-parameters (buffer-file-name)))
       (progn
        (error "Buffer %s is not associated with a file" buffer)
        (lily-eval-region (min-point) (max-point))))))
 (defun lily-eval-region (start end)
   "Run LilyPond on region."
   (interactive "r")
-  ;;  (message "saving current buffer to temporary file ...")
-  ;;  (write-file tmp-file-with-directory)
-  ;;(lily-compile-file lily-command "--init=init.fly" "-")
-  (let ((basename "emacs-lily"))
-    (write-region start end (concat basename ".fly") nil 'nomsg)
-    (lily-compile-file lily-command lily-parameters basename)))
+  (let ((basename "emacs-lily")
+       (suffix (if (string-match "^[\\]score" (buffer-substring start end))
+                   ".ly"
+                 (if (< 50 (abs (- start end)))
+                     ".fly"
+                     ".sly"))))
+    (write-region start end (concat basename suffix) nil 'nomsg)
+    (lily-compile-file lily-command lily-parameters (concat basename suffix))))
 
 (defun lily-running ()
   (let ((process (get-process "lilypond")))
 (defvar lily-mode-map ()
   "Keymap used in `lilypond-mode' buffers.")
 
+;; Note:  if you make changes to the map, you must do
+;;    M-x set-variable lily-mode-map nil
+;;    M-x eval-buffer
+;;    M-x lilypond-mode
+;; to let the changest take effect
 (if lily-mode-map
     ()
   (setq lily-mode-map (make-sparse-keymap))
-  ;; this doesn't work, here
-  ;; I would very much like to have [f9], globally defined as 'compile,
-  ;; being overidden to 'lily-eval-buffer for LilyPond buffers
-  (define-key lily-mode-map [C-f9] 'lily-eval-buffer)
-  ;; urg
-  ;; add to .emacs:
-  ;; (global-set-key [C-f9] 'lily-eval-buffer)
+  (define-key lily-mode-map [f9] 'lily-eval-buffer)
+  (define-key lily-mode-map [f10] 'lily-xdvi-buffer)
+  (define-key lily-mode-map [S-f9] 'lily-eval-region)
+  (define-key lily-mode-map [S-f10] 'lily-xdvi-region)
   ) 
 
 (defun lilypond-mode ()