|
@@ -55,12 +55,13 @@ let make_uniq dubbled_entries =
|
|
|
| true -> false))
|
|
|
;;
|
|
|
|
|
|
-(* Removing doubled entries (cmds). We need to remove carriage return before
|
|
|
- * deduplicating, since they don't need to be in rc file, and the first one
|
|
|
- * would be kept during deduplication. *)
|
|
|
-let prettify rc_file =
|
|
|
- let cmds = rc_file.Settings_v.progs in
|
|
|
- let without_lr = (* Removing line return, and trailing spaces *)
|
|
|
+(* Remove doubled or void entries in a list. Commands are cleanup (removing
|
|
|
+ * space caracters at the bottom and at the end) *)
|
|
|
+(* TODO Test it separatly, reusing tests from edit_command.ml *)
|
|
|
+let prettify_cmd cmds =
|
|
|
+ let without_lr =
|
|
|
+ (* Removing line return, and trailing spaces, at the end or
|
|
|
+ at the start of a command *)
|
|
|
List.filter_map cmds ~f:(fun str ->
|
|
|
trim str |> function
|
|
|
| "" ->
|
|
@@ -68,19 +69,26 @@ let prettify rc_file =
|
|
|
None
|
|
|
| s -> Some s)
|
|
|
in
|
|
|
- let unique = make_uniq without_lr in
|
|
|
- (* Store the deduplicated list in new rc_file *)
|
|
|
- let unified_rc = {rc_file with Settings_v.progs = unique} in
|
|
|
- (* If there is the same number of element, each one is present only once. *)
|
|
|
- if List.(length unique = length without_lr) then
|
|
|
- begin
|
|
|
- Messages.debug "No duplicate found";
|
|
|
- unified_rc
|
|
|
- end
|
|
|
+
|
|
|
+ (* Remove doubled entries *)
|
|
|
+ let unified_rc = make_uniq without_lr in
|
|
|
+
|
|
|
+ (* Display whether duplicates were found *)
|
|
|
+ if List.(length unified_rc = length without_lr) then
|
|
|
+ Messages.debug "No duplicate found"
|
|
|
else
|
|
|
- begin
|
|
|
- Messages.debug "Duplicate found, removed";
|
|
|
- unified_rc
|
|
|
- end
|
|
|
+ Messages.debug "Duplicate found, removed";
|
|
|
+
|
|
|
+ unified_rc
|
|
|
+;;
|
|
|
+
|
|
|
+(* Removing doubled entries (cmds). We need to remove carriage return before
|
|
|
+ * deduplicating, since they don't need to be in rc file, and the first one
|
|
|
+ * would be kept during deduplication. *)
|
|
|
+let prettify rc_file =
|
|
|
+ let cmds = rc_file.Settings_v.progs in
|
|
|
+ let unique = prettify_cmd cmds in
|
|
|
+ (* Store the deduplicated list in new rc_file *)
|
|
|
+ {rc_file with Settings_v.progs = unique}
|
|
|
;;
|
|
|
|