Mercurial > vim
comparison src/misc1.c @ 25790:16a7d1154be8 v8.2.3430
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Commit: https://github.com/vim/vim/commit/f1e8876fa2359b572d262772747405d3616db670
Author: =?UTF-8?q?Magnus=20Gro=C3=9F?= <magnus.gross@rwth-aachen.de>
Date: Sun Sep 12 13:39:55 2021 +0200
patch 8.2.3430: no generic way to trigger an autocommand on mode change
Problem: No generic way to trigger an autocommand on mode change.
Solution: Add the ModeChanged autocommand event. (Magnus Gross, closes https://github.com/vim/vim/issues/8856)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Sep 2021 13:45:05 +0200 |
parents | 4101d78f78e2 |
children | 2d0bea8aed33 |
comparison
equal
deleted
inserted
replaced
25789:3afd5ab3d69a | 25790:16a7d1154be8 |
---|---|
628 * "mode()" function | 628 * "mode()" function |
629 */ | 629 */ |
630 void | 630 void |
631 f_mode(typval_T *argvars, typval_T *rettv) | 631 f_mode(typval_T *argvars, typval_T *rettv) |
632 { | 632 { |
633 char_u buf[4]; | 633 char_u buf[MODE_MAX_LENGTH]; |
634 | 634 |
635 if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL) | 635 if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL) |
636 return; | 636 return; |
637 | 637 |
638 CLEAR_FIELD(buf); | 638 CLEAR_FIELD(buf); |
2641 return 0; | 2641 return 0; |
2642 | 2642 |
2643 // "://" or ":\\" must follow | 2643 // "://" or ":\\" must follow |
2644 return path_is_url(p); | 2644 return path_is_url(p); |
2645 } | 2645 } |
2646 | |
2647 /* | |
2648 * Fires a ModeChanged autocmd | |
2649 */ | |
2650 void | |
2651 trigger_modechanged() | |
2652 { | |
2653 #if defined(FEAT_EVAL) || defined(PROTO) | |
2654 dict_T *v_event; | |
2655 typval_T rettv; | |
2656 typval_T tv; | |
2657 char_u *pat_pre; | |
2658 char_u *pat; | |
2659 | |
2660 if (!has_modechanged()) | |
2661 return; | |
2662 | |
2663 v_event = get_vim_var_dict(VV_EVENT); | |
2664 | |
2665 tv.v_type = VAR_UNKNOWN; | |
2666 f_mode(&tv, &rettv); | |
2667 (void)dict_add_string(v_event, "new_mode", rettv.vval.v_string); | |
2668 (void)dict_add_string(v_event, "old_mode", last_mode); | |
2669 dict_set_items_ro(v_event); | |
2670 | |
2671 // concatenate modes in format "old_mode:new_mode" | |
2672 pat_pre = concat_str(last_mode, (char_u*)":"); | |
2673 pat = concat_str(pat_pre, rettv.vval.v_string); | |
2674 vim_free(pat_pre); | |
2675 | |
2676 apply_autocmds(EVENT_MODECHANGED, pat, NULL, FALSE, curbuf); | |
2677 STRCPY(last_mode, rettv.vval.v_string); | |
2678 | |
2679 vim_free(rettv.vval.v_string); | |
2680 vim_free(pat); | |
2681 dict_free_contents(v_event); | |
2682 hash_init(&v_event->dv_hashtab); | |
2683 #endif | |
2684 } |