-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlilypond-hook.el
97 lines (81 loc) · 3.08 KB
/
lilypond-hook.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
;;; lilypond-hook.el --- Automatically display and play lilypond Score
;;; on save action (Currently tested on Mac OSX only)
;; Copyright (C) 2011 Martyn Jago
;; Author: Martyn Jago
;; Keywords: LilyPond, Score, , Engraving, Music
;; URL: http://github.com/mjago/lilypond-hook.el
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; This package provides an Emacs post-save hook to automate the generation
;; and display of Music Score performed in LilyPond (pdf) and also plays the
;; Score in question via Midi player. These automated actions take place on
;; Saving any document with the extension ".ly"
;;; Customizable Options:
;;
;; Below are customizable option list:
;;; Installation:
;;
;; Put lilypond-hook.el in your load-path.
;;
;; Add the following to your ~/.emacs startup file.
;;
;; (require 'lilypond-hook)
;;
;;; Location of LilyPond must be set...
(setq ly-app-path "/Applications/lilypond.app/Contents/Resources/bin/lilypond")
(defun mj-execute-lilypond ()
(let ((ly-temp-file (buffer-file-name))
(ly-eps nil))
(message "Compiling LilyPond...")
(save-excursion
(switch-to-buffer-other-window "*lilypond*")
(set-buffer "*lilypond*")
(erase-buffer)
(call-process
ly-app-path nil
"*lilypond*"
t
(if ly-eps
"-dbackend=eps"
"")
ly-temp-file)
(goto-char (point-min))
(if (not (search-forward "error:" nil t))
(progn
(shell-command
(concat "open "
(file-name-nondirectory
(file-name-sans-extension
ly-temp-file))
".pdf"))
(shell-command
(concat "open "
(file-name-nondirectory
(file-name-sans-extension
ly-temp-file))
".midi")))
(message "Error in Compilation"))
(switch-to-buffer-other-window
(file-name-nondirectory ly-temp-file)))))
(defun lilypond-hook ()
(interactive)
(let ((ly-temp-file (buffer-file-name)))
(when (string-match "ly" (file-name-nondirectory
(file-name-extension
ly-temp-file)))
(mj-execute-lilypond))))
(add-hook 'after-save-hook 'lilypond-hook)
(provide 'lilypond-hook)
;;; lilypond-hook.el ends here