Commits

seanmcl committed 5f1b422

kill-when-unwatched bug

Comments (0)

Files changed (3)

elisp/omake/omake-custom.el

   "If t, prompt y/n before killing a project"
   :group 'omake
   :type 'boolean)
+;; (setq Omake.prompt-before-killing-project t)
 ;; (setq Omake.prompt-before-killing-project nil)
 
 (defcustom Omake.split-frame-horizontally t

ocaml/omake/project.ml

     Log.printf "ERROR: %s" (Exn.to_string exn);
     raise exn
 
+let kill t =
+  Emacs.kill_model t.id;
+  let pid = Pid.to_string t.pid in
+  let kids = try_with (fun () ->
+    Ashell.run_lines "pgrep" ["-P"; pid]) >>| function
+  | Ok kids -> kids
+  | Error _ -> []
+  in
+  kids >>= fun kids ->
+  try_with (fun () ->
+    Deferred.List.iter kids ~f:(fun k -> Ashell.run "kill" [k]) >>= fun () ->
+    Ashell.run "kill" [pid]) >>| function
+  | Ok () -> ()
+  | Error exn ->
+    Log.exn ~msg:"Error killing processes" exn
+
 let start t =
   let module U = File_tail.Update in
   let module W = File_tail.Warning in
     Writer.save file ~contents:elisp >>| fun () ->
     Emacs.Async.load_elisp_file id)
 
+let kill_when_unwatched t =
+  let ivar = Ivar.create () in
+  let stop = Ivar.read ivar in
+  if Config.kill_when_unwatched () then
+    Clock.every'
+      ~start:(Clock.after (Time.Span.of_sec 3.))
+      ~stop
+      (Time.Span.of_sec 3.)
+      (fun () ->
+        if num_watching t = 0 then
+          begin
+            Log.printf "Killing unwatched project: %s" (Id.to_string t.id);
+            kill t >>| fun () -> Ivar.fill ivar ()
+          end
+        else Deferred.unit)
+
 let create t =
   create1 t >>| fun t ->
+  kill_when_unwatched t;
   (* start never returns *)
   whenever (start t);
   t
 
-let kill t =
-  Emacs.kill_model t.id;
-  let pid = Pid.to_string t.pid in
-  let kids = try_with (fun () ->
-    Ashell.run_lines "pgrep" ["-P"; pid]) >>| function
-  | Ok kids -> kids
-  | Error _ -> []
-  in
-  kids >>= fun kids ->
-  try_with (fun () ->
-    Deferred.List.iter kids ~f:(fun k -> Ashell.run "kill" [k]) >>= fun () ->
-    Ashell.run "kill" [pid]) >>| function
-  | Ok () -> ()
-  | Error exn ->
-    Log.exn ~msg:"Error killing processes" exn
-
 let to_elisp t =
   sprintf "
     (Omake.Project.create

ocaml/omake/query.ml

   let ivar = Ivar.create () in
   let stop = Ivar.read ivar in
   Clock.every' ~stop (Time.Span.of_sec 3.) (fun () ->
-    (* Send the 0 signal (are you alive?) to emacs *)
+    (* Send the 0 signal (are you alive?) to emacs. *)
     match Result.try_with (fun () -> Signal.send_exn Signal.zero (`Pid pid)) with
     | Ok () -> Deferred.unit
     | Error exn ->
   let ivar = Ivar.create () in
   let stop = Ivar.read ivar in
   Clock.every' ~stop (Time.Span.of_sec 3.) (fun () ->
-    (* Send the 0 signal (are you alive?) to emacs *)
+    (* Send the 0 signal (are you alive?) to omake. *)
     match Result.try_with (fun () -> Signal.send_exn Signal.zero (`Pid pid)) with
     | Ok () -> Deferred.unit
     | Error exn ->
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.