Commits

camlspotter committed f6085f8

first interactive indentation!

Comments (0)

Files changed (1)

 	    (line-number-at-pos (progn
 				  (if region-active (goto-char (region-beginning)))
 				  (point)))))
-	 (end-lnum 
+	 (end-lnum- 
 	  (save-excursion 
 	    (line-number-at-pos (progn
 				  (if region-active (progn
 						      (goto-char (region-end))
-						      (forward-char -1)))
+						      (forward-char -1))) 
 				  (point)))))
 
+	 ; When the region is active but size 0, at the line head, end-lnum- < start-lnum .
+ 	 ; Fix is required.
+	 (end-lnum (max start-lnum end-lnum-)) 
+	 (start-char
+	  (save-excursion
+	    (goto-char (point-min)) (forward-line (1- start-lnum)) ; to line (start-lnum)
+	    (point)))
+
 	 (end-char
 	  (save-excursion
 	    (goto-char (point-min)) (forward-line end-lnum) ; to line (end-lnum + 1)
 	(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
 			     "/home/jfuruse/.share/projects/ocaml-indent/indent" 
 			     nil ; delete
 			     "-lines" (format "%d-%d" start-lnum end-lnum)
 			     )
 	(display-buffer ocaml-indent-process-buffer)
+	(let ((indented
+	       (with-current-buffer ocaml-indent-process-buffer
+		 (buffer-substring (point-min) (point-max)))))
+	  (save-excursion
+	    (delete-region start-char end-char)
+	    (goto-char start-char)
+	    (insert indented)))
 	))))