Browse Source

Code clean-up

 + Modified: add_command.ml, clean_command.ml, const.ml,
 edit_command.ml.
 + Correct comment, factorise, reindent.
Leo 9 years ago
parent
commit
d58298563e
4 changed files with 22 additions and 17 deletions
  1. 11 8
      src/add_command.ml
  2. 1 0
      src/clean_command.ml
  3. 1 1
      src/const.ml
  4. 9 8
      src/edit_command.ml

+ 11 - 8
src/add_command.ml

@@ -42,24 +42,27 @@ open Core.Std;;
 let new_list current_list position new_items =
   match position with
   | None -> List.append current_list new_items
-  | Some n -> (* If a number is given, add commands after position n by
-                 splitting the list and concatenating all. List.split_n works like this :
-               * #let l1 = [1;2;3;4;5;6] in
-               * # List.split_n l1 2;;
-               * - : int list * int list = ([1; 2], [3; 4; 5; 6]) *)
+  | Some n ->
+    (* If a number is given, add commands after position n by
+       splitting the list and concatenating all. List.split_n works like this:
+     * #let l1 = [1;2;3;4;5;6] in
+     * # List.split_n l1 2;;
+     * - : int list * int list = ([1; 2], [3; 4; 5; 6]) *)
     let l_begin,l_end = List.split_n current_list n in
     List.concat [ l_begin ; new_items ; l_end ]
 ;;
 
-
-
 (* Function which add the commands (one per line) ridden on stdin to the rc
  * file, and then display th new configuration *)
 let run ~(rc:File_com.t) position =
   (* Read command from stdin, as a list. fix_win_eol removes \r\n *)
   let cmd_list = In_channel.input_lines ~fix_win_eol:true In_channel.stdin in
   (* Create an updated rc file *)
-  let updated_rc = { rc with Settings_t.progs = (new_list rc.Settings_t.progs position cmd_list)} in
+  let updated_rc =
+    { rc with
+      Settings_t.progs = (new_list rc.Settings_t.progs position cmd_list)
+    }
+  in
   File_com.write updated_rc;
   (* Display the result *)
   let reread_rc = File_com.init_rc () in

+ 1 - 0
src/clean_command.ml

@@ -37,6 +37,7 @@
 open Core.Std;;
 
 let run ~rc () =
+  (* Everything is done in background by File_com.write *)
   File_com.write rc;
   Messages.debug "Configuration file cleaned up";
 ;;

+ 1 - 1
src/const.ml

@@ -34,7 +34,7 @@
 (*  termes.                                                                   *)
 (******************************************************************************)
 
-(* File to stock configuration variables *)
+(* File to store configuration variables *)
 
 open Core.Std;;
 

+ 9 - 8
src/edit_command.ml

@@ -73,7 +73,7 @@ let gen_modification items =
 ;;
 
 (* Function which get the nth element, put it in a file, let the user edit it,
- * and then remplace with the new result *)
+ * and then replace with the result *)
 let rec run ~(rc:File_com.t) position =
   (* Current list of commands *)
   let current_list = rc.Settings_t.progs in
@@ -83,26 +83,27 @@ let rec run ~(rc:File_com.t) position =
     "/tmp/oc_edit_" ;
     (Int.to_string (Random.int 100_000)) ;
     ".txt" ;
-  ] in
-  let tmp_edit = String.concat tmp_filename in
+  ]
+  |> String.concat
+  in
   (* Remove item to be edited *)
   let original_command,shorter_list =
     Remove_command.remove current_list position
   in
-  Out_channel.write_all tmp_edit original_command;
+  Out_channel.write_all tmp_filename original_command;
 
 
   (* Edit file *)
-  let edit = String.concat [ Lazy.force Const.editor ; " " ; tmp_edit ] in
+  let edit = String.concat [ Lazy.force Const.editor ; " " ; tmp_filename ] in
   Messages.debug edit;
   Sys.command edit
   |> (function
          0 -> ()
-       | n -> sprintf "Error while running %s: error code %i" edit n
-              |> Messages.warning);
+       | n -> sprintf
+         "Error while running %s: error code %i" edit n |> Messages.warning);
 
   (* Reading and applying the result *)
-  let new_commands = In_channel.read_lines tmp_edit |> epur in
+  let new_commands = In_channel.read_lines tmp_filename |> epur in
   let cmd_list = new_list shorter_list position new_commands in
   let updated_rc = { rc with Settings_t.progs = cmd_list} in
   File_com.write updated_rc;