From 12dd581b996106e1623ff3db1936a2388c7c6ba0 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Mon, 13 Feb 2012 10:21:10 +0100 Subject: [PATCH] allow to gracefully quit utop in emacs Ignore-this: 3360f5c57bfb97f64d4f4509901ea0cd darcs-hash:20120213092110-c41ad-88847c98d4a92479772b02d4fe88cdfa85fad9b6 --- src/lib/uTop_main.ml | 2 ++ src/top/utop.el | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index 46c6bd0..60c57e9 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -567,6 +567,8 @@ module Emacs(M : sig end) = struct send "history-end" ""; loop_commands (input :: history_prev) history_next end + | Some ("exit", code) -> + exit (int_of_string code) | Some (command, _) -> Printf.ksprintf (send "stderr") "unrecognized command %S!" command; exit 1 diff --git a/src/top/utop.el b/src/top/utop.el index f619ae3..32fb439 100644 --- a/src/top/utop.el +++ b/src/top/utop.el @@ -131,6 +131,8 @@ This hook is only run if exiting actually kills the buffer." (define-key map [(control ?c) (control ?c)] 'utop-interrupt) (define-key map [(control ?c) (control ?i)] 'utop-interrupt) (define-key map [(control ?c) (control ?k)] 'utop-kill) + (define-key map [(control ?c) (control ?g)] 'utop-exit) + (define-key map [(control ?c) (control ?s)] 'utop) map) "The utop local keymap.") @@ -672,6 +674,14 @@ To automatically do that just add these lines to your .emacs: (with-current-buffer utop-buffer-name (kill-process utop-process))) +(defun utop-exit (&optional exit-code) + "Try to gracefully exit utop. + +EXIT-CODE is the exit code that shoud be used. It defaults to 0." + (interactive) + (with-current-buffer utop-buffer-name + (process-send-string utop-process (format "exit:%d\n" (or exit-code 0))))) + (defun utop-sentinel (process msg) "Callback for process' state change." (let ((buffer (get-buffer utop-buffer-name))) @@ -769,6 +779,7 @@ To automatically do that just add these lines to your .emacs: ["Start OCaml" utop t] ["Interrupt OCaml" utop-interrupt :active (utop-is-running)] ["Kill OCaml" utop-kill :active (utop-is-running)] + ["Exit utop gracefully" utop-exit :active (utop-is-running)] ["Evaluate Phrase" utop-eval-input-auto-end :active (and (utop-is-running) (eq utop-state 'edit))] "---" ["Customize utop" (customize-group 'utop) t]