summaryrefslogtreecommitdiff
path: root/lisp/org/ob-lilypond.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/ob-lilypond.el')
-rw-r--r--lisp/org/ob-lilypond.el230
1 files changed, 115 insertions, 115 deletions
diff --git a/lisp/org/ob-lilypond.el b/lisp/org/ob-lilypond.el
index 9b575464ea..00a951d32d 100644
--- a/lisp/org/ob-lilypond.el
+++ b/lisp/org/ob-lilypond.el
@@ -39,62 +39,62 @@
(defvar org-babel-default-header-args:lilypond '()
"Default header arguments for lilypond code blocks.
NOTE: The arguments are determined at lilypond compile time.
-See (ly-set-header-args)")
+See (org-babel-lilypond-set-header-args)")
-(defvar ly-compile-post-tangle t
+(defvar org-babel-lilypond-compile-post-tangle t
"Following the org-babel-tangle (C-c C-v t) command,
-ly-compile-post-tangle determines whether ob-lilypond should
+org-babel-lilypond-compile-post-tangle determines whether ob-lilypond should
automatically attempt to compile the resultant tangled file.
If the value is nil, no automated compilation takes place.
Default value is t")
-(defvar ly-display-pdf-post-tangle t
+(defvar org-babel-lilypond-display-pdf-post-tangle t
"Following a successful LilyPond compilation
-ly-display-pdf-post-tangle determines whether to automate the
+org-babel-lilypond-display-pdf-post-tangle determines whether to automate the
drawing / redrawing of the resultant pdf. If the value is nil,
the pdf is not automatically redrawn. Default value is t")
-(defvar ly-play-midi-post-tangle t
+(defvar org-babel-lilypond-play-midi-post-tangle t
"Following a successful LilyPond compilation
-ly-play-midi-post-tangle determines whether to automate the
+org-babel-lilypond-play-midi-post-tangle determines whether to automate the
playing of the resultant midi file. If the value is nil,
the midi file is not automatically played. Default value is t")
-(defvar ly-OSX-ly-path
+(defvar org-babel-lilypond-OSX-ly-path
"/Applications/lilypond.app/Contents/Resources/bin/lilypond")
-(defvar ly-OSX-pdf-path "open")
-(defvar ly-OSX-midi-path "open")
+(defvar org-babel-lilypond-OSX-pdf-path "open")
+(defvar org-babel-lilypond-OSX-midi-path "open")
-(defvar ly-nix-ly-path "/usr/bin/lilypond")
-(defvar ly-nix-pdf-path "evince")
-(defvar ly-nix-midi-path "timidity")
+(defvar org-babel-lilypond-nix-ly-path "/usr/bin/lilypond")
+(defvar org-babel-lilypond-nix-pdf-path "evince")
+(defvar org-babel-lilypond-nix-midi-path "timidity")
-(defvar ly-w32-ly-path "lilypond")
-(defvar ly-w32-pdf-path "")
-(defvar ly-w32-midi-path "")
+(defvar org-babel-lilypond-w32-ly-path "lilypond")
+(defvar org-babel-lilypond-w32-pdf-path "")
+(defvar org-babel-lilypond-w32-midi-path "")
-(defvar ly-gen-png nil
+(defvar org-babel-lilypond-gen-png nil
"Image generation (png) can be turned on by default by setting
-LY-GEN-PNG to t")
+ORG-BABEL-LILYPOND-GEN-PNG to t")
-(defvar ly-gen-svg nil
+(defvar org-babel-lilypond-gen-svg nil
"Image generation (SVG) can be turned on by default by setting
-LY-GEN-SVG to t")
+ORG-BABEL-LILYPOND-GEN-SVG to t")
-(defvar ly-gen-html nil
+(defvar org-babel-lilypond-gen-html nil
"HTML generation can be turned on by default by setting
-LY-GEN-HTML to t")
+ORG-BABEL-LILYPOND-GEN-HTML to t")
-(defvar ly-gen-pdf nil
+(defvar org-babel-lilypond-gen-pdf nil
"PDF generation can be turned on by default by setting
-LY-GEN-PDF to t")
+ORG-BABEL-LILYPOND-GEN-PDF to t")
-(defvar ly-use-eps nil
+(defvar org-babel-lilypond-use-eps nil
"You can force the compiler to use the EPS backend by setting
-LY-USE-EPS to t")
+ORG-BABEL-LILYPOND-USE-EPS to t")
-(defvar ly-arrange-mode nil
- "Arrange mode is turned on by setting LY-ARRANGE-MODE
+(defvar org-babel-lilypond-arrange-mode nil
+ "Arrange mode is turned on by setting ORG-BABEL-LILYPOND-ARRANGE-MODE
to t. In Arrange mode the following settings are altered
from default...
:tangle yes, :noweb yes
@@ -123,20 +123,20 @@ Depending on whether we are in arrange mode either:
1. Attempt to execute lilypond block according to header settings
(This is the default basic mode)
2. Tangle all lilypond blocks and process the result (arrange mode)"
- (ly-set-header-args ly-arrange-mode)
- (if ly-arrange-mode
- (ly-tangle)
- (ly-process-basic body params)))
+ (org-babel-lilypond-set-header-args org-babel-lilypond-arrange-mode)
+ (if org-babel-lilypond-arrange-mode
+ (org-babel-lilypond-tangle)
+ (org-babel-lilypond-process-basic body params)))
-(defun ly-tangle ()
+(defun org-babel-lilypond-tangle ()
"ob-lilypond specific tangle, attempts to invoke
=ly-execute-tangled-ly= if tangle is successful. Also passes
specific arguments to =org-babel-tangle="
(interactive)
(if (org-babel-tangle nil "yes" "lilypond")
- (ly-execute-tangled-ly) nil))
+ (org-babel-lilypond-execute-tangled-ly) nil))
-(defun ly-process-basic (body params)
+(defun org-babel-lilypond-process-basic (body params)
"Execute a lilypond block in basic mode."
(let* ((result-params (cdr (assoc :result-params params)))
(out-file (cdr (assoc :file params)))
@@ -148,7 +148,7 @@ specific arguments to =org-babel-tangle="
(insert (org-babel-expand-body:generic body params)))
(org-babel-eval
(concat
- (ly-determine-ly-path)
+ (org-babel-lilypond-determine-ly-path)
" -dbackend=eps "
"-dno-gs-load-fonts "
"-dinclude-eps-fonts "
@@ -167,45 +167,45 @@ specific arguments to =org-babel-tangle="
"Return an error because LilyPond exporter does not support sessions."
(error "Sorry, LilyPond does not currently support sessions!"))
-(defun ly-execute-tangled-ly ()
+(defun org-babel-lilypond-execute-tangled-ly ()
"Compile result of block tangle with lilypond.
If error in compilation, attempt to mark the error in lilypond org file"
- (when ly-compile-post-tangle
- (let ((ly-tangled-file (ly-switch-extension
+ (when org-babel-lilypond-compile-post-tangle
+ (let ((org-babel-lilypond-tangled-file (org-babel-lilypond-switch-extension
(buffer-file-name) ".lilypond"))
- (ly-temp-file (ly-switch-extension
+ (org-babel-lilypond-temp-file (org-babel-lilypond-switch-extension
(buffer-file-name) ".ly")))
- (if (file-exists-p ly-tangled-file)
+ (if (file-exists-p org-babel-lilypond-tangled-file)
(progn
- (when (file-exists-p ly-temp-file)
- (delete-file ly-temp-file))
- (rename-file ly-tangled-file
- ly-temp-file))
+ (when (file-exists-p org-babel-lilypond-temp-file)
+ (delete-file org-babel-lilypond-temp-file))
+ (rename-file org-babel-lilypond-tangled-file
+ org-babel-lilypond-temp-file))
(error "Error: Tangle Failed!") t)
(switch-to-buffer-other-window "*lilypond*")
(erase-buffer)
- (ly-compile-lilyfile ly-temp-file)
+ (org-babel-lilypond-compile-lilyfile org-babel-lilypond-temp-file)
(goto-char (point-min))
- (if (not (ly-check-for-compile-error ly-temp-file))
+ (if (not (org-babel-lilypond-check-for-compile-error org-babel-lilypond-temp-file))
(progn
(other-window -1)
- (ly-attempt-to-open-pdf ly-temp-file)
- (ly-attempt-to-play-midi ly-temp-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))
(error "Error in Compilation!")))) nil)
-(defun ly-compile-lilyfile (file-name &optional test)
+(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 (ly-determine-ly-path)) ;program
+ (let ((arg-1 (org-babel-lilypond-determine-ly-path)) ;program
(arg-2 nil) ;infile
(arg-3 "*lilypond*") ;buffer
(arg-4 t) ;display
- (arg-5 (if ly-gen-png "--png" "")) ;&rest...
- (arg-6 (if ly-gen-html "--html" ""))
- (arg-7 (if ly-gen-pdf "--pdf" ""))
- (arg-8 (if ly-use-eps "-dbackend=eps" ""))
- (arg-9 (if ly-gen-svg "-dbackend=svg" ""))
+ (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
@@ -215,7 +215,7 @@ FILE-NAME is full path to lilypond (.ly) file"
arg-1 arg-2 arg-3 arg-4 arg-5 arg-6
arg-7 arg-8 arg-9 arg-10 arg-11))))
-(defun ly-check-for-compile-error (file-name &optional test)
+(defun org-babel-lilypond-check-for-compile-error (file-name &optional test)
"Check for compile error.
This is performed by parsing the *lilypond* buffer
containing the output message from the compilation.
@@ -226,24 +226,24 @@ nil as file-name since it is unused in this context"
(if (not test)
(if (not is-error)
nil
- (ly-process-compile-error file-name))
+ (org-babel-lilypond-process-compile-error file-name))
is-error)))
-(defun ly-process-compile-error (file-name)
+(defun org-babel-lilypond-process-compile-error (file-name)
"Process the compilation error that has occurred.
FILE-NAME is full path to lilypond file"
- (let ((line-num (ly-parse-line-num)))
- (let ((error-lines (ly-parse-error-line file-name line-num)))
- (ly-mark-error-line file-name error-lines)
+ (let ((line-num (org-babel-lilypond-parse-line-num)))
+ (let ((error-lines (org-babel-lilypond-parse-error-line file-name line-num)))
+ (org-babel-lilypond-mark-error-line file-name error-lines)
(error "Error: Compilation Failed!"))))
-(defun ly-mark-error-line (file-name line)
+(defun org-babel-lilypond-mark-error-line (file-name line)
"Mark the erroneous lines in the lilypond org buffer.
FILE-NAME is full path to lilypond file.
LINE is the erroneous line"
(switch-to-buffer-other-window
(concat (file-name-nondirectory
- (ly-switch-extension file-name ".org"))))
+ (org-babel-lilypond-switch-extension file-name ".org"))))
(let ((temp (point)))
(goto-char (point-min))
(setq case-fold-search nil)
@@ -254,7 +254,7 @@ LINE is the erroneous line"
(goto-char (- (point) (length line))))
(goto-char temp))))
-(defun ly-parse-line-num (&optional buffer)
+(defun org-babel-lilypond-parse-line-num (&optional buffer)
"Extract error line number."
(when buffer
(set-buffer buffer))
@@ -276,12 +276,12 @@ LINE is the erroneous line"
nil)))
nil)))
-(defun ly-parse-error-line (file-name lineNo)
+(defun org-babel-lilypond-parse-error-line (file-name lineNo)
"Extract the erroneous line from the tangled .ly file
FILE-NAME is full path to lilypond file.
LINENO is the number of the erroneous line"
(with-temp-buffer
- (insert-file-contents (ly-switch-extension file-name ".ly")
+ (insert-file-contents (org-babel-lilypond-switch-extension file-name ".ly")
nil nil nil t)
(if (> lineNo 0)
(progn
@@ -290,128 +290,128 @@ LINENO is the number of the erroneous line"
(buffer-substring (point) (point-at-eol)))
nil)))
-(defun ly-attempt-to-open-pdf (file-name &optional test)
+(defun org-babel-lilypond-attempt-to-open-pdf (file-name &optional test)
"Attempt to display the generated pdf file
FILE-NAME is full path to lilypond file
If TEST is non-nil, the shell command is returned and is not run"
- (when ly-display-pdf-post-tangle
- (let ((pdf-file (ly-switch-extension file-name ".pdf")))
+ (when org-babel-lilypond-display-pdf-post-tangle
+ (let ((pdf-file (org-babel-lilypond-switch-extension file-name ".pdf")))
(if (file-exists-p pdf-file)
(let ((cmd-string
- (concat (ly-determine-pdf-path) " " pdf-file)))
+ (concat (org-babel-lilypond-determine-pdf-path) " " pdf-file)))
(if test
cmd-string
(start-process
"\"Audition pdf\""
"*lilypond*"
- (ly-determine-pdf-path)
+ (org-babel-lilypond-determine-pdf-path)
pdf-file)))
(message "No pdf file generated so can't display!")))))
-(defun ly-attempt-to-play-midi (file-name &optional test)
+(defun org-babel-lilypond-attempt-to-play-midi (file-name &optional test)
"Attempt to play the generated MIDI file
FILE-NAME is full path to lilypond file
If TEST is non-nil, the shell command is returned and is not run"
- (when ly-play-midi-post-tangle
- (let ((midi-file (ly-switch-extension file-name ".midi")))
+ (when org-babel-lilypond-play-midi-post-tangle
+ (let ((midi-file (org-babel-lilypond-switch-extension file-name ".midi")))
(if (file-exists-p midi-file)
(let ((cmd-string
- (concat (ly-determine-midi-path) " " midi-file)))
+ (concat (org-babel-lilypond-determine-midi-path) " " midi-file)))
(if test
cmd-string
(start-process
"\"Audition midi\""
"*lilypond*"
- (ly-determine-midi-path)
+ (org-babel-lilypond-determine-midi-path)
midi-file)))
(message "No midi file generated so can't play!")))))
-(defun ly-determine-ly-path (&optional test)
+(defun org-babel-lilypond-determine-ly-path (&optional test)
"Return correct path to ly binary depending on OS
If TEST is non-nil, it contains a simulation of the OS for test purposes"
(let ((sys-type
(or test system-type)))
(cond ((string= sys-type "darwin")
- ly-OSX-ly-path)
+ org-babel-lilypond-OSX-ly-path)
((string= sys-type "windows-nt")
- ly-w32-ly-path)
- (t ly-nix-ly-path))))
+ org-babel-lilypond-w32-ly-path)
+ (t org-babel-lilypond-nix-ly-path))))
-(defun ly-determine-pdf-path (&optional test)
+(defun org-babel-lilypond-determine-pdf-path (&optional test)
"Return correct path to pdf viewer depending on OS
If TEST is non-nil, it contains a simulation of the OS for test purposes"
(let ((sys-type
(or test system-type)))
(cond ((string= sys-type "darwin")
- ly-OSX-pdf-path)
+ org-babel-lilypond-OSX-pdf-path)
((string= sys-type "windows-nt")
- ly-w32-pdf-path)
- (t ly-nix-pdf-path))))
+ org-babel-lilypond-w32-pdf-path)
+ (t org-babel-lilypond-nix-pdf-path))))
-(defun ly-determine-midi-path (&optional test)
+(defun org-babel-lilypond-determine-midi-path (&optional test)
"Return correct path to midi player depending on OS
If TEST is non-nil, it contains a simulation of the OS for test purposes"
(let ((sys-type
(or test test system-type)))
(cond ((string= sys-type "darwin")
- ly-OSX-midi-path)
+ org-babel-lilypond-OSX-midi-path)
((string= sys-type "windows-nt")
- ly-w32-midi-path)
- (t ly-nix-midi-path))))
+ org-babel-lilypond-w32-midi-path)
+ (t org-babel-lilypond-nix-midi-path))))
-(defun ly-toggle-midi-play ()
+(defun org-babel-lilypond-toggle-midi-play ()
"Toggle whether midi will be played following a successful compilation."
(interactive)
- (setq ly-play-midi-post-tangle
- (not ly-play-midi-post-tangle))
+ (setq org-babel-lilypond-play-midi-post-tangle
+ (not org-babel-lilypond-play-midi-post-tangle))
(message (concat "Post-Tangle MIDI play has been "
- (if ly-play-midi-post-tangle
+ (if org-babel-lilypond-play-midi-post-tangle
"ENABLED." "DISABLED."))))
-(defun ly-toggle-pdf-display ()
+(defun org-babel-lilypond-toggle-pdf-display ()
"Toggle whether pdf will be displayed following a successful compilation."
(interactive)
- (setq ly-display-pdf-post-tangle
- (not ly-display-pdf-post-tangle))
+ (setq org-babel-lilypond-display-pdf-post-tangle
+ (not org-babel-lilypond-display-pdf-post-tangle))
(message (concat "Post-Tangle PDF display has been "
- (if ly-display-pdf-post-tangle
+ (if org-babel-lilypond-display-pdf-post-tangle
"ENABLED." "DISABLED."))))
-(defun ly-toggle-png-generation ()
+(defun org-babel-lilypond-toggle-png-generation ()
"Toggle whether png image will be generated by compilation."
(interactive)
- (setq ly-gen-png (not ly-gen-png))
+ (setq org-babel-lilypond-gen-png (not org-babel-lilypond-gen-png))
(message (concat "PNG image generation has been "
- (if ly-gen-png "ENABLED." "DISABLED."))))
+ (if org-babel-lilypond-gen-png "ENABLED." "DISABLED."))))
-(defun ly-toggle-html-generation ()
+(defun org-babel-lilypond-toggle-html-generation ()
"Toggle whether html will be generated by compilation."
(interactive)
- (setq ly-gen-html (not ly-gen-html))
+ (setq org-babel-lilypond-gen-html (not org-babel-lilypond-gen-html))
(message (concat "HTML generation has been "
- (if ly-gen-html "ENABLED." "DISABLED."))))
+ (if org-babel-lilypond-gen-html "ENABLED." "DISABLED."))))
-(defun ly-toggle-pdf-generation ()
+(defun org-babel-lilypond-toggle-pdf-generation ()
"Toggle whether pdf will be generated by compilation."
(interactive)
- (setq ly-gen-pdf (not ly-gen-pdf))
+ (setq org-babel-lilypond-gen-pdf (not org-babel-lilypond-gen-pdf))
(message (concat "PDF generation has been "
- (if ly-gen-pdf "ENABLED." "DISABLED."))))
+ (if org-babel-lilypond-gen-pdf "ENABLED." "DISABLED."))))
-(defun ly-toggle-arrange-mode ()
+(defun org-babel-lilypond-toggle-arrange-mode ()
"Toggle whether in Arrange mode or Basic mode."
(interactive)
- (setq ly-arrange-mode
- (not ly-arrange-mode))
+ (setq org-babel-lilypond-arrange-mode
+ (not org-babel-lilypond-arrange-mode))
(message (concat "Arrange mode has been "
- (if ly-arrange-mode "ENABLED." "DISABLED."))))
+ (if org-babel-lilypond-arrange-mode "ENABLED." "DISABLED."))))
-(defun ly-switch-extension (file-name ext)
+(defun org-babel-lilypond-switch-extension (file-name ext)
"Utility command to swap current FILE-NAME extension with EXT"
(concat (file-name-sans-extension
file-name) ext))
-(defun ly-get-header-args (mode)
+(defun org-babel-lilypond-get-header-args (mode)
"Default arguments to use when evaluating a lilypond
source block. These depend upon whether we are in arrange
mode i.e. ARRANGE-MODE is t"
@@ -425,11 +425,11 @@ mode i.e. ARRANGE-MODE is t"
'((:results . "file")
(:exports . "results")))))
-(defun ly-set-header-args (mode)
+(defun org-babel-lilypond-set-header-args (mode)
"Set org-babel-default-header-args:lilypond
-dependent on LY-ARRANGE-MODE"
+dependent on ORG-BABEL-LILYPOND-ARRANGE-MODE"
(setq org-babel-default-header-args:lilypond
- (ly-get-header-args mode)))
+ (org-babel-lilypond-get-header-args mode)))
(provide 'ob-lilypond)