ARTIFACTS / Software / Impromptu Wiki Helper

DATE: Feb 2010
URL: wiki.scm
URL: Blog post
A scheme script that lets you access the online wiki/documentation from the Impromptu livecoding programming environment.

When you’re using Impromptu and don’t know the meaning or syntax of a function, the usual thing to do is call (help function-name) to get some help, or (help function-name #t)if you want to see also the examples associated with it. The help text gets displayed in the log view, so that you can copy/paste what you need from there. Quite useful, but nonetheless a bit too time-consuming and hard to read. Since a couple of months ago Impromptu has a wiki too – so I thought, it’d be nice to see a function’s help in a browser window, and possibly contribute to the function documentation too. So, that’s the rationale for this little utility function. By calling ‘wiki’ you can open up a web browser at the relevant Impromptu-wiki page.. as simple as that.
 

 
;===================
;(c) michelepasin.org
;===================

;;SCRIPT THAT LETS YOU ACCESS THE WIKI PAGES FOR THE IMPROMPTU PROGRAMMING ENVIRONMENT FROM THE EDITOR
;
;;USAGE
;Load the file in Impromptu, evaluate it and then you'll have access to the 'wiki' procedure. For example:
;
;(wiki gfx:scale-path) ;; looks up the gfx:scale-path documentation online
;
;More info on: http://www.michelepasin.org/musicblog/2010/02/15/impromptu-function-to-access-wiki-docs-from-the-editor/

;===================




;;;;;;;;;;;;;;;;;;;
;WEB HELPERS
;;;;;;;;;;;;;;;;;;;


;; open-url: calls the default mac browser with a url argument
;; disclaimer: I'm not an objc programmer... found an example at
;; http://macosx.com/forums/software-programming-web-scripting/18422-how-do-i-launch-url-using-cocoa-objective-c.html
(define util:open-url
   (lambda (urlstring)
      (let ((urlobj (objc:call "NSURL" "URLWithString:" urlstring))
            (workspace (objc:call "NSWorkspace" "sharedWorkspace")))
         (objc:call workspace "openURL:" urlobj))))





;;;;;;;;;;
;; wiki url caller
;;;;;;;;;;


(define wiki:wikiescape
   (lambda (funname)
      (for-each (lambda (x)
                   (set! funname (util:string-replace funname (car x) (cadr x))))
                '(("+" "%2B")
                  ("=" "%3D")
                  ("<" "lessthan")
                  (">" "greaterthan")
                  ("*" "%2A")
                  ("?" "%3F")
                  ("!" "%21")                
                  ))
      (util:string-capitalize funname)))


(define wiki:openurl
   (lambda (funname)
      (let* ((urlbase "http://moso.com.au/wiki/index.php?title=")
             (newname (wiki:wikiescape funname))
             (url (string-append urlbase newname)))
         (util:open-url url))))
         

;; macro wrapper
(define-macro (wiki name)
   `(wiki:openurl (sexpr->string (quote ,name))))