-(defun xLilyPond-compile-sentinel (process msg)
- (if (and process
- (= 0 (process-exit-status process)))
- (setq LilyPond-command-next
- (or (cddr (assoc LilyPond-command-next LilyPond-command-alist))
- LilyPond-command-default))))
-
-;; FIXME: shouldn't do this for stray View/xdvi
-(defun LilyPond-compile-sentinel (buffer msg)
- (if (string-match "^finished" msg)
- (setq LilyPond-command-next
- (or (cddr (assoc LilyPond-command-next LilyPond-command-alist))
- LilyPond-command-default))))
-
-;;(make-variable-buffer-local 'compilation-finish-function)
-(setq compilation-finish-function 'LilyPond-compile-sentinel)
+(defun LilyPond-find-required-command (command file)
+ "Find the first command in the chain that is needed to run
+ (input file is newer than the output file)"
+ (let* ((entry (cdr (assoc command LilyPond-command-alist)))
+ (next-command (nth 3 entry)))
+ (if (null next-command)
+ command
+ (let* ((src-string (nth 1 entry))
+ (input (LilyPond-command-expand src-string file))
+ (output (LilyPond-command-expand (nth 2 entry) file)))
+ (if (or (file-newer-than-file-p input output)
+ (and (equal "%s" src-string)
+ (not (equal (buffer-name) file))
+ (file-newer-than-file-p (buffer-name)
+ output)))
+ command
+ (LilyPond-find-required-command next-command file))))))