Skip to content

Commit

Permalink
Added auto reload on mtime change
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed May 4, 2023
1 parent fa0f880 commit b4d9177
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/docfd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ let run
Printf.printf "Error: Both env variables VISUAL and EDITOR are unset\n"; exit 1
| Some editor, _
| None, Some editor -> (
let old_stats = Unix.stat path in
Sys.command (Fmt.str "%s \'%s\'" editor path) |> ignore;
let new_stats = Unix.stat path in
if Float.abs (new_stats.st_mtime -. old_stats.st_mtime) >= 0.000_001 then (
(match Lwd.peek Ui_base.Vars.ui_mode with
| Ui_single_file -> Single_file_view.reload_document doc
| Ui_multi_file -> Multi_file_view.reload_document_selected ()
);
);
loop ()
)
in
Expand Down

0 comments on commit b4d9177

Please sign in to comment.