2011-06-28 20:40:17 -04:00
|
|
|
;;; ob-lilypond.el --- org-babel functions for lilypond evaluation
|
|
|
|
|
2016-01-09 17:12:03 -05:00
|
|
|
;; Copyright (C) 2010-2016 Free Software Foundation, Inc.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; Author: Martyn Jago
|
2012-03-17 11:28:46 -04:00
|
|
|
;; Keywords: babel language, literate programming
|
2012-03-21 06:56:52 -04:00
|
|
|
;; Homepage: http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-lilypond.html
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; This file is part of GNU Emacs.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2011-06-28 20:40:17 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2011-06-30 14:06:22 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2011-06-28 20:40:17 -04:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-30 14:06:22 -04:00
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-06-28 20:40:17 -04:00
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;;; Commentary:
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
;; Installation, ob-lilypond documentation, and examples are available at
|
|
|
|
;; http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-lilypond.html
|
|
|
|
;;
|
|
|
|
;; Lilypond documentation can be found at
|
|
|
|
;; http://lilypond.org/manuals.html
|
2014-05-09 08:54:33 -04:00
|
|
|
;;
|
|
|
|
;; This depends on epstopdf --- See http://www.ctan.org/pkg/epstopdf.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;;; Code:
|
2011-06-28 20:40:17 -04:00
|
|
|
(require 'ob)
|
2012-03-21 06:49:57 -04:00
|
|
|
(require 'outline)
|
2011-06-28 20:40:17 -04:00
|
|
|
(defalias 'lilypond-mode 'LilyPond-mode)
|
2011-07-07 21:33:56 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
|
|
|
|
|
2011-07-07 21:33:56 -04:00
|
|
|
(defvar org-babel-default-header-args:lilypond '()
|
2012-03-19 16:38:12 -04:00
|
|
|
"Default header arguments for lilypond code blocks.
|
|
|
|
NOTE: The arguments are determined at lilypond compile time.
|
2014-08-20 15:10:00 -04:00
|
|
|
See (org-babel-lilypond-set-header-args)")
|
2011-07-07 21:33:56 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-compile-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following the org-babel-tangle (C-c C-v t) command,
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-compile-post-tangle determines whether ob-lilypond should
|
2011-06-28 20:40:17 -04:00
|
|
|
automatically attempt to compile the resultant tangled file.
|
|
|
|
If the value is nil, no automated compilation takes place.
|
|
|
|
Default value is t")
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-display-pdf-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following a successful LilyPond compilation
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-display-pdf-post-tangle determines whether to automate the
|
2012-08-11 13:10:44 -04:00
|
|
|
drawing / redrawing of the resultant pdf. If the value is nil,
|
|
|
|
the pdf is not automatically redrawn. Default value is t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-play-midi-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following a successful LilyPond compilation
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-play-midi-post-tangle determines whether to automate the
|
2012-08-11 13:10:44 -04:00
|
|
|
playing of the resultant midi file. If the value is nil,
|
|
|
|
the midi file is not automatically played. Default value is t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2015-05-26 15:37:04 -04:00
|
|
|
(defvar org-babel-lilypond-ly-command ""
|
|
|
|
"Command to execute lilypond on your system.
|
|
|
|
Do not set it directly. Customize `org-babel-lilypond-commands' instead.")
|
|
|
|
(defvar org-babel-lilypond-pdf-command ""
|
|
|
|
"Command to show a PDF file on your system.
|
|
|
|
Do not set it directly. Customize `org-babel-lilypond-commands' instead.")
|
|
|
|
(defvar org-babel-lilypond-midi-command ""
|
|
|
|
"Command to play a MIDI file on your system.
|
|
|
|
Do not set it directly. Customize `org-babel-lilypond-commands' instead.")
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(defcustom org-babel-lilypond-commands
|
|
|
|
(cond
|
|
|
|
((eq system-type 'darwin)
|
|
|
|
'("/Applications/lilypond.app/Contents/Resources/bin/lilypond" "open" "open"))
|
|
|
|
((eq system-type 'windows-nt)
|
|
|
|
'("lilypond" "" ""))
|
|
|
|
(t
|
|
|
|
'("lilypond" "xdg-open" "xdg-open")))
|
|
|
|
"Commands to run lilypond and view or play the results.
|
|
|
|
These should be executables that take a filename as an argument.
|
|
|
|
On some system it is possible to specify the filename directly
|
|
|
|
and the viewer or player will be determined from the file type;
|
|
|
|
you can leave the string empty on this case."
|
|
|
|
:group 'org-babel
|
|
|
|
:type '(list
|
|
|
|
(string :tag "Lilypond ")
|
|
|
|
(string :tag "PDF Viewer ")
|
|
|
|
(string :tag "MIDI Player"))
|
|
|
|
:version "24.3"
|
|
|
|
:package-version '(Org . "8.2.7")
|
|
|
|
:set
|
|
|
|
(lambda (symbol value)
|
|
|
|
(setq
|
|
|
|
org-babel-lilypond-ly-command (nth 0 value)
|
|
|
|
org-babel-lilypond-pdf-command (nth 1 value)
|
|
|
|
org-babel-lilypond-midi-command (nth 2 value))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-png nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil means image generation (PNG) is turned on by default.")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-svg nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil means image generation (SVG) is be turned on by default.")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-html nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil means HTML generation is turned on by default.")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-pdf nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil means PDF generation is be turned on by default.")
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-use-eps nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil forces the compiler to use the EPS backend.")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-arrange-mode nil
|
2015-05-26 15:37:04 -04:00
|
|
|
"Non-nil turns Arrange mode on.
|
|
|
|
In Arrange mode the following settings are altered from default:
|
2011-07-06 09:17:29 -04:00
|
|
|
:tangle yes, :noweb yes
|
|
|
|
:results silent :comments yes.
|
|
|
|
In addition lilypond block execution causes tangling of all lilypond
|
2015-05-26 15:37:04 -04:00
|
|
|
blocks.")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
|
|
|
(defun org-babel-expand-body:lilypond (body params)
|
|
|
|
"Expand BODY according to PARAMS, return the expanded body."
|
|
|
|
(let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
|
|
|
|
(mapc
|
|
|
|
(lambda (pair)
|
|
|
|
(let ((name (symbol-name (car pair)))
|
|
|
|
(value (cdr pair)))
|
|
|
|
(setq body
|
|
|
|
(replace-regexp-in-string
|
2015-09-17 19:08:20 -04:00
|
|
|
(concat "$" (regexp-quote name))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if (stringp value) value (format "%S" value))
|
|
|
|
body))))
|
|
|
|
vars)
|
|
|
|
body))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(defun org-babel-execute:lilypond (body params)
|
|
|
|
"This function is called by `org-babel-execute-src-block'.
|
2011-07-06 09:17:29 -04:00
|
|
|
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)"
|
2014-08-20 15:10:00 -04:00
|
|
|
(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)))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-tangle ()
|
2011-06-28 20:40:17 -04:00
|
|
|
"ob-lilypond specific tangle, attempts to invoke
|
2012-08-11 13:10:44 -04:00
|
|
|
=ly-execute-tangled-ly= if tangle is successful. Also passes
|
2011-06-28 20:40:17 -04:00
|
|
|
specific arguments to =org-babel-tangle="
|
|
|
|
(interactive)
|
|
|
|
(if (org-babel-tangle nil "yes" "lilypond")
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-execute-tangled-ly) nil))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-process-basic (body params)
|
2012-07-30 04:08:15 -04:00
|
|
|
"Execute a lilypond block in basic mode."
|
2011-07-06 09:17:29 -04:00
|
|
|
(let* ((result-params (cdr (assoc :result-params params)))
|
|
|
|
(out-file (cdr (assoc :file params)))
|
|
|
|
(cmdline (or (cdr (assoc :cmdline params))
|
|
|
|
""))
|
2011-07-07 21:33:56 -04:00
|
|
|
(in-file (org-babel-temp-file "lilypond-")))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
|
|
|
(with-temp-file in-file
|
2011-07-07 21:33:56 -04:00
|
|
|
(insert (org-babel-expand-body:generic body params)))
|
2011-07-06 09:17:29 -04:00
|
|
|
(org-babel-eval
|
|
|
|
(concat
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
org-babel-lilypond-ly-command
|
2011-07-06 09:17:29 -04:00
|
|
|
" -dbackend=eps "
|
|
|
|
"-dno-gs-load-fonts "
|
|
|
|
"-dinclude-eps-fonts "
|
2013-02-06 19:51:14 -05:00
|
|
|
(or (cdr (assoc (file-name-extension out-file)
|
2013-01-31 05:17:18 -05:00
|
|
|
'(("pdf" . "--pdf ")
|
|
|
|
("ps" . "--ps ")
|
|
|
|
("png" . "--png "))))
|
|
|
|
"--png ")
|
2011-07-06 09:17:29 -04:00
|
|
|
"--output="
|
|
|
|
(file-name-sans-extension out-file)
|
|
|
|
" "
|
|
|
|
cmdline
|
2012-07-30 04:08:15 -04:00
|
|
|
in-file) "")) nil)
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(defun org-babel-prep-session:lilypond (session params)
|
|
|
|
"Return an error because LilyPond exporter does not support sessions."
|
|
|
|
(error "Sorry, LilyPond does not currently support sessions!"))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-execute-tangled-ly ()
|
2011-06-28 20:40:17 -04:00
|
|
|
"Compile result of block tangle with lilypond.
|
|
|
|
If error in compilation, attempt to mark the error in lilypond org file"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-compile-post-tangle
|
|
|
|
(let ((org-babel-lilypond-tangled-file (org-babel-lilypond-switch-extension
|
2011-06-28 20:40:17 -04:00
|
|
|
(buffer-file-name) ".lilypond"))
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-temp-file (org-babel-lilypond-switch-extension
|
2011-06-28 20:40:17 -04:00
|
|
|
(buffer-file-name) ".ly")))
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(if (not (file-exists-p org-babel-lilypond-tangled-file))
|
|
|
|
(error "Error: Tangle Failed!")
|
|
|
|
(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))
|
2011-06-28 20:40:17 -04:00
|
|
|
(switch-to-buffer-other-window "*lilypond*")
|
|
|
|
(erase-buffer)
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-compile-lilyfile org-babel-lilypond-temp-file)
|
2011-06-28 20:40:17 -04:00
|
|
|
(goto-char (point-min))
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(if (org-babel-lilypond-check-for-compile-error org-babel-lilypond-temp-file)
|
|
|
|
(error "Error in Compilation!")
|
|
|
|
(other-window -1)
|
|
|
|
(org-babel-lilypond-attempt-to-open-pdf org-babel-lilypond-temp-file)
|
|
|
|
(org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-temp-file)))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-compile-lilyfile (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Compile lilypond file and check for compile errors
|
|
|
|
FILE-NAME is full path to lilypond (.ly) file"
|
|
|
|
(message "Compiling LilyPond...")
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(let ((arg-1 org-babel-lilypond-ly-command) ;program
|
2011-06-28 20:40:17 -04:00
|
|
|
(arg-2 nil) ;infile
|
|
|
|
(arg-3 "*lilypond*") ;buffer
|
2012-03-19 16:38:12 -04:00
|
|
|
(arg-4 t) ;display
|
2014-08-20 15:10:00 -04:00
|
|
|
(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" ""))
|
2012-03-19 16:38:12 -04:00
|
|
|
(arg-10 (concat "--output=" (file-name-sans-extension file-name)))
|
|
|
|
(arg-11 file-name))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
2012-03-19 16:38:12 -04:00
|
|
|
`(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5 ,arg-6
|
|
|
|
,arg-7 ,arg-8 ,arg-9 ,arg-10 ,arg-11)
|
2011-06-28 20:40:17 -04:00
|
|
|
(call-process
|
2012-03-19 16:38:12 -04:00
|
|
|
arg-1 arg-2 arg-3 arg-4 arg-5 arg-6
|
|
|
|
arg-7 arg-8 arg-9 arg-10 arg-11))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-check-for-compile-error (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Check for compile error.
|
|
|
|
This is performed by parsing the *lilypond* buffer
|
|
|
|
containing the output message from the compilation.
|
|
|
|
FILE-NAME is full path to lilypond file.
|
|
|
|
If TEST is t just return nil if no error found, and pass
|
|
|
|
nil as file-name since it is unused in this context"
|
|
|
|
(let ((is-error (search-forward "error:" nil t)))
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(if test
|
|
|
|
is-error
|
|
|
|
(when is-error
|
|
|
|
(org-babel-lilypond-process-compile-error file-name)))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-process-compile-error (file-name)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Process the compilation error that has occurred.
|
|
|
|
FILE-NAME is full path to lilypond file"
|
2014-08-20 15:10:00 -04:00
|
|
|
(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)
|
2011-06-28 20:40:17 -04:00
|
|
|
(error "Error: Compilation Failed!"))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-mark-error-line (file-name line)
|
2011-06-28 20:40:17 -04:00
|
|
|
"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
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-switch-extension file-name ".org"))))
|
2011-06-28 20:40:17 -04:00
|
|
|
(let ((temp (point)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(setq case-fold-search nil)
|
|
|
|
(if (search-forward line nil t)
|
|
|
|
(progn
|
2015-09-27 11:45:07 -04:00
|
|
|
(outline-show-all)
|
2011-06-28 20:40:17 -04:00
|
|
|
(set-mark (point))
|
|
|
|
(goto-char (- (point) (length line))))
|
|
|
|
(goto-char temp))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-parse-line-num (&optional buffer)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Extract error line number."
|
|
|
|
(when buffer
|
|
|
|
(set-buffer buffer))
|
|
|
|
(let ((start
|
|
|
|
(and (search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)))
|
|
|
|
(num nil))
|
|
|
|
(if start
|
|
|
|
(progn
|
|
|
|
(forward-char)
|
|
|
|
(let ((num (buffer-substring
|
|
|
|
(+ 1 start)
|
|
|
|
(- (search-forward ":" nil t) 1))))
|
|
|
|
(setq num (string-to-number num))
|
|
|
|
(if (numberp num)
|
|
|
|
num
|
|
|
|
nil)))
|
|
|
|
nil)))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-parse-error-line (file-name lineNo)
|
2011-06-28 20:40:17 -04:00
|
|
|
"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"
|
2011-07-01 15:22:05 -04:00
|
|
|
(with-temp-buffer
|
2014-08-20 15:10:00 -04:00
|
|
|
(insert-file-contents (org-babel-lilypond-switch-extension file-name ".ly")
|
2011-07-01 15:22:05 -04:00
|
|
|
nil nil nil t)
|
|
|
|
(if (> lineNo 0)
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (- lineNo 1))
|
|
|
|
(buffer-substring (point) (point-at-eol)))
|
|
|
|
nil)))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-attempt-to-open-pdf (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"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"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-display-pdf-post-tangle
|
|
|
|
(let ((pdf-file (org-babel-lilypond-switch-extension file-name ".pdf")))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if (file-exists-p pdf-file)
|
|
|
|
(let ((cmd-string
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(concat org-babel-lilypond-pdf-command " " pdf-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
|
|
|
cmd-string
|
2012-03-19 16:38:12 -04:00
|
|
|
(start-process
|
|
|
|
"\"Audition pdf\""
|
|
|
|
"*lilypond*"
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
org-babel-lilypond-pdf-command
|
2012-03-19 16:38:12 -04:00
|
|
|
pdf-file)))
|
|
|
|
(message "No pdf file generated so can't display!")))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-attempt-to-play-midi (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"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"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-play-midi-post-tangle
|
|
|
|
(let ((midi-file (org-babel-lilypond-switch-extension file-name ".midi")))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if (file-exists-p midi-file)
|
|
|
|
(let ((cmd-string
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
(concat org-babel-lilypond-midi-command " " midi-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
|
|
|
cmd-string
|
2012-03-19 16:38:12 -04:00
|
|
|
(start-process
|
|
|
|
"\"Audition midi\""
|
|
|
|
"*lilypond*"
|
ob-lilypond: Code cleanup
* lisp/ob-lilypond.el (org-babel-lilypond-OSX-ly-path,
org-babel-lilypond-OSX-pdf-path, org-babel-lilypond-OSX-midi-path,
org-babel-lilypond-nix-ly-path, org-babel-lilypond-nix-pdf-path,
org-babel-lilypond-nix-midi-path, org-babel-lilypond-w32-ly-path,
org-babel-lilypond-w32-pdf-path, org-babel-lilypond-w32-midi-path,
org-babel-lilypond-determine-ly-path,
org-babel-lilypond-determine-pdf-path,
org-babel-lilypond-determine-midi-path): Remove.
(org-babel-lilypond-ly-command, org-babel-lilypond-midi-command,
org-babel-lilypond-pdf-command): Replacement for removed variables
and functions. Adapt all calls to the removed functions to use
these variables instead.
(org-babel-lilypond-commands): New defcustom for setting up
the *-command variables. Keep different defaults for different
systems as the original code did to avoid tripping up unsuspecting
users.
(org-babel-lilypond-execute-tangled-ly,
org-babel-lilypond-check-for-compile-error): Revert conditions to
avoid superfluous forms. Remove unused return values.
* testing/lisp/test-ob-lilypond.el: Do test for new variables and
replace removed function calls with the appropriate variable
content. Exercise the new defcustom thoroughly.
2014-08-17 04:29:24 -04:00
|
|
|
org-babel-lilypond-midi-command
|
2012-03-19 16:38:12 -04:00
|
|
|
midi-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message "No midi file generated so can't play!")))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-midi-play ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether midi will be played following a successful compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-play-midi-post-tangle
|
|
|
|
(not org-babel-lilypond-play-midi-post-tangle))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "Post-Tangle MIDI play has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-play-midi-post-tangle
|
2011-06-28 20:40:17 -04:00
|
|
|
"ENABLED." "DISABLED."))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-pdf-display ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether pdf will be displayed following a successful compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-display-pdf-post-tangle
|
|
|
|
(not org-babel-lilypond-display-pdf-post-tangle))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "Post-Tangle PDF display has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-display-pdf-post-tangle
|
2011-06-28 20:40:17 -04:00
|
|
|
"ENABLED." "DISABLED."))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-png-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether png image will be generated by compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-png (not org-babel-lilypond-gen-png))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "PNG image generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-png "ENABLED." "DISABLED."))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-html-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether html will be generated by compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-html (not org-babel-lilypond-gen-html))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "HTML generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-html "ENABLED." "DISABLED."))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-pdf-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether pdf will be generated by compilation."
|
2012-03-19 16:38:12 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-pdf (not org-babel-lilypond-gen-pdf))
|
2012-03-19 16:38:12 -04:00
|
|
|
(message (concat "PDF generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-pdf "ENABLED." "DISABLED."))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-arrange-mode ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether in Arrange mode or Basic mode."
|
2011-07-06 09:17:29 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-arrange-mode
|
|
|
|
(not org-babel-lilypond-arrange-mode))
|
2011-07-06 09:17:29 -04:00
|
|
|
(message (concat "Arrange mode has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-arrange-mode "ENABLED." "DISABLED."))))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-switch-extension (file-name ext)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Utility command to swap current FILE-NAME extension with EXT"
|
|
|
|
(concat (file-name-sans-extension
|
|
|
|
file-name) ext))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-get-header-args (mode)
|
2011-07-06 09:17:29 -04:00
|
|
|
"Default arguments to use when evaluating a lilypond
|
2012-08-11 13:10:44 -04:00
|
|
|
source block. These depend upon whether we are in arrange
|
|
|
|
mode i.e. ARRANGE-MODE is t"
|
2011-07-06 09:17:29 -04:00
|
|
|
(cond (mode
|
|
|
|
'((:tangle . "yes")
|
|
|
|
(:noweb . "yes")
|
|
|
|
(:results . "silent")
|
2012-03-19 16:38:12 -04:00
|
|
|
(:cache . "yes")
|
2011-07-06 09:17:29 -04:00
|
|
|
(:comments . "yes")))
|
|
|
|
(t
|
|
|
|
'((:results . "file")
|
|
|
|
(:exports . "results")))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-set-header-args (mode)
|
2011-07-06 09:17:29 -04:00
|
|
|
"Set org-babel-default-header-args:lilypond
|
2014-08-20 15:10:00 -04:00
|
|
|
dependent on ORG-BABEL-LILYPOND-ARRANGE-MODE"
|
2011-07-06 09:17:29 -04:00
|
|
|
(setq org-babel-default-header-args:lilypond
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-get-header-args mode)))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(provide 'ob-lilypond)
|
2011-06-30 14:06:22 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
;;; ob-lilypond.el ends here
|