emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Martyn Jago <martyn.jago@btinternet.com>
To: mail@christianmoe.com
Cc: emacs-orgmode@gnu.org
Subject: [BABEL][PATCH] ob-lilypond basic mode - was  ob-lilypond
Date: Wed, 6 Jul 2011 09:13:36 +0100	[thread overview]
Message-ID: <1F2BF18C-4151-4461-9FE3-4FC6E3F909F4@btinternet.com> (raw)
In-Reply-To: <4E0DB72F.8020200@christianmoe.com>

[-- Attachment #1: Type: text/plain, Size: 2704 bytes --]

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: 

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-example/pdf-example.org
   - resultant pdf: https://github.com/mjago/ob-lilypond/blob/master/examples/basic-mode/pdf-example/pdf-example.pdf?raw=true
 - Export org file with lilypond fragments to html using png
   - org source: https://github.com/mjago/ob-lilypond/raw/master/examples/basic-mode/html-example/html-example.org
   - resultant html: https://raw.github.com/mjago/ob-lilypond/master/examples/basic-mode/html-example/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<martyn.jago@btinternet.com>  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


[-- Attachment #2.1: Type: text/html, Size: 572 bytes --]

[-- Attachment #2.2: basic-mode.patch --]
[-- Type: application/octet-stream, Size: 9516 bytes --]

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
+ 

[-- Attachment #2.3: Type: text/html, Size: 4613 bytes --]

  reply	other threads:[~2011-07-06  8:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-27 13:00 ob-lilypond Martyn Jago
2011-06-27 18:53 ` ob-lilypond Eric Schulte
2011-06-28  9:38   ` ob-lilypond Martyn Jago
2011-06-28 10:07     ` ob-lilypond Bastien
2011-06-28 10:21       ` ob-lilypond Bastien
2011-06-28 20:45         ` ob-lilypond Eric Schulte
2011-06-28 23:07           ` ob-lilypond Bastien
2011-06-29  0:41             ` ob-lilypond Eric Schulte
2011-06-29 17:07           ` ob-lilypond Martyn Jago
2011-06-29 21:15             ` ob-lilypond Eric Schulte
2011-06-30  6:38               ` ob-lilypond Martyn Jago
2011-06-30 18:10                 ` ob-lilypond Eric Schulte
2011-07-01 12:01                   ` ob-lilypond Christian Moe
2011-07-06  8:13                     ` Martyn Jago [this message]
2011-07-06 13:20                       ` [BABEL][PATCH] ob-lilypond basic mode - was ob-lilypond Eric Schulte
2011-07-01 13:43                   ` ob-lilypond Martyn Jago
2011-07-01 19:27                     ` ob-lilypond Eric Schulte
2011-07-02 13:04                       ` ob-lilypond Martyn Jago
2011-06-28 13:38     ` ob-lilypond Cameron Horsburgh
2011-06-28 16:46       ` ob-lilypond Martyn Jago
2011-06-28 12:11 ` ob-lilypond Christian Moe
2011-06-28 13:18   ` ob-lilypond David O'Toole
2011-06-28 17:06   ` ob-lilypond Martyn Jago
2011-06-28 18:51     ` ob-lilypond Christian Moe
2011-06-28 19:00     ` ob-lilypond Michael Brand
2011-06-28 20:00     ` ob-lilypond Christian Moe
2011-06-28 21:19       ` ob-lilypond Martyn Jago

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1F2BF18C-4151-4461-9FE3-4FC6E3F909F4@btinternet.com \
    --to=martyn.jago@btinternet.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@christianmoe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).