-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathlyqi-compile-commands.el
More file actions
79 lines (64 loc) · 2.36 KB
/
lyqi-compile-commands.el
File metadata and controls
79 lines (64 loc) · 2.36 KB
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Compilation commands
;;;
(eval-when-compile (require 'cl))
;;;
;;; Master file, used for compilation
;;; - if `lyqi:buffer-master-file' (which is buffer local) is non-NIL,
;;; use its value;
;;; - if `lyqi:global-master-file' is non-NIL, use its value;
;;; - if curent-buffer is a .ly file, use this file.
;;;
(defvar lyqi:global-master-file nil
"Master .ly file for LilyPond compilation (if
`lyqi:buffer-master-file' is NIL).")
(defvar lyqi:buffer-master-file nil
"Master .ly file for LilyPond compilation for current
buffer (overrides `lyqi:global-master-file').")
(defun lyqi:master-file ()
(let ((pathname (buffer-file-name)))
(or (and (string-equal (file-name-extension pathname) "ly")
pathname)
lyqi:buffer-master-file
lyqi:global-master-file)))
(defun lyqi:defined-master-file ()
(and (not (string-equal (file-name-extension (buffer-file-name)) "ly"))
(or lyqi:buffer-master-file
lyqi:global-master-file)))
(defun lyqi:set-buffer-master-file (filename)
(interactive "fBuffer master file:")
(setq lyqi:buffer-master-file filename))
(defun lyqi:set-global-master-file (filename)
(interactive "fGlobal master file:")
(setq lyqi:global-master-file filename))
(defun lyqi:unset-master-file ()
(interactive "")
(cond (lyqi:buffer-master-file
(setq lyqi:buffer-master-file nil))
(lyqi:global-master-file
(setq lyqi:global-master-file nil))))
;;;
;;; LilyPond compilation
;;;
(defun lyqi:compile-command (command ext)
(when (lyqi:master-file)
(let* ((pathname (file-truename (lyqi:master-file)))
(directory (file-name-directory pathname))
(basename (file-name-sans-extension (file-name-nondirectory pathname)))
(command (format "cd %s; %s %s.%s"
(shell-quote-argument directory)
command
(shell-quote-argument basename)
ext)))
(compilation-start command))))
(defun lyqi:compile-ly ()
(interactive)
(lyqi:compile-command lyqi:lilypond-command "ly"))
(defun lyqi:open-pdf ()
(interactive)
(lyqi:compile-command lyqi:pdf-command "pdf"))
(defun lyqi:open-midi ()
(interactive)
(lyqi:compile-command lyqi:midi-command "midi"))
(provide 'lyqi-compile-commands)