annotate src/autocmd.c @ 16162:cd5c83115ec6 v8.1.1086

patch 8.1.1086: too many curly braces commit https://github.com/vim/vim/commit/abab0b0fdd6535969447b03a4fffc1947918cf6c Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 30 18:47:01 2019 +0100 patch 8.1.1086: too many curly braces Problem: Too many curly braces. Solution: Remove curly braces where they are not needed. (Hirohito Higashi, closes #3982)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Mar 2019 19:00:07 +0100
parents 746b95fd25ad
children 81e6940504e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * autocmd.c: Autocommand related functions
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 * The autocommands are stored in a list for each event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 * Autocommands for the same pattern, that are consecutive, are joined
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * together, to avoid having to match the pattern too often.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * The result is an array of Autopat lists, which point to AutoCmd lists:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * last_autopat[0] -----------------------------+
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * first_autopat[0] --> Autopat.next --> Autopat.next --> NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * Autopat.cmds Autopat.cmds
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 * | |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 * V V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 * AutoCmd.next AutoCmd.next
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 * | |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 * V V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 * AutoCmd.next NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 * NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 * last_autopat[1] --------+
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 * first_autopat[1] --> Autopat.next --> NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 * Autopat.cmds
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 * AutoCmd.next
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 * NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 * etc.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 * The order of AutoCmds is important, this is the order in which they were
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 * defined and will have to be executed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 typedef struct AutoCmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 char_u *cmd; // The command to be executed (NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 // when command has been removed).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 char nested; // If autocommands nest here.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 char last; // last command in list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 sctx_T script_ctx; // script context where defined
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 struct AutoCmd *next; // next AutoCmd in list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 } AutoCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 typedef struct AutoPat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 struct AutoPat *next; // Next AutoPat in AutoPat list; MUST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 // be the first entry.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 char_u *pat; // pattern as typed (NULL when pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 // has been removed)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 regprog_T *reg_prog; // compiled regprog for pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 AutoCmd *cmds; // list of commands to do
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 int group; // group ID
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 int patlen; // strlen() of pat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 int buflocal_nr; // !=0 for buffer-local AutoPat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 char allow_dirs; // Pattern may match whole path
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 char last; // last pattern for apply_autocmds()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 } AutoPat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 static struct event_name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 char *name; // event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 event_T event; // event number
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 } event_names[] =
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 {"BufAdd", EVENT_BUFADD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {"BufCreate", EVENT_BUFADD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 {"BufDelete", EVENT_BUFDELETE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 {"BufEnter", EVENT_BUFENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 {"BufFilePost", EVENT_BUFFILEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 {"BufFilePre", EVENT_BUFFILEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 {"BufHidden", EVENT_BUFHIDDEN},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {"BufLeave", EVENT_BUFLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 {"BufNew", EVENT_BUFNEW},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 {"BufNewFile", EVENT_BUFNEWFILE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 {"BufRead", EVENT_BUFREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 {"BufReadCmd", EVENT_BUFREADCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 {"BufReadPost", EVENT_BUFREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {"BufReadPre", EVENT_BUFREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 {"BufUnload", EVENT_BUFUNLOAD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 {"BufWinEnter", EVENT_BUFWINENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 {"BufWinLeave", EVENT_BUFWINLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 {"BufWipeout", EVENT_BUFWIPEOUT},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 {"BufWrite", EVENT_BUFWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 {"BufWritePost", EVENT_BUFWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 {"BufWritePre", EVENT_BUFWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 {"BufWriteCmd", EVENT_BUFWRITECMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 {"CmdlineChanged", EVENT_CMDLINECHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 {"CmdlineEnter", EVENT_CMDLINEENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 {"CmdlineLeave", EVENT_CMDLINELEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 {"CmdwinEnter", EVENT_CMDWINENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 {"CmdwinLeave", EVENT_CMDWINLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 {"CmdUndefined", EVENT_CMDUNDEFINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 {"ColorScheme", EVENT_COLORSCHEME},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 {"ColorSchemePre", EVENT_COLORSCHEMEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {"CompleteDone", EVENT_COMPLETEDONE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 {"CursorHold", EVENT_CURSORHOLD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 {"CursorHoldI", EVENT_CURSORHOLDI},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 {"CursorMoved", EVENT_CURSORMOVED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 {"CursorMovedI", EVENT_CURSORMOVEDI},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {"DiffUpdated", EVENT_DIFFUPDATED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 {"DirChanged", EVENT_DIRCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {"EncodingChanged", EVENT_ENCODINGCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 {"ExitPre", EVENT_EXITPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {"FileEncoding", EVENT_ENCODINGCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 {"FileAppendPost", EVENT_FILEAPPENDPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 {"FileAppendPre", EVENT_FILEAPPENDPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 {"FileAppendCmd", EVENT_FILEAPPENDCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {"FileChangedShell",EVENT_FILECHANGEDSHELL},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 {"FileChangedShellPost",EVENT_FILECHANGEDSHELLPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 {"FileChangedRO", EVENT_FILECHANGEDRO},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 {"FileReadPost", EVENT_FILEREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 {"FileReadPre", EVENT_FILEREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 {"FileReadCmd", EVENT_FILEREADCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {"FileType", EVENT_FILETYPE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 {"FileWritePost", EVENT_FILEWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 {"FileWritePre", EVENT_FILEWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 {"FileWriteCmd", EVENT_FILEWRITECMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 {"FilterReadPost", EVENT_FILTERREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 {"FilterReadPre", EVENT_FILTERREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 {"FilterWritePost", EVENT_FILTERWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {"FilterWritePre", EVENT_FILTERWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 {"FocusGained", EVENT_FOCUSGAINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 {"FocusLost", EVENT_FOCUSLOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 {"FuncUndefined", EVENT_FUNCUNDEFINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 {"GUIEnter", EVENT_GUIENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 {"GUIFailed", EVENT_GUIFAILED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 {"InsertChange", EVENT_INSERTCHANGE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 {"InsertEnter", EVENT_INSERTENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 {"InsertLeave", EVENT_INSERTLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 {"InsertCharPre", EVENT_INSERTCHARPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 {"MenuPopup", EVENT_MENUPOPUP},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 {"OptionSet", EVENT_OPTIONSET},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 {"QuitPre", EVENT_QUITPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 {"RemoteReply", EVENT_REMOTEREPLY},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 {"SessionLoadPost", EVENT_SESSIONLOADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 {"ShellCmdPost", EVENT_SHELLCMDPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 {"ShellFilterPost", EVENT_SHELLFILTERPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 {"SourceCmd", EVENT_SOURCECMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 {"SourcePre", EVENT_SOURCEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 {"SourcePost", EVENT_SOURCEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 {"SpellFileMissing",EVENT_SPELLFILEMISSING},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {"StdinReadPost", EVENT_STDINREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 {"StdinReadPre", EVENT_STDINREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 {"SwapExists", EVENT_SWAPEXISTS},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 {"Syntax", EVENT_SYNTAX},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 {"TabNew", EVENT_TABNEW},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 {"TabClosed", EVENT_TABCLOSED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 {"TabEnter", EVENT_TABENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 {"TabLeave", EVENT_TABLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 {"TermChanged", EVENT_TERMCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 {"TerminalOpen", EVENT_TERMINALOPEN},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 {"TermResponse", EVENT_TERMRESPONSE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 {"TextChanged", EVENT_TEXTCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 {"TextChangedI", EVENT_TEXTCHANGEDI},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 {"TextChangedP", EVENT_TEXTCHANGEDP},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 {"User", EVENT_USER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 {"VimEnter", EVENT_VIMENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 {"VimLeave", EVENT_VIMLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {"VimLeavePre", EVENT_VIMLEAVEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 {"WinNew", EVENT_WINNEW},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 {"WinEnter", EVENT_WINENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 {"WinLeave", EVENT_WINLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 {"VimResized", EVENT_VIMRESIZED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 {"TextYankPost", EVENT_TEXTYANKPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 {NULL, (event_T)0}
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 static AutoPat *first_autopat[NUM_EVENTS] =
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 static AutoPat *last_autopat[NUM_EVENTS] =
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 #define AUGROUP_DEFAULT -1 // default autocmd group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 #define AUGROUP_ERROR -2 // erroneous autocmd group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 #define AUGROUP_ALL -3 // all autocmd groups
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 * struct used to keep status while executing autocommands for an event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 typedef struct AutoPatCmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 AutoPat *curpat; // next AutoPat to examine
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 AutoCmd *nextcmd; // next AutoCmd to execute
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 int group; // group being used
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 char_u *fname; // fname to match with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 char_u *sfname; // sfname to match with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 char_u *tail; // tail of fname
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 event_T event; // current event
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 int arg_bufnr; // Initially equal to <abuf>, set to zero when
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 // buf is deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 struct AutoPatCmd *next; // chain of active apc-s for auto-invalidation
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 } AutoPatCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 * augroups stores a list of autocmd group names.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 static garray_T augroups = {0, 0, sizeof(char_u *), 10, NULL};
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 /* use get_deleted_augroup() to get this */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 static char_u *deleted_augroup = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 * Set by the apply_autocmds_group function if the given event is equal to
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 * EVENT_FILETYPE. Used by the readfile function in order to determine if
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 * EVENT_BUFREADPOST triggered the EVENT_FILETYPE.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 * Relying on this value requires one to reset it prior calling
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 * apply_autocmds_group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 int au_did_filetype INIT(= FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 * The ID of the current group. Group 0 is the default one.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 static int current_augroup = AUGROUP_DEFAULT;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 static int au_need_clean = FALSE; /* need to delete marked patterns */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 static char_u *event_nr2name(event_T event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 static int au_get_grouparg(char_u **argp);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 static int do_autocmd_event(event_T event, char_u *pat, int nested, char_u *cmd, int forceit, int group);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 static void auto_next_pat(AutoPatCmd *apc, int stop_at_last);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 static int au_find_group(char_u *name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 static event_T last_event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 static int last_group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 static int autocmd_blocked = 0; /* block all autocmds */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 get_deleted_augroup(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 if (deleted_augroup == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 deleted_augroup = (char_u *)_("--Deleted--");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 return deleted_augroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 * Show the autocommands for one AutoPat.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 show_autocmd(AutoPat *ap, event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 // Check for "got_int" (here and at various places below), which is set
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 // when "q" has been hit for the "--more--" prompt
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 if (ap->pat == NULL) // pattern has been removed
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 if (event != last_event || ap->group != last_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if (ap->group != AUGROUP_DEFAULT)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 if (AUGROUP_NAME(ap->group) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 msg_puts_attr((char *)get_deleted_augroup(), HL_ATTR(HLF_E));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 msg_puts_attr((char *)AUGROUP_NAME(ap->group), HL_ATTR(HLF_T));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 msg_puts(" ");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 msg_puts_attr((char *)event_nr2name(event), HL_ATTR(HLF_T));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 last_event = event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 last_group = ap->group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 msg_col = 4;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 msg_outtrans(ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 for (ac = ap->cmds; ac != NULL; ac = ac->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 if (ac->cmd != NULL) // skip removed commands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 if (msg_col >= 14)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 msg_col = 14;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 msg_outtrans(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 if (p_verbose > 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 last_set_msg(ac->script_ctx);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (ac->next != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 * Mark an autocommand pattern for deletion.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 au_remove_pat(AutoPat *ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 VIM_CLEAR(ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 ap->buflocal_nr = -1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 au_need_clean = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 * Mark all commands for a pattern for deletion.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 au_remove_cmds(AutoPat *ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 for (ac = ap->cmds; ac != NULL; ac = ac->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 VIM_CLEAR(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 au_need_clean = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 * Cleanup autocommands and patterns that have been deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 * This is only done when not executing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 au_cleanup(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 AutoPat *ap, **prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 AutoCmd *ac, **prev_ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 if (autocmd_busy || !au_need_clean)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 // loop over all events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 // loop over all autocommand patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 prev_ap = &(first_autopat[(int)event]);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 for (ap = *prev_ap; ap != NULL; ap = *prev_ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 // loop over all commands for this pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 prev_ac = &(ap->cmds);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 for (ac = *prev_ac; ac != NULL; ac = *prev_ac)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // remove the command if the pattern is to be deleted or when
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 // the command has been marked for deletion
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 if (ap->pat == NULL || ac->cmd == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 *prev_ac = ac->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 vim_free(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 vim_free(ac);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 prev_ac = &(ac->next);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 // remove the pattern if it has been marked for deletion
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if (ap->pat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 if (ap->next == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 if (prev_ap == &(first_autopat[(int)event]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 last_autopat[(int)event] = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 // this depends on the "next" field being the first in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 // the struct
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 last_autopat[(int)event] = (AutoPat *)prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 *prev_ap = ap->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 vim_regfree(ap->reg_prog);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 vim_free(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 prev_ap = &(ap->next);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 au_need_clean = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 * Called when buffer is freed, to remove/invalidate related buffer-local
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 * autocmds.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 aubuflocal_remove(buf_T *buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 AutoPatCmd *apc;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 // invalidate currently executing autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 for (apc = active_apc_list; apc; apc = apc->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 if (buf->b_fnum == apc->arg_bufnr)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 apc->arg_bufnr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 // invalidate buflocals looping through events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 // loop over all autocommand patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 if (ap->buflocal_nr == buf->b_fnum)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 au_remove_pat(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 if (p_verbose >= 6)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 verbose_enter();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 smsg(_("auto-removing autocommand: %s <buffer=%d>"),
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 event_nr2name(event), buf->b_fnum);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 verbose_leave();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 au_cleanup();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 * Add an autocmd group name.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 * Return its ID. Returns AUGROUP_ERROR (< 0) for error.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 au_new_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 i = au_find_group(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 if (i == AUGROUP_ERROR) // the group doesn't exist yet, add it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 // First try using a free entry.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 if (AUGROUP_NAME(i) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 AUGROUP_NAME(i) = vim_strsave(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 if (AUGROUP_NAME(i) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 if (i == augroups.ga_len)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 ++augroups.ga_len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 return i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 au_del_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 i = au_find_group(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 if (i == AUGROUP_ERROR) // the group doesn't exist
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 semsg(_("E367: No such group: \"%s\""), name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 else if (i == current_augroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 emsg(_("E936: Cannot delete the current group"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 int in_use = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 if (ap->group == i && ap->pat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 in_use = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 event = NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 vim_free(AUGROUP_NAME(i));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 if (in_use)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 AUGROUP_NAME(i) = get_deleted_augroup();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 AUGROUP_NAME(i) = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 * Find the ID of an autocmd group name.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 * Return its ID. Returns AUGROUP_ERROR (< 0) for error.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 au_find_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != get_deleted_augroup()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 && STRCMP(AUGROUP_NAME(i), name) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 return i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 * Return TRUE if augroup "name" exists.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 au_has_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 return au_find_group(name) != AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 * ":augroup {name}".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 do_augroup(char_u *arg, int del_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 if (del_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 if (*arg == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 emsg(_(e_argreq));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 au_del_group(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 else if (STRICMP(arg, "end") == 0) // ":aug end": back to group 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 current_augroup = AUGROUP_DEFAULT;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 else if (*arg) // ":aug xxx": switch to group xxx
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 i = au_new_group(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (i != AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 current_augroup = i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 else // ":aug": list the group names
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 msg_start();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (AUGROUP_NAME(i) != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 msg_puts((char *)AUGROUP_NAME(i));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 msg_puts(" ");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 msg_clr_eos();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 msg_end();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 #if defined(EXITFREE) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 free_all_autocmds(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 char_u *s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 for (current_augroup = -1; current_augroup < augroups.ga_len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 ++current_augroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 do_autocmd((char_u *)"", TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 s = ((char_u **)(augroups.ga_data))[i];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 if (s != get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 vim_free(s);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 ga_clear(&augroups);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 * Return the event number for event name "start".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 * Return NUM_EVENTS if the event name was not found.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 * Return a pointer to the next event name in "end".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 static event_T
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 event_name2nr(char_u *start, char_u **end)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 int len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 // the event name ends with end of line, '|', a blank or a comma
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 for (p = start; *p && !VIM_ISWHITE(*p) && *p != ',' && *p != '|'; ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 for (i = 0; event_names[i].name != NULL; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 len = (int)STRLEN(event_names[i].name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 *end = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 if (event_names[i].name == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 return NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 return event_names[i].event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 * Return the name for event "event".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 event_nr2name(event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 for (i = 0; event_names[i].name != NULL; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 if (event_names[i].event == event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 return (char_u *)event_names[i].name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 return (char_u *)"Unknown";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 * Scan over the events. "*" stands for all events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 find_end_event(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 char_u *arg,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 int have_group) // TRUE when group name was found
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 char_u *pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 if (*arg == '*')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 if (arg[1] && !VIM_ISWHITE(arg[1]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 semsg(_("E215: Illegal character after *: %s"), arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 pat = arg + 1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 for (pat = arg; *pat && *pat != '|' && !VIM_ISWHITE(*pat); pat = p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (have_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 semsg(_("E216: No such event: %s"), pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 semsg(_("E216: No such group or event: %s"), pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 return pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 * Return TRUE if "event" is included in 'eventignore'.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 event_ignored(event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 char_u *p = p_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 while (*p != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 if (event_name2nr(p, &p) == event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * Return OK when the contents of p_ei is valid, FAIL otherwise.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 check_ei(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 char_u *p = p_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 while (*p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 p += 3;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 else if (event_name2nr(p, &p) == NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 return OK;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 # if defined(FEAT_SYN_HL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 * Add "what" to 'eventignore' to skip loading syntax highlighting for every
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 * buffer loaded into the window. "what" must start with a comma.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 * Returns the old value of 'eventignore' in allocated memory.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 au_event_disable(char *what)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 char_u *new_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 char_u *save_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 save_ei = vim_strsave(p_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 if (save_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 new_ei = vim_strnsave(p_ei, (int)(STRLEN(p_ei) + STRLEN(what)));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 if (new_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 if (*what == ',' && *p_ei == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 STRCPY(new_ei, what + 1);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 STRCAT(new_ei, what);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 set_string_option_direct((char_u *)"ei", -1, new_ei,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 OPT_FREE, SID_NONE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 vim_free(new_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 return save_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 au_event_restore(char_u *old_ei)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 if (old_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 set_string_option_direct((char_u *)"ei", -1, old_ei,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 OPT_FREE, SID_NONE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 vim_free(old_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 # endif /* FEAT_SYN_HL */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 * do_autocmd() -- implements the :autocmd command. Can be used in the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 * following ways:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 * :autocmd <event> <pat> <cmd> Add <cmd> to the list of commands that
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 * will be automatically executed for <event>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 * when editing a file matching <pat>, in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 * the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 * :autocmd <event> <pat> Show the autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 * <event> and <pat>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 * :autocmd <event> Show the autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 * <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 * :autocmd Show all autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 * :autocmd! <event> <pat> <cmd> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 * <event> and <pat>, and add the command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 * <cmd>, for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 * :autocmd! <event> <pat> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 * <event> and <pat> for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 * :autocmd! <event> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 * <event> for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 * :autocmd! Remove ALL autocommands for the current
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 * group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 * Multiple events and patterns may be given separated by commas. Here are
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 * some examples:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 * :autocmd bufread,bufenter *.c,*.h set tw=0 smartindent noic
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 * :autocmd bufleave * set tw=79 nosmartindent ic infercase
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 * :autocmd * *.c show all autocommands for *.c files.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 * Mostly a {group} argument can optionally appear before <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 do_autocmd(char_u *arg_in, int forceit)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 char_u *arg = arg_in;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 char_u *pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 char_u *envpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 char_u *cmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 int need_free = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 int nested = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 if (*arg == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 arg = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 group = AUGROUP_ALL; // no argument, use all groups
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 * Check for a legal group name. If not, use AUGROUP_ALL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 group = au_get_grouparg(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 if (arg == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 * Scan over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 * If we find an illegal name, return here, don't do anything.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 pat = find_end_event(arg, group != AUGROUP_ALL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 if (pat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 pat = skipwhite(pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 if (*pat == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 pat = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 cmd = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 * Scan over the pattern. Put a NUL at the end.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 cmd = pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 while (*cmd && (!VIM_ISWHITE(*cmd) || cmd[-1] == '\\'))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 cmd++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 if (*cmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 *cmd++ = NUL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 // Expand environment variables in the pattern. Set 'shellslash', we
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 // want forward slashes here.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 int p_ssl_save = p_ssl;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 p_ssl = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 envpat = expand_env_save(pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 p_ssl = p_ssl_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 if (envpat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 pat = envpat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 * Check for "nested" flag.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 cmd = skipwhite(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 if (*cmd != NUL && STRNCMP(cmd, "nested", 6) == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 && VIM_ISWHITE(cmd[6]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 nested = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 cmd = skipwhite(cmd + 6);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 * Find the start of the commands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 * Expand <sfile> in it.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 if (*cmd != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 cmd = expand_sfile(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 if (cmd == NULL) // some error
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 need_free = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 * Print header when showing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 if (!forceit && *cmd == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 // Highlight title
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 msg_puts_title(_("\n--- Autocommands ---"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 * Loop over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 last_event = (event_T)-1; // for listing the event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 last_group = AUGROUP_ERROR; // for listing the group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 if (*arg == '*' || *arg == NUL || *arg == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 if (do_autocmd_event(event, pat,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 nested, cmd, forceit, group) == FAIL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 while (*arg && *arg != '|' && !VIM_ISWHITE(*arg))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 if (do_autocmd_event(event_name2nr(arg, &arg), pat,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 nested, cmd, forceit, group) == FAIL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 if (need_free)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 vim_free(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 vim_free(envpat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 * Find the group ID in a ":autocmd" or ":doautocmd" argument.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 * The "argp" argument is advanced to the following argument.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 * Returns the group ID, AUGROUP_ERROR for error (out of memory).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 au_get_grouparg(char_u **argp)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 char_u *group_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 char_u *arg = *argp;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 int group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 for (p = arg; *p && !VIM_ISWHITE(*p) && *p != '|'; ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 if (p > arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 group_name = vim_strnsave(arg, (int)(p - arg));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 if (group_name == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 group = au_find_group(group_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 group = AUGROUP_ALL; // no match, use all groups
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 *argp = skipwhite(p); // match, skip over group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 vim_free(group_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 return group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 * do_autocmd() for one event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 * If *pat == NUL do for all patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 * If *cmd == NUL show entries.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 * If forceit == TRUE delete entries.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 * If group is not AUGROUP_ALL, only use this group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 do_autocmd_event(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 char_u *pat,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 int nested,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 char_u *cmd,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 int forceit,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 int group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 AutoPat **prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 AutoCmd **prev_ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 int brace_level;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 char_u *endpat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 int findgroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 int allgroups;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 int patlen;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 int is_buflocal;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 int buflocal_nr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 char_u buflocal_pat[25]; /* for "<buffer=X>" */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 if (group == AUGROUP_ALL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 findgroup = current_augroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 findgroup = group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 allgroups = (group == AUGROUP_ALL && !forceit && *cmd == NUL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 * Show or delete all patterns for an event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (*pat == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 if (forceit) // delete the AutoPat, if it's in the current group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 if (ap->group == findgroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 au_remove_pat(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 else if (group == AUGROUP_ALL || ap->group == group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 show_autocmd(ap, event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 * Loop through all the specified patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 for ( ; *pat; pat = (*endpat == ',' ? endpat + 1 : endpat))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 * Find end of the pattern.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 * Watch out for a comma in braces, like "*.\{obj,o\}".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 brace_level = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 for (endpat = pat; *endpat && (*endpat != ',' || brace_level
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 || (endpat > pat && endpat[-1] == '\\')); ++endpat)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 if (*endpat == '{')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 brace_level++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 else if (*endpat == '}')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 brace_level--;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 if (pat == endpat) // ignore single comma
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 continue;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 patlen = (int)(endpat - pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 * detect special <buflocal[=X]> buffer-local patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 is_buflocal = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 buflocal_nr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 if (patlen >= 8 && STRNCMP(pat, "<buffer", 7) == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 && pat[patlen - 1] == '>')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 // "<buffer...>": Error will be printed only for addition.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 // printing and removing will proceed silently.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 is_buflocal = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 if (patlen == 8)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 // "<buffer>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 buflocal_nr = curbuf->b_fnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 else if (patlen > 9 && pat[7] == '=')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 if (patlen == 13 && STRNICMP(pat, "<buffer=abuf>", 13) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 // "<buffer=abuf>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 buflocal_nr = autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 else if (skipdigits(pat + 8) == pat + patlen - 1)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 // "<buffer=123>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 buflocal_nr = atoi((char *)pat + 8);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 if (is_buflocal)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 // normalize pat into standard "<buffer>#N" form
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 sprintf((char *)buflocal_pat, "<buffer=%d>", buflocal_nr);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 pat = buflocal_pat; // can modify pat and patlen
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 patlen = (int)STRLEN(buflocal_pat); // but not endpat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 * Find AutoPat entries with this pattern. When adding a command it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 * always goes at or after the last one, so start at the end.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 if (!forceit && *cmd != NUL && last_autopat[(int)event] != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 prev_ap = &last_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 prev_ap = &first_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 while ((ap = *prev_ap) != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 if (ap->pat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 /* Accept a pattern when:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 * - a group was specified and it's that group, or a group was
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 * not specified and it's the current group, or a group was
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 * not specified and we are listing
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 * - the length of the pattern matches
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 * - the pattern matches.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 * For <buffer[=X]>, this condition works because we normalize
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 * all buffer-local patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 if ((allgroups || ap->group == findgroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 && ap->patlen == patlen
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 && STRNCMP(pat, ap->pat, patlen) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 * Remove existing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 * If adding any new autocmd's for this AutoPat, don't
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 * delete the pattern from the autopat list, append to
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 * this list.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 if (forceit)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 if (*cmd != NUL && ap->next == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 au_remove_cmds(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 au_remove_pat(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 * Show autocmd's for this autopat, or buflocals <buffer=X>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 else if (*cmd == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 show_autocmd(ap, event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 * Add autocmd to this autopat, if it's the last one.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 else if (ap->next == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 prev_ap = &ap->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * Add a new command.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 if (*cmd != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 * If the pattern we want to add a command to does appear at the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 * end of the list (or not is not in the list at all), add the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 * pattern at the end of the list.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 if (ap == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 /* refuse to add buffer-local ap if buffer number is invalid */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 if (is_buflocal && (buflocal_nr == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 || buflist_findnr(buflocal_nr) == NULL))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 semsg(_("E680: <buffer=%d>: invalid buffer number "),
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 buflocal_nr);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 if (ap == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 ap->pat = vim_strnsave(pat, patlen);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 ap->patlen = patlen;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 if (ap->pat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 vim_free(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 if (is_buflocal)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 ap->buflocal_nr = buflocal_nr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 ap->reg_prog = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 char_u *reg_pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 ap->buflocal_nr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 reg_pat = file_pat_to_reg_pat(pat, endpat,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 &ap->allow_dirs, TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 if (reg_pat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 ap->reg_prog = vim_regcomp(reg_pat, RE_MAGIC);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 vim_free(reg_pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 if (reg_pat == NULL || ap->reg_prog == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 vim_free(ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 vim_free(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 ap->cmds = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 *prev_ap = ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 last_autopat[(int)event] = ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 ap->next = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 if (group == AUGROUP_ALL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 ap->group = current_augroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 ap->group = group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 * Add the autocmd at the end of the AutoCmd list.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 prev_ac = &(ap->cmds);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 while ((ac = *prev_ac) != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 prev_ac = &ac->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 if (ac == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 ac->cmd = vim_strsave(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 ac->script_ctx = current_sctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 ac->script_ctx.sc_lnum += sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 if (ac->cmd == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 vim_free(ac);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 ac->next = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 *prev_ac = ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 ac->nested = nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 au_cleanup(); // may really delete removed patterns/commands now
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 return OK;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 * Implementation of ":doautocmd [group] event [fname]".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 * Return OK for success, FAIL for failure;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 do_doautocmd(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 char_u *arg,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 int do_msg, // give message for no matching autocmds?
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 int *did_something)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 char_u *fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 int nothing_done = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 if (did_something != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 *did_something = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 * Check for a legal group name. If not, use AUGROUP_ALL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 group = au_get_grouparg(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 if (arg == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 if (*arg == '*')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 emsg(_("E217: Can't execute autocommands for ALL events"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 * Scan over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 * If we find an illegal name, return here, don't do anything.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 fname = find_end_event(arg, group != AUGROUP_ALL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 if (fname == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 fname = skipwhite(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 * Loop over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 while (*arg && !ends_excmd(*arg) && !VIM_ISWHITE(*arg))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 if (apply_autocmds_group(event_name2nr(arg, &arg),
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 fname, NULL, TRUE, group, curbuf, NULL))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 nothing_done = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 if (nothing_done && do_msg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 msg(_("No matching autocommands"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 if (did_something != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 *did_something = !nothing_done;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 return aborting() ? FAIL : OK;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 #else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 return OK;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 * ":doautoall": execute autocommands for each loaded buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 ex_doautoall(exarg_T *eap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 int retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 aco_save_T aco;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 buf_T *buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 bufref_T bufref;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 char_u *arg = eap->arg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 int call_do_modelines = check_nomodeline(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 int did_aucmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 * This is a bit tricky: For some commands curwin->w_buffer needs to be
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 * equal to curbuf, but for some buffers there may not be a window.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 * So we change the buffer for the current window for a moment. This
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 * gives problems when the autocommands make changes to the list of
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 * buffers or windows...
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 FOR_ALL_BUFFERS(buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 if (buf->b_ml.ml_mfp != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 // find a window for this buffer and save some values
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 aucmd_prepbuf(&aco, buf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 set_bufref(&bufref, buf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 // execute the autocommands for this buffer
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 retval = do_doautocmd(arg, FALSE, &did_aucmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 if (call_do_modelines && did_aucmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 // Execute the modeline settings, but don't set window-local
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 // options if we are using the current window for another
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 // buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 // restore the current window
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 aucmd_restbuf(&aco);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 // stop if there is some error or buffer was deleted
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 if (retval == FAIL || !bufref_valid(&bufref))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 check_cursor(); // just in case lines got deleted
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 * Check *argp for <nomodeline>. When it is present return FALSE, otherwise
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 * return TRUE and advance *argp to after it.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 * Thus return TRUE when do_modelines() should be called.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 check_nomodeline(char_u **argp)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 if (STRNCMP(*argp, "<nomodeline>", 12) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 *argp = skipwhite(*argp + 12);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 * Prepare for executing autocommands for (hidden) buffer "buf".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 * Search for a visible window containing the current buffer. If there isn't
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 * one then use "aucmd_win".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 * Set "curbuf" and "curwin" to match "buf".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 aucmd_prepbuf(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 aco_save_T *aco, // structure to save values in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 buf_T *buf) // new curbuf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 win_T *win;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 int save_ea;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 #ifdef FEAT_AUTOCHDIR
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 int save_acd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 // Find a window that is for the new buffer
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 if (buf == curbuf) // be quick when buf is curbuf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 win = curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 FOR_ALL_WINDOWS(win)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 if (win->w_buffer == buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 // Allocate "aucmd_win" when needed. If this fails (out of memory) fall
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 // back to using the current window.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 if (win == NULL && aucmd_win == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 win_alloc_aucmd_win();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 if (aucmd_win == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 win = curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 if (win == NULL && aucmd_win_used)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 // Strange recursive autocommand, fall back to using the current
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 // window. Expect a few side effects...
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 win = curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 aco->save_curwin = curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 aco->save_curbuf = curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 aco->save_prevwin = prevwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 if (win != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 // There is a window for "buf" in the current tab page, make it the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 // curwin. This is preferred, it has the least side effects (esp. if
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 // "buf" is curbuf).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 aco->use_aucmd_win = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 curwin = win;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 // There is no window for "buf", use "aucmd_win". To minimize the side
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 // effects, insert it in the current tab page.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 // Anything related to a window (e.g., setting folds) may have
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 // unexpected results.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 aco->use_aucmd_win = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 aucmd_win_used = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 aucmd_win->w_buffer = buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 #if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 aucmd_win->w_s = &buf->b_s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 ++buf->b_nwindows;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 win_init_empty(aucmd_win); // set cursor and topline to safe values
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 // Make sure w_localdir and globaldir are NULL to avoid a chdir() in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 // win_enter_ext().
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 VIM_CLEAR(aucmd_win->w_localdir);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 aco->globaldir = globaldir;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 globaldir = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 // Split the current window, put the aucmd_win in the upper half.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 // We don't want the BufEnter or WinEnter autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 block_autocmds();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 make_snapshot(SNAP_AUCMD_IDX);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 save_ea = p_ea;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 p_ea = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 #ifdef FEAT_AUTOCHDIR
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 // Prevent chdir() call in win_enter_ext(), through do_autochdir().
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 save_acd = p_acd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 p_acd = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 (void)win_split_ins(0, WSP_TOP, aucmd_win, 0);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 (void)win_comp_pos(); // recompute window positions
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 p_ea = save_ea;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 #ifdef FEAT_AUTOCHDIR
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 p_acd = save_acd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 unblock_autocmds();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 curwin = aucmd_win;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 curbuf = buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 aco->new_curwin = curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 set_bufref(&aco->new_curbuf, curbuf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 * Cleanup after executing autocommands for a (hidden) buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 * Restore the window as it was (if possible).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 aucmd_restbuf(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 aco_save_T *aco) // structure holding saved values
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 int dummy;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 if (aco->use_aucmd_win)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 --curbuf->b_nwindows;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 // Find "aucmd_win", it can't be closed, but it may be in another tab
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 // page. Do not trigger autocommands here.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 block_autocmds();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 if (curwin != aucmd_win)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 tabpage_T *tp;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 win_T *wp;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 FOR_ALL_TAB_WINDOWS(tp, wp)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 if (wp == aucmd_win)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 if (tp != curtab)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 goto_tabpage_tp(tp, TRUE, TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 win_goto(aucmd_win);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 goto win_found;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 win_found:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 // Remove the window and frame from the tree of frames.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 (void)winframe_remove(curwin, &dummy, NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 win_remove(curwin, NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 aucmd_win_used = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 last_status(FALSE); // may need to remove last status line
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 if (!valid_tabpage_win(curtab))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 // no valid window in current tabpage
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 close_tabpage(curtab);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 restore_snapshot(SNAP_AUCMD_IDX, FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 (void)win_comp_pos(); // recompute window positions
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 unblock_autocmds();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 if (win_valid(aco->save_curwin))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 curwin = aco->save_curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 // Hmm, original window disappeared. Just use the first one.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 curwin = firstwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 if (win_valid(aco->save_prevwin))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 prevwin = aco->save_prevwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 vars_clear(&aucmd_win->w_vars->dv_hashtab); // free all w: variables
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 hash_init(&aucmd_win->w_vars->dv_hashtab); // re-use the hashtab
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 curbuf = curwin->w_buffer;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 vim_free(globaldir);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 globaldir = aco->globaldir;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 // the buffer contents may have changed
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 check_cursor();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 if (curwin->w_topline > curbuf->b_ml.ml_line_count)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 curwin->w_topline = curbuf->b_ml.ml_line_count;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 #ifdef FEAT_DIFF
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 curwin->w_topfill = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 #if defined(FEAT_GUI)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 // Hide the scrollbars from the aucmd_win and update.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 gui_mch_enable_scrollbar(&aucmd_win->w_scrollbars[SBAR_LEFT], FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 gui_mch_enable_scrollbar(&aucmd_win->w_scrollbars[SBAR_RIGHT], FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 gui_may_update_scrollbars();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // restore curwin
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 if (win_valid(aco->save_curwin))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 // Restore the buffer which was previously edited by curwin, if
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 // it was changed, we are still the same window and the buffer is
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 // valid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 if (curwin == aco->new_curwin
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 && curbuf != aco->new_curbuf.br_buf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 && bufref_valid(&aco->new_curbuf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 && aco->new_curbuf.br_buf->b_ml.ml_mfp != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 # if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 if (curwin->w_s == &curbuf->b_s)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 curwin->w_s = &aco->new_curbuf.br_buf->b_s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 --curbuf->b_nwindows;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 curbuf = aco->new_curbuf.br_buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 curwin->w_buffer = curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 ++curbuf->b_nwindows;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 curwin = aco->save_curwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 curbuf = curwin->w_buffer;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 if (win_valid(aco->save_prevwin))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 prevwin = aco->save_prevwin;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 // In case the autocommand move the cursor to a position that that
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 // not exist in curbuf.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 check_cursor();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 static int autocmd_nested = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 * Execute autocommands for "event" and file name "fname".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 * Return TRUE if some commands were executed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 apply_autocmds(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 char_u *fname, // NULL or empty means use actual file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 char_u *fname_io, // fname to use for <afile> on cmdline
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 int force, // when TRUE, ignore autocmd_busy
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 buf_T *buf) // buffer for <abuf>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 return apply_autocmds_group(event, fname, fname_io, force,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 AUGROUP_ALL, buf, NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 * Like apply_autocmds(), but with extra "eap" argument. This takes care of
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 * setting v:filearg.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 apply_autocmds_exarg(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 char_u *fname,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 char_u *fname_io,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 int force,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 buf_T *buf,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 exarg_T *eap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 return apply_autocmds_group(event, fname, fname_io, force,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 AUGROUP_ALL, buf, eap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 * Like apply_autocmds(), but handles the caller's retval. If the script
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 * processing is being aborted or if retval is FAIL when inside a try
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 * conditional, no autocommands are executed. If otherwise the autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 * cause the script to be aborted, retval is set to FAIL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 apply_autocmds_retval(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 char_u *fname, // NULL or empty means use actual file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 char_u *fname_io, // fname to use for <afile> on cmdline
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 int force, // when TRUE, ignore autocmd_busy
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 buf_T *buf, // buffer for <abuf>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 int *retval) // pointer to caller's retval
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 int did_cmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 if (should_abort(*retval))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 did_cmd = apply_autocmds_group(event, fname, fname_io, force,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 AUGROUP_ALL, buf, NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 if (did_cmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 && aborting()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 )
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 *retval = FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 return did_cmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 * Return TRUE when there is a CursorHold autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 has_cursorhold(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 return (first_autopat[(int)(get_real_state() == NORMAL_BUSY
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 ? EVENT_CURSORHOLD : EVENT_CURSORHOLDI)] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 * Return TRUE if the CursorHold event can be triggered.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 trigger_cursorhold(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 int state;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 if (!did_cursorhold
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 && has_cursorhold()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 && reg_recording == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 && typebuf.tb_len == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 #ifdef FEAT_INS_EXPAND
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 && !ins_compl_active()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 )
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 state = get_real_state();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 if (state == NORMAL_BUSY || (state & INSERT) != 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 * Return TRUE when there is a CursorMoved autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 has_cursormoved(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 return (first_autopat[(int)EVENT_CURSORMOVED] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 #if defined(FEAT_CONCEAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 * Return TRUE when there is a CursorMovedI autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 has_cursormovedI(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 return (first_autopat[(int)EVENT_CURSORMOVEDI] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 * Return TRUE when there is a TextChanged autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 has_textchanged(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 return (first_autopat[(int)EVENT_TEXTCHANGED] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 * Return TRUE when there is a TextChangedI autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 has_textchangedI(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 return (first_autopat[(int)EVENT_TEXTCHANGEDI] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 * Return TRUE when there is a TextChangedP autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 has_textchangedP(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 return (first_autopat[(int)EVENT_TEXTCHANGEDP] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 * Return TRUE when there is an InsertCharPre autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 has_insertcharpre(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 * Return TRUE when there is an CmdUndefined autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 has_cmdundefined(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 return (first_autopat[(int)EVENT_CMDUNDEFINED] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 * Return TRUE when there is an FuncUndefined autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 has_funcundefined(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 #if defined(FEAT_EVAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 * Return TRUE when there is a TextYankPost autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 has_textyankpost(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 return (first_autopat[(int)EVENT_TEXTYANKPOST] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 * Execute autocommands for "event" and file name "fname".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 * Return TRUE if some commands were executed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 apply_autocmds_group(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 char_u *fname, // NULL or empty means use actual file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 char_u *fname_io, // fname to use for <afile> on cmdline, NULL means
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 // use fname
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 int force, // when TRUE, ignore autocmd_busy
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 int group, // group ID, or AUGROUP_ALL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 buf_T *buf, // buffer for <abuf>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 exarg_T *eap UNUSED) // command arguments
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 char_u *sfname = NULL; // short file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 char_u *tail;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 int save_changed;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 buf_T *old_curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 char_u *save_sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 linenr_T save_sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 char_u *save_autocmd_fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 int save_autocmd_fname_full;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 int save_autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 char_u *save_autocmd_match;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 int save_autocmd_busy;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 int save_autocmd_nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 static int nesting = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 AutoPatCmd patcmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 sctx_T save_current_sctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 funccal_entry_T funccal_entry;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 char_u *save_cmdarg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 long save_cmdbang;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 static int filechangeshell_busy = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 #ifdef FEAT_PROFILE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 proftime_T wait_time;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 int did_save_redobuff = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 save_redo_T save_redo;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 int save_KeyTyped = KeyTyped;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 * Quickly return if there are no autocommands for this event or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 * autocommands are blocked.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 if (event == NUM_EVENTS || first_autopat[(int)event] == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 || autocmd_blocked > 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 * When autocommands are busy, new autocommands are only executed when
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 * explicitly enabled with the "nested" flag.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 if (autocmd_busy && !(force || autocmd_nested))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 * Quickly return when immediately aborting on error, or when an interrupt
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 * occurred or an exception was thrown but not caught.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 if (aborting())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 * FileChangedShell never nests, because it can create an endless loop.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 if (filechangeshell_busy && (event == EVENT_FILECHANGEDSHELL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 || event == EVENT_FILECHANGEDSHELLPOST))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 * Ignore events in 'eventignore'.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 if (event_ignored(event))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 * Allow nesting of autocommands, but restrict the depth, because it's
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 * possible to create an endless loop.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 if (nesting == 10)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 emsg(_("E218: autocommand nesting too deep"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 * Check if these autocommands are disabled. Used when doing ":all" or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 * ":ball".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 if ( (autocmd_no_enter
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 && (event == EVENT_WINENTER || event == EVENT_BUFENTER))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 || (autocmd_no_leave
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 && (event == EVENT_WINLEAVE || event == EVENT_BUFLEAVE)))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 * Save the autocmd_* variables and info about the current buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 save_autocmd_fname = autocmd_fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 save_autocmd_fname_full = autocmd_fname_full;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 save_autocmd_bufnr = autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 save_autocmd_match = autocmd_match;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 save_autocmd_busy = autocmd_busy;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 save_autocmd_nested = autocmd_nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 save_changed = curbuf->b_changed;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 old_curbuf = curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 * Set the file name to be used for <afile>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 * Make a copy to avoid that changing a buffer name or directory makes it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 * invalid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 if (fname_io == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 if (event == EVENT_COLORSCHEME || event == EVENT_COLORSCHEMEPRE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 || event == EVENT_OPTIONSET)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 autocmd_fname = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 else if (fname != NULL && !ends_excmd(*fname))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 autocmd_fname = fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 else if (buf != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 autocmd_fname = buf->b_ffname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 autocmd_fname = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 autocmd_fname = fname_io;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 if (autocmd_fname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 autocmd_fname = vim_strsave(autocmd_fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 autocmd_fname_full = FALSE; // call FullName_save() later
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 * Set the buffer number to be used for <abuf>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 if (buf == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 autocmd_bufnr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 autocmd_bufnr = buf->b_fnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 * When the file name is NULL or empty, use the file name of buffer "buf".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 * Always use the full path of the file name to match with, in case
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 * "allow_dirs" is set.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 if (fname == NULL || *fname == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 if (buf == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 fname = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 #ifdef FEAT_SYN_HL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 if (event == EVENT_SYNTAX)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 fname = buf->b_p_syn;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 if (event == EVENT_FILETYPE)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 fname = buf->b_p_ft;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 if (buf->b_sfname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 sfname = vim_strsave(buf->b_sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 fname = buf->b_ffname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 if (fname == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 fname = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 fname = vim_strsave(fname); // make a copy, so we can change it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 sfname = vim_strsave(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 // Don't try expanding FileType, Syntax, FuncUndefined, WindowID,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 // ColorScheme, QuickFixCmd* or DirChanged
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 if (event == EVENT_FILETYPE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 || event == EVENT_SYNTAX
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 || event == EVENT_CMDLINECHANGED
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 || event == EVENT_CMDLINEENTER
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 || event == EVENT_CMDLINELEAVE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 || event == EVENT_CMDWINENTER
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 || event == EVENT_CMDWINLEAVE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 || event == EVENT_CMDUNDEFINED
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 || event == EVENT_FUNCUNDEFINED
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 || event == EVENT_REMOTEREPLY
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 || event == EVENT_SPELLFILEMISSING
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 || event == EVENT_QUICKFIXCMDPRE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 || event == EVENT_COLORSCHEME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 || event == EVENT_COLORSCHEMEPRE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 || event == EVENT_OPTIONSET
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 || event == EVENT_QUICKFIXCMDPOST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 || event == EVENT_DIRCHANGED)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 fname = vim_strsave(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 autocmd_fname_full = TRUE; // don't expand it later
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 fname = FullName_save(fname, FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 if (fname == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 vim_free(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 goto BYPASS_AU;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 * Replace all backslashes with forward slashes. This makes the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 * autocommand patterns portable between Unix and MS-DOS.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 if (sfname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 forward_slash(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 forward_slash(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 #ifdef VMS
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 // remove version for correct match
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 if (sfname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 vms_remove_version(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 vms_remove_version(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 * Set the name to be used for <amatch>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 autocmd_match = fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 // Don't redraw while doing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 ++RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 save_sourcing_name = sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 sourcing_name = NULL; // don't free this one
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 save_sourcing_lnum = sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 sourcing_lnum = 0; // no line number here
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 save_current_sctx = current_sctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 # ifdef FEAT_PROFILE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 if (do_profiling == PROF_YES)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 prof_child_enter(&wait_time); // doesn't count for the caller itself
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 // Don't use local function variables, if called from a function.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 save_funccal(&funccal_entry);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 * When starting to execute autocommands, save the search patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 if (!autocmd_busy)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 save_search_patterns();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 #ifdef FEAT_INS_EXPAND
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 if (!ins_compl_active())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 saveRedobuff(&save_redo);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 did_save_redobuff = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 did_filetype = keep_filetype;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 * Note that we are applying autocmds. Some commands need to know.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 autocmd_busy = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 filechangeshell_busy = (event == EVENT_FILECHANGEDSHELL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 ++nesting; // see matching decrement below
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 // Remember that FileType was triggered. Used for did_filetype().
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 if (event == EVENT_FILETYPE)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 did_filetype = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 tail = gettail(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 // Find first autocommand that matches
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 patcmd.curpat = first_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 patcmd.nextcmd = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 patcmd.group = group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 patcmd.fname = fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 patcmd.sfname = sfname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 patcmd.tail = tail;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 patcmd.event = event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 patcmd.arg_bufnr = autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 patcmd.next = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 auto_next_pat(&patcmd, FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 // found one, start executing the autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 if (patcmd.curpat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 // add to active_apc_list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 patcmd.next = active_apc_list;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 active_apc_list = &patcmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 // set v:cmdarg (only when there is a matching pattern)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 save_cmdbang = (long)get_vim_var_nr(VV_CMDBANG);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 if (eap != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 save_cmdarg = set_cmdarg(eap, NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 set_vim_var_nr(VV_CMDBANG, (long)eap->forceit);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 save_cmdarg = NULL; // avoid gcc warning
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 // mark the last pattern, to avoid an endless loop when more patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 // are added when executing autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 for (ap = patcmd.curpat; ap->next != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 ap->last = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 ap->last = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 check_lnums(TRUE); // make sure cursor and topline are valid
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 do_cmdline(NULL, getnextac, (void *)&patcmd,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 if (eap != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 (void)set_cmdarg(NULL, save_cmdarg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 set_vim_var_nr(VV_CMDBANG, save_cmdbang);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 // delete from active_apc_list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 if (active_apc_list == &patcmd) // just in case
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 active_apc_list = patcmd.next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 --RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 autocmd_busy = save_autocmd_busy;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 filechangeshell_busy = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 autocmd_nested = save_autocmd_nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 vim_free(sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 sourcing_name = save_sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 sourcing_lnum = save_sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 vim_free(autocmd_fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 autocmd_fname = save_autocmd_fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 autocmd_fname_full = save_autocmd_fname_full;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 autocmd_bufnr = save_autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095 autocmd_match = save_autocmd_match;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 current_sctx = save_current_sctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 restore_funccal();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 # ifdef FEAT_PROFILE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 if (do_profiling == PROF_YES)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 prof_child_exit(&wait_time);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 KeyTyped = save_KeyTyped;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 vim_free(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 vim_free(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 --nesting; // see matching increment above
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 * When stopping to execute autocommands, restore the search patterns and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 * the redo buffer. Free any buffers in the au_pending_free_buf list and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 * free any windows in the au_pending_free_win list.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 if (!autocmd_busy)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 restore_search_patterns();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 if (did_save_redobuff)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 restoreRedobuff(&save_redo);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 did_filetype = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 while (au_pending_free_buf != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 buf_T *b = au_pending_free_buf->b_next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 vim_free(au_pending_free_buf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 au_pending_free_buf = b;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 while (au_pending_free_win != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 win_T *w = au_pending_free_win->w_next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 vim_free(au_pending_free_win);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 au_pending_free_win = w;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 * Some events don't set or reset the Changed flag.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 * Check if still in the same buffer!
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 if (curbuf == old_curbuf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 && (event == EVENT_BUFREADPOST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 || event == EVENT_BUFWRITEPOST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 || event == EVENT_FILEAPPENDPOST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 || event == EVENT_VIMLEAVE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 || event == EVENT_VIMLEAVEPRE))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 #ifdef FEAT_TITLE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 if (curbuf->b_changed != save_changed)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 need_maketitle = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 curbuf->b_changed = save_changed;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 au_cleanup(); // may really delete removed patterns/commands now
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 BYPASS_AU:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 // When wiping out a buffer make sure all its buffer-local autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 // are deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 if (event == EVENT_BUFWIPEOUT && buf != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 aubuflocal_remove(buf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 if (retval == OK && event == EVENT_FILETYPE)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 au_did_filetype = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 # ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 static char_u *old_termresponse = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 * Block triggering autocommands until unblock_autocmd() is called.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 * Can be used recursively, so long as it's symmetric.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 block_autocmds(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 # ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 // Remember the value of v:termresponse.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 if (autocmd_blocked == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 old_termresponse = get_vim_var_str(VV_TERMRESPONSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 ++autocmd_blocked;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 unblock_autocmds(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 --autocmd_blocked;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 # ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 // When v:termresponse was set while autocommands were blocked, trigger
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 // the autocommands now. Esp. useful when executing a shell command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 // during startup (vimdiff).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 if (autocmd_blocked == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 && get_vim_var_str(VV_TERMRESPONSE) != old_termresponse)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 apply_autocmds(EVENT_TERMRESPONSE, NULL, NULL, FALSE, curbuf);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 #if defined(FEAT_EVAL) && (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM)) \
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 is_autocmd_blocked(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 return autocmd_blocked != 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 * Find next autocommand pattern that matches.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 auto_next_pat(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 AutoPatCmd *apc,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 int stop_at_last) // stop when 'last' flag is set
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 AutoCmd *cp;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 char_u *name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 char *s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 VIM_CLEAR(sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 apc->curpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 // Only use a pattern when it has not been removed, has commands and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 // the group matches. For buffer-local autocommands only check the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 // buffer number.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 && (apc->group == AUGROUP_ALL || apc->group == ap->group))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2234 // execution-condition
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 if (ap->buflocal_nr == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 ? (match_file_pat(NULL, &ap->reg_prog, apc->fname,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 apc->sfname, apc->tail, ap->allow_dirs))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 : ap->buflocal_nr == apc->arg_bufnr)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 name = event_nr2name(apc->event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 s = _("%s Autocommands for \"%s\"");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242 sourcing_name = alloc((unsigned)(STRLEN(s)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 + STRLEN(name) + ap->patlen + 1));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 if (sourcing_name != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 sprintf((char *)sourcing_name, s,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 (char *)name, (char *)ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 if (p_verbose >= 8)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2249 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 verbose_enter();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 smsg(_("Executing %s"), sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 verbose_leave();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 apc->curpat = ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257 apc->nextcmd = ap->cmds;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 // mark last command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 for (cp = ap->cmds; cp->next != NULL; cp = cp->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 cp->last = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 cp->last = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 line_breakcheck();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 if (apc->curpat != NULL) // found a match
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 if (stop_at_last && ap->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 * Get next autocommand command.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 * Called by do_cmdline() to get the next line for ":if".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 * Returns allocated string, or NULL for end of autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2277 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2278 getnextac(int c UNUSED, void *cookie, int indent UNUSED)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 AutoPatCmd *acp = (AutoPatCmd *)cookie;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 char_u *retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 // Can be called again after returning the last line.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 if (acp->curpat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 // repeat until we find an autocommand to execute
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 for (;;)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 // skip removed commands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 while (acp->nextcmd != NULL && acp->nextcmd->cmd == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 if (acp->nextcmd->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 acp->nextcmd = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 acp->nextcmd = acp->nextcmd->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 if (acp->nextcmd != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 // at end of commands, find next pattern that matches
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 if (acp->curpat->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 acp->curpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 acp->curpat = acp->curpat->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 if (acp->curpat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 auto_next_pat(acp, TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 if (acp->curpat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 ac = acp->nextcmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 if (p_verbose >= 9)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 verbose_enter_scroll();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 smsg(_("autocommand %s"), ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 msg_puts("\n"); // don't overwrite this either
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 verbose_leave_scroll();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 retval = vim_strsave(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 autocmd_nested = ac->nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 current_sctx = ac->script_ctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 if (ac->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 acp->nextcmd = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 acp->nextcmd = ac->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 * Return TRUE if there is a matching autocommand for "fname".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 * To account for buffer-local autocommands, function needs to know
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 * in which buffer the file will be opened.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 has_autocmd(event_T event, char_u *sfname, buf_T *buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 char_u *fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 char_u *tail = gettail(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 fname = FullName_save(sfname, FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 if (fname == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 * Replace all backslashes with forward slashes. This makes the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 * autocommand patterns portable between Unix and MS-DOS.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 sfname = vim_strsave(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 if (sfname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 forward_slash(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 forward_slash(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 && (ap->buflocal_nr == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 ? match_file_pat(NULL, &ap->reg_prog,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 fname, sfname, tail, ap->allow_dirs)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 : buf != NULL && ap->buflocal_nr == buf->b_fnum
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 ))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373 vim_free(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 vim_free(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383 * Function given to ExpandGeneric() to obtain the list of autocommand group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 * names.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 get_augroup_name(expand_T *xp UNUSED, int idx)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 if (idx == augroups.ga_len) // add "END" add the end
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 return (char_u *)"END";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 if (idx >= augroups.ga_len) // end of list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 // skip deleted entries
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 return (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 return AUGROUP_NAME(idx); // return a name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 static int include_groups = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 set_context_in_autocmd(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 expand_T *xp,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 char_u *arg,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 int doautocmd) // TRUE for :doauto*, FALSE for :autocmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 // check for a group name, skip it if present
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 include_groups = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 p = arg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 group = au_get_grouparg(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 // If there only is a group name that's what we expand.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 if (*arg == NUL && group != AUGROUP_ALL && !VIM_ISWHITE(arg[-1]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 arg = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 // skip over event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 for (p = arg; *p != NUL && !VIM_ISWHITE(*p); ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 arg = p + 1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 if (*p == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 if (group == AUGROUP_ALL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 include_groups = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 xp->xp_context = EXPAND_EVENTS; // expand event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 xp->xp_pattern = arg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 // skip over pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 arg = skipwhite(p);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 while (*arg && (!VIM_ISWHITE(*arg) || arg[-1] == '\\'))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 arg++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 if (*arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 return arg; // expand (next) command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 if (doautocmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 xp->xp_context = EXPAND_FILES; // expand file names
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 xp->xp_context = EXPAND_NOTHING; // pattern is not expanded
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 * Function given to ExpandGeneric() to obtain the list of event names.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 get_event_name(expand_T *xp UNUSED, int idx)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 if (idx < augroups.ga_len) // First list group names, if wanted
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 if (!include_groups || AUGROUP_NAME(idx) == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 || AUGROUP_NAME(idx) == get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 return (char_u *)""; // skip deleted entries
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 return AUGROUP_NAME(idx); // return a name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 return (char_u *)event_names[idx - augroups.ga_len].name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 #endif // FEAT_CMDL_COMPL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 #if defined(FEAT_EVAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 * Return TRUE if autocmd is supported.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 autocmd_supported(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 return (event_name2nr(name, &p) != NUM_EVENTS);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 * Return TRUE if an autocommand is defined for a group, event and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 * pattern: The group can be omitted to accept any group. "event" and "pattern"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 * can be NULL to accept any event and pattern. "pattern" can be NULL to accept
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 * any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 * Used for:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 * exists("#Group") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 * exists("#Group#Event") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 * exists("#Group#Event#pat") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 * exists("#Event") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 * exists("#Event#pat")
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 au_exists(char_u *arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 char_u *arg_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 char_u *pattern = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 char_u *event_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 buf_T *buflocal_buf = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 // Make a copy so that we can change the '#' chars to a NUL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 arg_save = vim_strsave(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 if (arg_save == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 p = vim_strchr(arg_save, '#');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 if (p != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 *p++ = NUL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 // First, look for an autocmd group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 group = au_find_group(arg_save);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2517 // Didn't match a group name, assume the first argument is an event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 event_name = arg_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 if (p == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 // "Group": group name is present and it's recognized
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 // Must be "Group#Event" or "Group#Event#pat".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 event_name = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 p = vim_strchr(event_name, '#');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 if (p != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 *p++ = NUL; // "Group#Event#pat"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 pattern = p; // "pattern" is NULL when there is no pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 // find the index (enum) for the event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540 event = event_name2nr(event_name, &p);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 // return FALSE if the event name is not recognized
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 if (event == NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 // Find the first autocommand for this event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 // If there isn't any, return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548 // If there is one and no pattern given, return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 ap = first_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 if (ap == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 // if pattern is "<buffer>", special handling is needed which uses curbuf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 // for pattern "<buffer=N>, fnamecmp() will work fine
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 buflocal_buf = curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 // Check if there is an autocommand with the given pattern.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 for ( ; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 // only use a pattern when it has not been removed and has commands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 // For buffer-local autocommands, fnamecmp() works fine.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 && (group == AUGROUP_ALL || ap->group == group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 && (pattern == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 || (buflocal_buf == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 ? fnamecmp(ap->pat, pattern) == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 : ap->buflocal_nr == buflocal_buf->b_fnum)))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 theend:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 vim_free(arg_save);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 #endif