From mboxrd@z Thu Jan 1 00:00:00 1970 From: Martyn Jago Subject: [BABEL][PATCH] ob-lilypond basic mode - was ob-lilypond Date: Wed, 6 Jul 2011 09:13:36 +0100 Message-ID: <1F2BF18C-4151-4461-9FE3-4FC6E3F909F4@btinternet.com> References: <87k4c79kdg.fsf@gmail.com> <87d3hyl15p.fsf@gnu.org> <874o3al0ib.fsf@gnu.org> <87zkl1bs7s.fsf@gmail.com> <87r56c5ogi.fsf@gmail.com> <87ei2b8a1z.fsf@gmail.com> <4E0DB72F.8020200@christianmoe.com> Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: multipart/alternative; boundary=Apple-Mail-18-920334610 Return-path: Received: from eggs.gnu.org ([140.186.70.92]:47832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QeNEu-0004fR-Ov for emacs-orgmode@gnu.org; Wed, 06 Jul 2011 04:13:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QeNEr-0006Sn-RM for emacs-orgmode@gnu.org; Wed, 06 Jul 2011 04:13:44 -0400 Received: from nm2-vm0.bt.bullet.mail.ird.yahoo.com ([212.82.108.92]:41741) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1QeNEq-0006ST-GA for emacs-orgmode@gnu.org; Wed, 06 Jul 2011 04:13:41 -0400 In-Reply-To: <4E0DB72F.8020200@christianmoe.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: mail@christianmoe.com Cc: emacs-orgmode@gnu.org --Apple-Mail-18-920334610 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi I've added functionality to make ob-lilypond act in a consistent = org-babel way by default (think ob-dot). The previous modus operandi is now known as arrange-mode and is selected = by setting ly-arrange-mode to t More details including examples are at = http://github.com/mjago/ob-lilypond Patch:=20 Included examples are as follows... - Export org file with lilypond fragments to pdf using eps (high = quality vector graphics) - org source: = https://github.com/mjago/ob-lilypond/raw/master/examples/basic-mode/pdf-ex= ample/pdf-example.org - resultant pdf: = https://github.com/mjago/ob-lilypond/blob/master/examples/basic-mode/pdf-e= xample/pdf-example.pdf?raw=3Dtrue - Export org file with lilypond fragments to html using png - org source: = https://github.com/mjago/ob-lilypond/raw/master/examples/basic-mode/html-e= xample/html-example.org - resultant html: = https://raw.github.com/mjago/ob-lilypond/master/examples/basic-mode/html-e= xample/html-example.html Regards Martyn On 1 Jul 2011, at 13:01, Christian Moe wrote: > On 6/30/11 8:10 PM, Eric Schulte wrote: >> Martyn Jago writes: >>> (...) >> Great, I've just moved this into the Org-mode core and added it to = the >> list of Babel languages. >=20 > Great! >=20 >>>=20 >>> One distinction that has occurred to me (especially following = comments on >>> the mailing list) is that of "babel language" and "babel language = work-flow". >>> In other words, I can visualise refactoring ob-lilypond to be no = more than >>> a specification of the Lilypond syntax, and working in parallel, on = a >>> work-flow implementation for Lilypond that is "opinionated" in terms = of >>> adjusting org-babel settings away from their defaults / removing = work-flow >>> noise etc. ( org-lilypond.el ) ? Would this make sense, and if so = where would >>> it live (aligned to org-babel / a native Emacs mode perhaps)? >>> I hope that makes sense. >>>=20 >>=20 >> That sounds like a good idea. Ideally ob-lilypond should include = just >> those elements expected by the code block interface, namely functions >> for session/external evaluation, for expanding variables in code = block >> bodies, and for returning results to Org-mode. I think that it would = be >> a good idea to develop an external org-lilypond to support a more >> comprehensive workflow. >=20 > I like this. >=20 > I certainly see that the already complex task of making arrangements = like those in Martyn's examples should be made as easy as possible. >=20 > As for the comparatively simple use cases I brought up, once they're = supported by ob-lilypond I'd be perfectly happy to throw header = arguments at them. >=20 > Yours, > Christian --Apple-Mail-18-920334610 Content-Type: multipart/mixed; boundary=Apple-Mail-19-920334610 --Apple-Mail-19-920334610 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset=us-ascii Hi

I've added functionality to make ob-lilypond act in a consistent org-babel way by default (think ob-dot).
The previous modus operandi is now known as arrange-mode and is selected by setting ly-arrange-mode to t

More details including examples are at http://github.com/mjago/ob-lilypond

Patch: 
--Apple-Mail-19-920334610 Content-Disposition: attachment; filename=basic-mode.patch Content-Type: application/octet-stream; name="basic-mode.patch" Content-Transfer-Encoding: 7bit diff --git a/lisp/ob-lilypond.el b/lisp/ob-lilypond.el index 39aa78c..d09a5b0 100644 --- a/lisp/ob-lilypond.el +++ b/lisp/ob-lilypond.el @@ -5,7 +5,7 @@ ;; Author: Martyn Jago ;; Keywords: babel language, literate programming ;; Homepage: https://github.com/mjago/ob-lilypond -;; Version: 0.2 +;; Version: 0.3 ;; This file is part of GNU Emacs. @@ -33,7 +33,7 @@ (defalias 'lilypond-mode 'LilyPond-mode) (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.") (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 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) "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) "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 () "ob-lilypond specific tangle, attempts to invoke @@ -119,6 +130,32 @@ specific arguments to =org-babel-tangle=" (if (org-babel-tangle nil "yes" "lilypond") (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) "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-4 t) ;display (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-8 (if ly-gen-svg "-dbackend=svg" "")) (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 () "Toggle whether png image will be generated by compilation" - + (interactive) (setq 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 () "Toggle whether html will be generated by compilation" - + (interactive) (setq ly-gen-html (not ly-gen-html)) (message (concat "HTML generation has been " (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) (interactive) (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) "Utility command to swap current FILE-NAME extension with EXT" - + (concat (file-name-sans-extension 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) ;; arch-tag: ac449eea-2cf2-4dc5-ae33-426f57ba4894 - + ;;; ob-lilypond.el ends here diff --git a/testing/lisp/test-ob-lilypond.el b/testing/lisp/test-ob-lilypond.el index 16d6f09..4ade387 100644 --- a/testing/lisp/test-ob-lilypond.el +++ b/testing/lisp/test-ob-lilypond.el @@ -31,10 +31,10 @@ (should (boundp 'ly-version))) (ert-deftest ob-lilypond/ly-version-command () - (should (equal "ob-lilypond version 0.2" (ly-version))) + (should (equal "ob-lilypond version 0.3" (ly-version))) (with-temp-buffer (ly-version t) - (should (equal "ob-lilypond version 0.2" + (should (equal "ob-lilypond version 0.3" (buffer-substring (point-min) (point-max)))))) (ert-deftest ob-lilypond/ly-compile-lilyfile () @@ -108,12 +108,15 @@ (ert-deftest ob-lilypond/use-eps () (should (boundp 'ly-use-eps))) -(ert-deftest ob-lilypond/org-babel-default-header-args:lilypond () - (should (equal '((:tangle . "yes") - (:noweb . "yes") - (:results . "silent") - (:comments . "yes")) - org-babel-default-header-args:lilypond))) +(ert-deftest ob-lilypond/ly-arrange-mode () + (should (boundp 'ly-arrange-mode))) + +;; (ert-deftest ob-lilypond/org-babel-default-header-args:lilypond () +;; (should (equal '((:tangle . "yes") +;; (:noweb . "yes") +;; (:results . "silent") +;; (:comments . "yes")) +;; org-babel-default-header-args:lilypond))) ;;TODO finish... (ert-deftest ob-lilypond/org-babel-expand-body:lilypond () @@ -196,7 +199,7 @@ (pdf-file (concat ly-here "../examples/ob-lilypond-test.pdf"))) - (setq ly-open-pdf-post-tangle t) + (setq ly-display-pdf-post-tangle t) (when (not (file-exists-p pdf-file)) (set-buffer (get-buffer-create (file-name-nondirectory pdf-file))) (write-file pdf-file)) @@ -257,7 +260,7 @@ (ly-determine-midi-path "win32"))) (should (equal ly-nix-midi-path (ly-determine-midi-path "nix")))) - + (ert-deftest ob-lilypond/ly-toggle-midi-play-toggles-flag () (if ly-play-midi-post-tangle (progn @@ -282,6 +285,18 @@ (ly-toggle-pdf-display) (should (not ly-display-pdf-post-tangle)))) +(ert-deftest ob-lilypond/ly-toggle-arrange-mode () + (if ly-arrange-mode + (progn + (ly-toggle-arrange-mode) + (should (not ly-arrange-mode)) + (ly-toggle-arrange-mode) + (should ly-arrange-mode)) + (ly-toggle-arrange-mode) + (should ly-arrange-mode) + (ly-toggle-arrange-mode) + (should (not ly-arrange-mode)))) + (ert-deftest ob-lilypond/ly-toggle-png-generation-toggles-flag () (if ly-gen-png (progn @@ -293,7 +308,7 @@ (should ly-gen-png) (ly-toggle-png-generation) (should (not ly-gen-png)))) - + (ert-deftest ob-lilypond/ly-toggle-html-generation-toggles-flag () (if ly-gen-html (progn @@ -318,6 +333,29 @@ (should (equal "/some/path/to/test-name.xyz" (ly-switch-extension "/some/path/to/test-name" ".xyz")))) +(ert-deftest ob-lilypond/ly-get-header-args () + (should (equal '((:tangle . "yes") + (:noweb . "yes") + (:results . "silent") + (:comments . "yes")) + (ly-set-header-args t))) + (should (equal '((:results . "file") + (:exports . "results")) + (ly-set-header-args nil)))) + +(ert-deftest ob-lilypond/ly-set-header-args () + (ly-set-header-args t) + (should (equal '((:tangle . "yes") + (:noweb . "yes") + (:results . "silent") + (:comments . "yes")) + org-babel-default-header-args:lilypond)) + (ly-set-header-args nil) + (should (equal '((:results . "file") + (:exports . "results")) + org-babel-default-header-args:lilypond))) + (provide 'test-ob-lilypond) ;;; test-ob-lilypond.el ends here + --Apple-Mail-19-920334610 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii https://github.com/mjago/ob-lilypond/raw/ma= ster/examples/basic-mode/pdf-example/pdf-example.org
 - Export org file with lilypond fragments to html = using png
<= br>
Regards

Martyn

<= div>On 1 Jul 2011, at 13:01, Christian Moe wrote:

On = 6/30/11 8:10 PM, Eric Schulte wrote:
Martyn = Jago<martyn.jago@btinternet.com&= gt;  writes:
(...)
Great, I've just moved this into the Org-mode core and = added it to the
list of Babel = languages.

Great!


One distinction that has = occurred to me (especially following comments = on
the mailing list) is that of "babel language" and "babel = language work-flow".
In other words, I can visualise = refactoring ob-lilypond to be no more = than
a specification of the Lilypond syntax, and working in = parallel, on a
work-flow implementation for = Lilypond that is "opinionated" in terms = of
adjusting org-babel settings away from their defaults / = removing work-flow
noise etc. ( org-lilypond.el ) ? = Would this make sense, and if so where = would
it live (aligned to org-babel / a native Emacs mode = perhaps)?
I hope that makes = sense.


That sounds = like a good idea.  Ideally ob-lilypond should include = just
those elements expected = by the code block interface, namely = functions
for session/external = evaluation, for expanding variables in code = block
bodies, and for = returning results to Org-mode.  I think that it would = be
a good idea to develop an = external org-lilypond to support a more
comprehensive workflow.

I like = this.

I certainly see that the already complex task of making = arrangements like those in Martyn's examples should be made as easy as = possible.

As for the comparatively simple use cases I brought up, = once they're supported by ob-lilypond I'd be perfectly happy to throw = header arguments at = them.

Yours,
Christian

= --Apple-Mail-19-920334610-- --Apple-Mail-18-920334610--