Commits

camlspotter committed 9c09aca

debug in el

Comments (0)

Files changed (2)

     modified : bool (* Has the source code ever modified ? *)
   } with sexp_of
 
-  let init = { bases = []; orig_indent = 0; last_indent = 0; last_token = None; }
+  let init = { bases = []; orig_indent = 0; last_indent = 0; last_token = None; modified = false }
 
   let indent t = Stack.indent t.last_indent t.bases
 end
 
   type t = (int * int) option
       
-  let add_string t lnum s =
+  let add_string ?(no_exit=false) t lnum s =
     let add_line t lnum s =
       match t with
       | None -> print_string s
       | Some (start, end_) ->
           if lnum < start then ()
-          else if lnum > end_ then raise Exit
+          else if lnum > end_ then if no_exit then () else raise Exit
           else print_string s
     in
     let get_line s =
             if debug then begin
               Printer.add_string printer current_line indent_string;
               if pre == post then 
-                Printer.add_string printer current_line 
+                Printer.add_string ~no_exit:true printer current_line 
                   (Printf.sprintf "-- %s\n" (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases)))
               else
-                Printer.add_string printer current_line 
+                Printer.add_string ~no_exit:true printer current_line 
                   (Printf.sprintf "-- %s // %s\n" 
                      (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t pre.bases))
                      (Sexplib.Sexp.to_string_mach (Stack.sexp_of_t post.bases)))
             if new_line then 
               { post with 
                 last_token = (if t <> COMMENT then Some t else state.last_token)
-                ; last_indent = State.indent pre 
+              ; last_indent = State.indent pre 
               }
             else 
               { post with 
 ;  'tuareg-mode-hook
 ;  '(lambda ()
 ;        ...
-;        (local-set-key (kbd "<C-tab>") 'ocaml-indent-run)
+;        (local-set-key (kbd "<C-tab>") 'ocaml-indent) ; Use <tab> if you dare.
 ;        ...
 ;        )...)
 
 (defconst ocaml-indent-process-buffer "*ocaml-indent-process*"
   "The name of ocaml-indent communication buffer")
 
-(defun ocaml-indent-run ()
-  (interactive)
+(defun ocaml-indent-run (&optional debug)
   (let ((region-active (and transient-mark-mode mark-active)))
     (let* 
 	((start-lnum
 	(with-current-buffer (get-buffer-create ocaml-indent-process-buffer)
 	  (erase-buffer))
 
-	(message (format "ocaml-indent -lines %d-%d" start-lnum end-lnum))
-	(call-process-region 1 end-char
-			     ocaml-indent-command
-			     nil ; delete
-			     ocaml-indent-process-buffer ; buffer
-			     nil ;display
-			     "-lines" (format "%d-%d" start-lnum end-lnum)
-			     )
+	(let* ((base-command '(call-process-region 1 end-char
+						   ocaml-indent-command
+						   nil ; delete
+						   ocaml-indent-process-buffer ; buffer
+						   nil ;display
+						   ))
+	       (base-options (list "-lines" (format "%d-%d" start-lnum end-lnum)))
+	       (options (if debug (append (list "-debug") base-options) base-options))
+	       (function (append base-command options))
+	       )
+	  (message "%S %S" ocaml-indent-command options)
+	  (eval function))
+
         ;; (display-buffer ocaml-indent-process-buffer)
 	(let ((indented
 	       (with-current-buffer ocaml-indent-process-buffer
 	    (insert indented)))
 	))))
 
+(defun ocaml-indent ()
+  (interactive)
+  (ocaml-indent-run))
+
+(defun ocaml-indent-debug ()
+  (interactive)
+  (ocaml-indent-run t))
+
 (provide 'ocaml-indent)