diff options
| author | jixiuf <jixiuf@qq.com> | 2020-02-03 23:01:58 +0800 |
|---|---|---|
| committer | jixiuf <jixiuf@qq.com> | 2020-02-03 23:48:43 +0800 |
| commit | 4bfe85cae868943006662805e4445b3bd94eee2c (patch) | |
| tree | a1216f8ab119d01d729f3daa06f29c9a96b38f76 /vterm-module.c | |
| parent | 783b34e9d8ebb6e66c6981f6ecdd3ae8b948fe56 (diff) | |
add func vterm--at-prompt-p
Diffstat (limited to 'vterm-module.c')
| -rw-r--r-- | vterm-module.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vterm-module.c b/vterm-module.c index 512d973..1fcaad6 100644 --- a/vterm-module.c +++ b/vterm-module.c @@ -13,6 +13,7 @@ static LineInfo *alloc_lineinfo() { LineInfo *info = malloc(sizeof(LineInfo)); info->directory = NULL; + info->prompt_col = -1; return info; } void free_lineinfo(LineInfo *line) { @@ -853,6 +854,11 @@ static int osc_callback(const char *command, size_t cmdlen, void *user) { } term->lines[i]->directory = malloc(cmdlen - 4 + 1); strcpy(term->lines[i]->directory, &buffer[4]); + if (i == term->cursor.row) { + term->lines[i]->prompt_col = term->cursor.col; + } else { + term->lines[i]->prompt_col = -1; + } } return 1; } else if (cmdlen > 4 && buffer[0] == '5' && buffer[1] == '1' && @@ -1047,6 +1053,27 @@ emacs_value Fvterm_get_icrnl(emacs_env *env, ptrdiff_t nargs, return Qnil; } +emacs_value Fvterm_get_prompt_point(emacs_env *env, ptrdiff_t nargs, + emacs_value args[], void *data) { + Term *term = env->get_user_ptr(env, args[0]); + int linenum = env->extract_integer(env, args[1]); + if (linenum >= term->linenum) { + linenum = term->linenum; + } + for (int l = linenum; l >= 1; l--) { + int cur_row = linenr_to_row(term, l); + LineInfo *info = get_lineinfo(term, cur_row); + if (info != NULL && info->prompt_col >= 0) { + goto_line(env, l); + size_t offset = get_col_offset(term, cur_row, info->prompt_col); + forward_char(env, env->make_integer(env, info->prompt_col - offset)); + + return point(env); + } + } + return Qnil; +} + emacs_value Fvterm_reset_cursor_point(emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data) { Term *term = env->get_user_ptr(env, args[0]); @@ -1145,6 +1172,13 @@ int emacs_module_init(struct emacs_runtime *ert) { fun = env->make_function(env, 2, 2, Fvterm_get_pwd, "Get the working directory of at line n.", NULL); bind_function(env, "vterm--get-pwd-raw", fun); + fun = env->make_function(env, 2, 2, Fvterm_get_prompt_point, + "Get the end postion of current prompt.", NULL); + bind_function(env, "vterm--get-prompt-point-internal", fun); + fun = env->make_function(env, 1, 1, Fvterm_reset_cursor_point, + "Reset cursor postion.", NULL); + bind_function(env, "vterm--reset-point", fun); + fun = env->make_function(env, 1, 1, Fvterm_get_icrnl, "Gets the icrnl state of the pty", NULL); |
