|
@@ -5,7 +5,7 @@
|
|
;; Author: Martyn Jago
|
|
;; Author: Martyn Jago
|
|
;; Keywords: babel language, literate programming
|
|
;; Keywords: babel language, literate programming
|
|
;; Homepage: https://github.com/mjago/ob-lilypond
|
|
;; Homepage: https://github.com/mjago/ob-lilypond
|
|
-;; Version: 0.2
|
|
|
|
|
|
+;; Version: 0.3
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
@@ -33,7 +33,7 @@
|
|
(defalias 'lilypond-mode 'LilyPond-mode)
|
|
(defalias 'lilypond-mode 'LilyPond-mode)
|
|
(add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
|
|
(add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
|
|
|
|
|
|
-(defconst ly-version "0.2"
|
|
|
|
|
|
+(defconst ly-version "0.3"
|
|
"The version number of the file ob-lilypond.el.")
|
|
"The version number of the file ob-lilypond.el.")
|
|
|
|
|
|
(defvar ly-compile-post-tangle t
|
|
(defvar ly-compile-post-tangle t
|
|
@@ -84,9 +84,14 @@ LY-GEN-HTML to t")
|
|
"You can force the compiler to use the EPS backend by setting
|
|
"You can force the compiler to use the EPS backend by setting
|
|
LY-USE-EPS to t")
|
|
LY-USE-EPS to t")
|
|
|
|
|
|
-(defvar org-babel-default-header-args:lilypond
|
|
|
|
- '((:tangle . "yes") (:noweb . "yes") (:results . "silent") (:comments . "yes"))
|
|
|
|
- "Default arguments to use when evaluating a lilypond source block.")
|
|
|
|
|
|
+(defvar ly-arrange-mode nil
|
|
|
|
+ "Arrange mode is turned on by setting LY-ARRANGE-MODE
|
|
|
|
+to t. In Arrange mode the following settings are altered
|
|
|
|
+from default...
|
|
|
|
+:tangle yes, :noweb yes
|
|
|
|
+:results silent :comments yes.
|
|
|
|
+In addition lilypond block execution causes tangling of all lilypond
|
|
|
|
+blocks")
|
|
|
|
|
|
(defun org-babel-expand-body:lilypond (body params)
|
|
(defun org-babel-expand-body:lilypond (body params)
|
|
"Expand BODY according to PARAMS, return the expanded body."
|
|
"Expand BODY according to PARAMS, return the expanded body."
|
|
@@ -106,9 +111,15 @@ LY-USE-EPS to t")
|
|
|
|
|
|
(defun org-babel-execute:lilypond (body params)
|
|
(defun org-babel-execute:lilypond (body params)
|
|
"This function is called by `org-babel-execute-src-block'.
|
|
"This function is called by `org-babel-execute-src-block'.
|
|
-tTangle all lilypond blocks and process the result"
|
|
|
|
|
|
+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-tangle))
|
|
|
|
|
|
+ (ly-set-header-args ly-arrange-mode)
|
|
|
|
+ (if ly-arrange-mode
|
|
|
|
+ (ly-tangle)
|
|
|
|
+ (ly-process-basic body params)))
|
|
|
|
|
|
(defun ly-tangle ()
|
|
(defun ly-tangle ()
|
|
"ob-lilypond specific tangle, attempts to invoke
|
|
"ob-lilypond specific tangle, attempts to invoke
|
|
@@ -119,6 +130,32 @@ specific arguments to =org-babel-tangle="
|
|
(if (org-babel-tangle nil "yes" "lilypond")
|
|
(if (org-babel-tangle nil "yes" "lilypond")
|
|
(ly-execute-tangled-ly) nil))
|
|
(ly-execute-tangled-ly) nil))
|
|
|
|
|
|
|
|
+(defun ly-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)))
|
|
|
|
+ (cmdline (or (cdr (assoc :cmdline params))
|
|
|
|
+ ""))
|
|
|
|
+ (in-file (org-babel-temp-file "dot-")))
|
|
|
|
+
|
|
|
|
+ (with-temp-file in-file
|
|
|
|
+ (insert (org-babel-expand-body:dot body params)))
|
|
|
|
+
|
|
|
|
+ (org-babel-eval
|
|
|
|
+ (concat
|
|
|
|
+ (ly-determine-ly-path)
|
|
|
|
+ " -dbackend=eps "
|
|
|
|
+ "-dno-gs-load-fonts "
|
|
|
|
+ "-dinclude-eps-fonts "
|
|
|
|
+ "--png "
|
|
|
|
+ "--output="
|
|
|
|
+ (file-name-sans-extension out-file)
|
|
|
|
+ " "
|
|
|
|
+ cmdline
|
|
|
|
+ in-file) "")
|
|
|
|
+ ) nil)
|
|
|
|
+
|
|
(defun org-babel-prep-session:lilypond (session params)
|
|
(defun org-babel-prep-session:lilypond (session params)
|
|
"Return an error because LilyPond exporter does not support sessions."
|
|
"Return an error because LilyPond exporter does not support sessions."
|
|
|
|
|
|
@@ -161,7 +198,7 @@ FILE-NAME is full path to lilypond (.ly) file"
|
|
(arg-3 "*lilypond*") ;buffer
|
|
(arg-3 "*lilypond*") ;buffer
|
|
(arg-4 t) ;display
|
|
(arg-4 t) ;display
|
|
(arg-5 (if ly-gen-png "--png" "")) ;&rest...
|
|
(arg-5 (if ly-gen-png "--png" "")) ;&rest...
|
|
- (arg-6 (if ly-gen-html "--html" ""))
|
|
|
|
|
|
+ (arg-6 (if ly-gen-html "--html" ""))
|
|
(arg-7 (if ly-use-eps "-dbackend=eps" ""))
|
|
(arg-7 (if ly-use-eps "-dbackend=eps" ""))
|
|
(arg-8 (if ly-gen-svg "-dbackend=svg" ""))
|
|
(arg-8 (if ly-gen-svg "-dbackend=svg" ""))
|
|
(arg-9 (concat "--output=" (file-name-sans-extension file-name)))
|
|
(arg-9 (concat "--output=" (file-name-sans-extension file-name)))
|
|
@@ -340,7 +377,7 @@ If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
|
|
(defun ly-toggle-png-generation ()
|
|
(defun ly-toggle-png-generation ()
|
|
"Toggle whether png image will be generated by compilation"
|
|
"Toggle whether png image will be generated by compilation"
|
|
-
|
|
|
|
|
|
+
|
|
(interactive)
|
|
(interactive)
|
|
(setq ly-gen-png
|
|
(setq ly-gen-png
|
|
(not ly-gen-png))
|
|
(not ly-gen-png))
|
|
@@ -349,13 +386,22 @@ If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
|
|
(defun ly-toggle-html-generation ()
|
|
(defun ly-toggle-html-generation ()
|
|
"Toggle whether html will be generated by compilation"
|
|
"Toggle whether html will be generated by compilation"
|
|
-
|
|
|
|
|
|
+
|
|
(interactive)
|
|
(interactive)
|
|
(setq ly-gen-html
|
|
(setq ly-gen-html
|
|
(not ly-gen-html))
|
|
(not ly-gen-html))
|
|
(message (concat "HTML generation has been "
|
|
(message (concat "HTML generation has been "
|
|
(if ly-gen-html "ENABLED." "DISABLED."))))
|
|
(if ly-gen-html "ENABLED." "DISABLED."))))
|
|
|
|
|
|
|
|
+(defun ly-toggle-arrange-mode ()
|
|
|
|
+ "Toggle whether in Arrange mode or Basic mode"
|
|
|
|
+
|
|
|
|
+ (interactive)
|
|
|
|
+ (setq ly-arrange-mode
|
|
|
|
+ (not ly-arrange-mode))
|
|
|
|
+ (message (concat "Arrange mode has been "
|
|
|
|
+ (if ly-arrange-mode "ENABLED." "DISABLED."))))
|
|
|
|
+
|
|
(defun ly-version (&optional insert-at-point)
|
|
(defun ly-version (&optional insert-at-point)
|
|
(interactive)
|
|
(interactive)
|
|
(setq version (format "ob-lilypond version %s" ly-version))
|
|
(setq version (format "ob-lilypond version %s" ly-version))
|
|
@@ -364,12 +410,31 @@ If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
|
|
(defun ly-switch-extension (file-name ext)
|
|
(defun ly-switch-extension (file-name ext)
|
|
"Utility command to swap current FILE-NAME extension with EXT"
|
|
"Utility command to swap current FILE-NAME extension with EXT"
|
|
-
|
|
|
|
|
|
+
|
|
(concat (file-name-sans-extension
|
|
(concat (file-name-sans-extension
|
|
file-name) ext))
|
|
file-name) ext))
|
|
|
|
|
|
|
|
+(defun ly-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"
|
|
|
|
+ (cond (mode
|
|
|
|
+ '((:tangle . "yes")
|
|
|
|
+ (:noweb . "yes")
|
|
|
|
+ (:results . "silent")
|
|
|
|
+ (:comments . "yes")))
|
|
|
|
+ (t
|
|
|
|
+ '((:results . "file")
|
|
|
|
+ (:exports . "results")))))
|
|
|
|
+
|
|
|
|
+(defun ly-set-header-args (mode)
|
|
|
|
+ "Set org-babel-default-header-args:lilypond
|
|
|
|
+dependent on LY-ARRANGE-MODE"
|
|
|
|
+ (setq org-babel-default-header-args:lilypond
|
|
|
|
+ (ly-get-header-args mode)))
|
|
|
|
+
|
|
(provide 'ob-lilypond)
|
|
(provide 'ob-lilypond)
|
|
|
|
|
|
;; arch-tag: ac449eea-2cf2-4dc5-ae33-426f57ba4894
|
|
;; arch-tag: ac449eea-2cf2-4dc5-ae33-426f57ba4894
|
|
-
|
|
|
|
|
|
+
|
|
;;; ob-lilypond.el ends here
|
|
;;; ob-lilypond.el ends here
|