diff options
| author | Lukas Fürmetz <fuermetz@mailbox.org> | 2017-07-26 17:03:35 +0200 |
|---|---|---|
| committer | Lukas Fürmetz <fuermetz@mailbox.org> | 2017-07-26 17:24:03 +0200 |
| commit | 2f0c340d8923284fdcd6e1eeac9db724103c84ed (patch) | |
| tree | b97a1ed2f524780589b2939e202f109d4c85cafe | |
| parent | d4c3ee244ce020a7e7a032f6989bdc4c5e428235 (diff) | |
Terminate process if corresponding buffer is killed
| -rw-r--r-- | vterm-module.c | 16 | ||||
| -rw-r--r-- | vterm-module.h | 2 | ||||
| -rw-r--r-- | 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 <fcntl.h> #include <pty.h> +#include <signal.h> #include <stdbool.h> #include <stdio.h> #include <string.h> @@ -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); @@ -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) |
