From 2f0c340d8923284fdcd6e1eeac9db724103c84ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BCrmetz?= Date: Wed, 26 Jul 2017 17:03:35 +0200 Subject: Terminate process if corresponding buffer is killed --- vterm-module.c | 16 +++++++++++++++- vterm-module.h | 2 ++ vterm.el | 3 ++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/vterm-module.c b/vterm-module.c index b7a0e01..6f169c2 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -1,6 +1,7 @@ #include "vterm-module.h" #include #include +#include #include #include #include @@ -348,6 +349,15 @@ static emacs_value Fvterm_update(emacs_env *env, ptrdiff_t nargs, return env->make_integer(env, 0); } +static emacs_value Fvterm_kill(emacs_env *env, ptrdiff_t nargs, + emacs_value args[], void *data) { + struct Term *term = env->get_user_ptr(env, args[0]); + kill(term->pid, SIGKILL); + int status; + waitpid(term->pid, &status, 0); + return env->intern(env, "nil"); +} + int emacs_module_init(struct emacs_runtime *ert) { emacs_env *env = ert->get_environment(ert); emacs_value fun; @@ -357,9 +367,13 @@ int emacs_module_init(struct emacs_runtime *ert) { bind_function(env, "vterm-new", fun); fun = env->make_function(env, 1, 5, Fvterm_update, - "Process io and updates the screen.", NULL); + "Process io and update the screen.", NULL); bind_function(env, "vterm-update", fun); + fun = env->make_function(env, 1, 1, Fvterm_kill, + "Kill the the shell process.", NULL); + bind_function(env, "vterm-kill", fun); + provide(env, "vterm-module"); return 0; diff --git a/vterm-module.h b/vterm-module.h index 3ebefe5..2af8d47 100644 --- a/vterm-module.h +++ b/vterm-module.h @@ -34,4 +34,6 @@ static emacs_value Fvterm_new(emacs_env *env, ptrdiff_t nargs, static void process_key(struct Term *term, char *key, VTermModifier modifier); static emacs_value Fvterm_update(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data); +static emacs_value Fvterm_kill(emacs_env *env, ptrdiff_t nargs, + emacs_value args[], void *data); int emacs_module_init(struct emacs_runtime *ert); diff --git a/vterm.el b/vterm.el index c28af20..8381f0b 100644 --- a/vterm.el +++ b/vterm.el @@ -68,6 +68,7 @@ be send to the terminal.") (defun vterm-kill-buffer-hook () (when (eq major-mode 'vterm-mode) - (cancel-timer vterm-timer))) + (cancel-timer vterm-timer) + (vterm-kill vterm-term))) (provide 'vterm) -- cgit v1.0