From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id AAB9DBBAF for ; Thu, 8 Apr 2010 12:58:29 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlIGAKxTvUuEuwMcmWdsb2JhbACPYohagwgBAQEBAQgLCgcRIrhPhQkE X-IronPort-AV: E=Sophos;i="4.52,169,1270418400"; d="scan'208";a="48171243" Received: from mailrelay.rz.uni-wuerzburg.de ([132.187.3.28]) by mail3-smtp-sop.national.inria.fr with ESMTP; 08 Apr 2010 12:58:29 +0200 Received: from virusscan.mail (localhost [127.0.0.1]) by mailrelay.mail (Postfix) with ESMTP id DF9C25ACD6 for ; Thu, 8 Apr 2010 12:58:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by virusscan.mail (Postfix) with ESMTP id DD3095AC72 for ; Thu, 8 Apr 2010 12:58:28 +0200 (CEST) X-Virus-Scanned: by amavisd-new at uni-wuerzburg.de Received: from mail.physik.uni-wuerzburg.de (wthp192.physik.uni-wuerzburg.de [132.187.40.192]) by mailmaster.uni-wuerzburg.de (Postfix) with ESMTP id BDFA65CE32 for ; Thu, 8 Apr 2010 12:58:28 +0200 (CEST) Received: from wthp058.physik.uni-wuerzburg.de ([132.187.40.58]) by mail.physik.uni-wuerzburg.de (Lotus Domino Release 8.5.1FP2) with ESMTP id 2010040812582844-4481 ; Thu, 8 Apr 2010 12:58:28 +0200 Received: by wthp058.physik.uni-wuerzburg.de (Postfix, from userid 11210) id 3626347A7A; Thu, 8 Apr 2010 12:58:28 +0200 (CEST) To: caml-list@yquem.inria.fr Subject: Format: Fortran (&c.) style continuation lines? Reply-To: ohl@physik.uni-wuerzburg.de Message-Id: <20100408105828.3626347A7A@wthp058.physik.uni-wuerzburg.de> Date: Thu, 8 Apr 2010 12:58:28 +0200 (CEST) From: ohl@physik.uni-wuerzburg.de (Thorsten Ohl (TP2)) X-MIMETrack: Itemize by SMTP Server on domino1/uni-wuerzburg(Release 8.5.1FP2|March 17, 2010) at 04/08/2010 12:58:28 PM, Serialize by Router on domino1/uni-wuerzburg(Release 8.5.1FP2|March 17, 2010) at 04/08/2010 12:58:28 PM, Serialize complete at 04/08/2010 12:58:28 PM X-Spam: no; 0.00; ohl:01 thorsten:01 ohl:01 foo:01 printf:01 foo:01 printf:01 -thorsten:01 thorsten:01 wuerzburg:01 lexical:01 functions:01 functions:01 bin:01 newline:02 Hi, for ages, I've been using the following (somewhat hackish) approach to pretty printing source code that requires special lexical markers to allow statements that continue over more than one line. (e.g. in Fortran foo = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 & + 1 + 1 + 1 + 1 + 1 + 1 + 1 and in /bin/sh we have the same with "\\" instead of "&"): open Format;; let continuing = ref true;; let wrap_newline () = let out, flush, newline, space = get_all_formatter_output_functions () in let newline' () = if !continuing then out " &" 0 2; newline () in set_all_formatter_output_functions out flush newline' space;; let nl () = continuing := false; print_newline (); continuing := true;; let _ = wrap_newline ();; (* Nonsensical example: *) for statement = 1 to 3 do printf " @[<2>foo = 1"; for i = 1 to 100 do printf "@, + 1" done; nl () done;; The requirement to end each statement with "nl ()" is tedious in real world applications and the use of the global variable "continuing" violates my sense of aesthetics... Is there a more idiomatic approach that I'm missing? Thanks, -Thorsten -- Thorsten Ohl, Wuerzburg Univ., Physics -- http://physik.uni-wuerzburg.de/ohl