comparison src/autocmd.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 ddc223a7f5f5
children 336e2d9924e6
comparison
equal deleted inserted replaced
25789:3afd5ab3d69a 25790:16a7d1154be8
148 {"InsertEnter", EVENT_INSERTENTER}, 148 {"InsertEnter", EVENT_INSERTENTER},
149 {"InsertLeave", EVENT_INSERTLEAVE}, 149 {"InsertLeave", EVENT_INSERTLEAVE},
150 {"InsertLeavePre", EVENT_INSERTLEAVEPRE}, 150 {"InsertLeavePre", EVENT_INSERTLEAVEPRE},
151 {"InsertCharPre", EVENT_INSERTCHARPRE}, 151 {"InsertCharPre", EVENT_INSERTCHARPRE},
152 {"MenuPopup", EVENT_MENUPOPUP}, 152 {"MenuPopup", EVENT_MENUPOPUP},
153 {"ModeChanged", EVENT_MODECHANGED},
153 {"OptionSet", EVENT_OPTIONSET}, 154 {"OptionSet", EVENT_OPTIONSET},
154 {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST}, 155 {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
155 {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE}, 156 {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
156 {"QuitPre", EVENT_QUITPRE}, 157 {"QuitPre", EVENT_QUITPRE},
157 {"RemoteReply", EVENT_REMOTEREPLY}, 158 {"RemoteReply", EVENT_REMOTEREPLY},
1815 { 1816 {
1816 return (first_autopat[(int)EVENT_COMPLETECHANGED] != NULL); 1817 return (first_autopat[(int)EVENT_COMPLETECHANGED] != NULL);
1817 } 1818 }
1818 #endif 1819 #endif
1819 1820
1821 #if defined(FEAT_EVAL) || defined(PROTO)
1822 /*
1823 * Return TRUE when there is a ModeChanged autocommand defined.
1824 */
1825 int
1826 has_modechanged(void)
1827 {
1828 return (first_autopat[(int)EVENT_MODECHANGED] != NULL);
1829 }
1830 #endif
1831
1820 /* 1832 /*
1821 * Execute autocommands for "event" and file name "fname". 1833 * Execute autocommands for "event" and file name "fname".
1822 * Return TRUE if some commands were executed. 1834 * Return TRUE if some commands were executed.
1823 */ 1835 */
1824 static int 1836 static int
1936 * invalid. 1948 * invalid.
1937 */ 1949 */
1938 if (fname_io == NULL) 1950 if (fname_io == NULL)
1939 { 1951 {
1940 if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE 1952 if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
1941 || event == EVENT_OPTIONSET) 1953 || event == EVENT_OPTIONSET
1954 || event == EVENT_MODECHANGED)
1942 autocmd_fname = NULL; 1955 autocmd_fname = NULL;
1943 else if (fname != NULL && !ends_excmd(*fname)) 1956 else if (fname != NULL && !ends_excmd(*fname))
1944 autocmd_fname = fname; 1957 autocmd_fname = fname;
1945 else if (buf != NULL) 1958 else if (buf != NULL)
1946 autocmd_fname = buf->b_ffname; 1959 autocmd_fname = buf->b_ffname;
2009 || event == EVENT_QUICKFIXCMDPRE 2022 || event == EVENT_QUICKFIXCMDPRE
2010 || event == EVENT_COLORSCHEME 2023 || event == EVENT_COLORSCHEME
2011 || event == EVENT_COLORSCHEMEPRE 2024 || event == EVENT_COLORSCHEMEPRE
2012 || event == EVENT_OPTIONSET 2025 || event == EVENT_OPTIONSET
2013 || event == EVENT_QUICKFIXCMDPOST 2026 || event == EVENT_QUICKFIXCMDPOST
2014 || event == EVENT_DIRCHANGED) 2027 || event == EVENT_DIRCHANGED
2028 || event == EVENT_MODECHANGED)
2015 { 2029 {
2016 fname = vim_strsave(fname); 2030 fname = vim_strsave(fname);
2017 autocmd_fname_full = TRUE; // don't expand it later 2031 autocmd_fname_full = TRUE; // don't expand it later
2018 } 2032 }
2019 else 2033 else