lisp/ob-lilypond.el: refactor org-babel-lilypond-compile-lilyfile

* ob-lilypond.el (org-babel-lilypond-compile-lilyfile):
Correct compilation message.
Remove superfluous local variables.
Remove unused ad-hoc debugging TEST parameter.

* test-ob-lilypond.el (ob-lilypond/ly-compile-lilyfile):
Locally bind variables which may generate output files.
Refactor to account for removed TEST parameter.
This commit is contained in:
Nicholas Vollmer 2023-08-24 09:32:27 -04:00 committed by Ihor Radchenko
parent 13e4ee7371
commit 4fe52fc8ac
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
3 changed files with 35 additions and 34 deletions

View File

@ -304,6 +304,9 @@ setting the ~STYLE~ property for each sub-task.
The change is breaking when ~org-use-property-inheritance~ is set to ~t~.
*** ~org-babel-lilypond-compile-lilyfile~ ignores optional second argument
The =TEST= parameter is better served by Emacs debugging tools.
** New and changed options
*** ~org-export-smart-quotes-alist~ is now a custom option

View File

@ -235,27 +235,20 @@ If error in compilation, attempt to mark the error in lilypond org file."
(org-babel-lilypond-attempt-to-open-pdf org-babel-lilypond-temp-file)
(org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-temp-file)))))
(defun org-babel-lilypond-compile-lilyfile (file-name &optional test)
"Compile lilypond file and check for compile errors.
FILE-NAME is full path to lilypond (.ly) file."
(message "Compiling LilyPond...")
(let ((arg-1 org-babel-lilypond-ly-command) ;program
;; (arg-2 nil) ;infile
(arg-3 "*lilypond*") ;buffer
(arg-4 t) ;display
(arg-5 (if org-babel-lilypond-gen-png "--png" "")) ;&rest...
(arg-6 (if org-babel-lilypond-gen-html "--html" ""))
(arg-7 (if org-babel-lilypond-gen-pdf "--pdf" ""))
(arg-8 (if org-babel-lilypond-use-eps "-dbackend=eps" ""))
(arg-9 (if org-babel-lilypond-gen-svg "-dbackend=svg" ""))
(arg-10 (concat "--output=" (file-name-sans-extension file-name)))
(arg-11 file-name))
(if test
`(,arg-1 ,nil ,arg-3 ,arg-4 ,arg-5 ,arg-6 ;; arg-2
,arg-7 ,arg-8 ,arg-9 ,arg-10 ,arg-11)
(call-process
arg-1 nil arg-3 arg-4 arg-5 arg-6 ;; arg-2
arg-7 arg-8 arg-9 arg-10 arg-11))))
;;Ignoring second arg for pre Org 9.7 compatibility
(defun org-babel-lilypond-compile-lilyfile (filename &optional _)
"Compile Lilypond FILENAME and check for compile errors."
(message "Compiling %s..." filename)
(let ((args (delq nil (list
(and org-babel-lilypond-gen-png "--png")
(and org-babel-lilypond-gen-html "--html")
(and org-babel-lilypond-gen-pdf "--pdf")
(and org-babel-lilypond-use-eps "-dbackend=eps")
(and org-babel-lilypond-gen-svg "-dbackend=svg")
(concat "--output=" (file-name-sans-extension filename))
filename))))
(apply #'call-process org-babel-lilypond-ly-command nil
"*lilypond*" 'display args)))
(defun org-babel-lilypond-check-for-compile-error (file-name &optional test)
"Check for compile error.

View File

@ -46,19 +46,24 @@
:type 'error)
(ert-deftest ob-lilypond/ly-compile-lilyfile ()
(should (equal
`(,org-babel-lilypond-ly-command ;program
nil ;infile
"*lilypond*" ;buffer
t ;display
,(if org-babel-lilypond-gen-png "--png" "") ;&rest...
,(if org-babel-lilypond-gen-html "--html" "")
,(if org-babel-lilypond-gen-pdf "--pdf" "")
,(if org-babel-lilypond-use-eps "-dbackend=eps" "")
,(if org-babel-lilypond-gen-svg "-dbackend=svg" "")
"--output=test-file"
"test-file.ly")
(org-babel-lilypond-compile-lilyfile "test-file.ly" t))))
(cl-letf (((symbol-function 'call-process) 'list)
(org-babel-lilypond-gen-png nil)
(org-babel-lilypond-gen-html nil)
(org-babel-lilypond-use-eps nil)
(org-babel-lilypond-gen-svg nil))
(should (equal
`(,org-babel-lilypond-ly-command ;program
nil ;infile
"*lilypond*" ;buffer
display
,@(when org-babel-lilypond-gen-png '("--png")) ;&rest...
,@(when org-babel-lilypond-gen-html '("--html"))
,@(when org-babel-lilypond-gen-pdf '("--pdf"))
,@(when org-babel-lilypond-use-eps '("-dbackend=eps"))
,@(when org-babel-lilypond-gen-svg '("-dbackend=svg"))
"--output=test-file"
"test-file.ly")
(org-babel-lilypond-compile-lilyfile "test-file.ly")))))
(ert-deftest ob-lilypond/ly-compile-post-tangle ()
(should (boundp 'org-babel-lilypond-compile-post-tangle)))