Previous week Up Next week


Here is the latest Caml Weekly News, for the week of September 30 to October 07, 2008.

  1. The OSP end-of-summer meeting
  2. Syntax highlighting and Ocaml/PHP integration

The OSP end-of-summer meeting


Yaron Minsky announced:
For those of you interested in what happened at the OSP end-of-summer 
meeting, I posted my summary on our blog.
Stefano Zacchiroli then suggested:
FWIW, I remind you all that Janest' blog is aggregated, together with 
many other OCaml-related blog, on the OCaml Planet, available at .

Syntax highlighting and Ocaml/PHP integration


Dario Teixeira asked:
I'm looking for a GPL-compatible syntax highlighting library with support 
for most common programming languages and markups.  Obviously I would 
prefer a native Ocaml library, though something in C would also be 
acceptable due the relative ease of writing bindings. 

One library that looks competent is GeSHi [1].  Unfortunately it is 
written in PHP.  However, for lack of alternatives, I am looking into 
ways of integrating GeSHi with Ocaml. 

I reckon that a shell invocation of PHP is straightforward, but I bet 
that it would entail a huge performance penalty due to the startup time. 
Therefore, I am looking into somehow integrating the PHP interpreter 
within the main Ocaml programme.  Something like Apache's mod_php. 
Does anyone have any experience with this?  (Note that I have *zero* 
experience with PHP). 

If all else fails, my backup solution is simply to run a small webserver 
with GeSHi and transform the library call into a web service.  Though I 
would rather avoid this convoluted option. 

Thanks in advance for your input! 
Best regards, 
Dario Teixeira 

P.S.  Another (possibly far-fetched) solution is to take advantage of the 
      syntax highlighting capabilities of Vim or Emacs.  Something along 
      the lines of embedding or remotely invoking one of these editors, 
      with the sole purpose of asking them to highlight a text file. 
      Is this even possible? 

Dave Benjamin suggested:
I have had decent results opening a pipe to GNU source-highlight. I'm 
mainly using it on JSON, so I can't vouch for its support of other 
languages but it seems pretty comprehensive. 
let pipe program input = 

   let (in_channel, out_channel) = Unix.open_process program in 
   output_string out_channel input; 
   close_out out_channel; 
   let result = ref [] in 
       while true do 
         result := input_line in_channel :: !result 
     with End_of_file -> () 
   ignore (Unix.close_process (in_channel, out_channel)); 
   String.concat "\n" (List.rev !result) 

let pre_body = Pcre.regexp ~flags:[`DOTALL] ".*<pre>(.*)</pre>.*" 

let source_highlight lang code = 
   let result = pipe ("source-highlight -s " ^ lang) code in 
   Pcre.replace ~rex:pre_body ~templ:"$1" result 

Caveat: The "pipe" function above will block on large inputs due to 
buffering deadlock. It should probably be rewritten using
Martin Jambon also suggested:
I've used vim a little bit for my static webpages, here's the result: 
The script is: 
#!/bin/sh -e 
# Usage : any2html <file1> [<file2> ...] 
# Requires : vim 
[ $# -lt 1 ] && echo "Usage : $0 <fic1> <fic2> ..." && exit 1 
while [ -n "$1" ] 
     file=`basename "$1"` 
     cp -f "$1" /tmp 
     vim -f +"syn on" +"so \\\$VIMRUNTIME/syntax/2html.vim" +"wq" +"q" /tmp/"$file" 
     cp -f /tmp/"$file".html "$1".html 
Adrien Nader suggested:
You might try Highlight[1] and Caml2html[2]. I know I've tried
Highlight but I simply can't remember how the result looked like, most
probably because I needed to write to a tex file (I still don't know
if there's anything with color support). Caml2html generates nice
pages but only supports the ocaml language, it's written in ocaml

OK, tried hightlight again... Its output is less colorized than vim's
but still alright and this can be changed. It's GPLv2. The drawback is
that it's written in C++ so probably not the best solution if you want
to hack it. (* I've been going through (p)7zip to write bindings, why
does C++ have to be that horrible ? *) The code might be perfectly
understandable though, I've not looked at it.


Using folding to read the cwn in vim 6+

Here is a quick trick to help you read this CWN if you are viewing it using vim (version 6 or greater).

:set foldmethod=expr
:set foldexpr=getline(v:lnum)=~'^=\\{78}$'?'&lt;1':1

If you know of a better way, please let me know.

Old cwn

If you happen to miss a CWN, you can send me a message and I'll mail it to you, or go take a look at the archive or the RSS feed of the archives.

If you also wish to receive it every week by mail, you may subscribe online.

Alan Schmitt