annotate src/autocmd.c @ 20826:beb49796cb36 v8.2.0965

patch 8.2.0965: has_funcundefined() is not used Commit: https://github.com/vim/vim/commit/5055c56cfbedc6326c607d40c7a1241682f7675e Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 12 22:15:31 2020 +0200 patch 8.2.0965: has_funcundefined() is not used Problem: Has_funcundefined() is not used. Solution: Delete the function. (Dominique Pell?, closes https://github.com/vim/vim/issues/6242)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Jun 2020 22:30:03 +0200
parents e76b83c07bd8
children a427f5f26419
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).
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
55 char once; // "One shot": removed after execution
15634
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 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
57 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
58 #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
59 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
60 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 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
62 } AutoCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 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
65 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 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
67 // 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
68 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
69 // 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 } AutoPat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 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
80 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 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
82 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
83 } 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
84 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {"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
86 {"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
87 {"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
88 {"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
89 {"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
90 {"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
91 {"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
92 {"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
93 {"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
94 {"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
95 {"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
96 {"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
97 {"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
98 {"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
99 {"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
100 {"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
101 {"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
102 {"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
103 {"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
104 {"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
105 {"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
106 {"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
107 {"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
108 {"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
109 {"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
110 {"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
111 {"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
112 {"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
113 {"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
114 {"ColorSchemePre", EVENT_COLORSCHEMEPRE},
16268
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
115 {"CompleteChanged", EVENT_COMPLETECHANGED},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 {"CompleteDone", EVENT_COMPLETEDONE},
19199
8cbadf7fb9d4 patch 8.2.0158: triggering CompleteDone earlier is not backwards compatible
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
117 {"CompleteDonePre", EVENT_COMPLETEDONEPRE},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 {"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
119 {"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
120 {"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
121 {"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
122 {"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
123 {"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
124 {"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
125 {"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
126 {"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
127 {"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
128 {"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
129 {"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
130 {"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
131 {"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
132 {"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
133 {"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
134 {"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
135 {"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
136 {"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
137 {"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
138 {"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
139 {"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
140 {"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
141 {"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
142 {"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
143 {"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
144 {"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
145 {"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
146 {"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
147 {"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
148 {"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
149 {"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
150 {"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
151 {"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
152 {"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
153 {"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
154 {"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
155 {"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
156 {"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
157 {"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
158 {"RemoteReply", EVENT_REMOTEREPLY},
18098
a2870e6f5b45 patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
159 {"SafeState", EVENT_SAFESTATE},
18102
0d9ec3a2821f patch 8.1.2046: SafeState may be triggered at the wrong moment
Bram Moolenaar <Bram@vim.org>
parents: 18098
diff changeset
160 {"SafeStateAgain", EVENT_SAFESTATEAGAIN},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 {"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
162 {"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
163 {"ShellFilterPost", EVENT_SHELLFILTERPOST},
20800
e76b83c07bd8 patch 8.2.0952: no simple way to interrupt Vim
Bram Moolenaar <Bram@vim.org>
parents: 20751
diff changeset
164 {"SigUSR1", EVENT_SIGUSR1},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 {"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
166 {"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
167 {"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
168 {"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
169 {"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
170 {"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
171 {"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
172 {"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
173 {"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
174 {"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
175 {"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
176 {"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
177 {"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
178 {"TerminalOpen", EVENT_TERMINALOPEN},
18450
507348b211b4 patch 8.1.2219: no autocommand for open window with terminal
Bram Moolenaar <Bram@vim.org>
parents: 18102
diff changeset
179 {"TerminalWinOpen", EVENT_TERMINALWINOPEN},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 {"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
181 {"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
182 {"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
183 {"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
184 {"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
185 {"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
186 {"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
187 {"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
188 {"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
189 {"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
190 {"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
191 {"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
192 {"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
193 {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
194 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 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
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 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
199 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
200 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
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 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 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
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 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
209 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
210 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
211 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
212 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
213 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
214 };
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 #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
217 #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
218 #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
219
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 * 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
222 */
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
223 struct AutoPatCmd_S
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 // buf is deleted.
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
234 AutoPatCmd *next; // chain of active apc-s for auto-invalidation
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
235 };
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
237 static AutoPatCmd *active_apc_list = NULL; // stack of active autocommands
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
239 // Macro to loop over all the patterns for an autocmd event
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
240 #define FOR_ALL_AUTOCMD_PATTERNS(event, ap) \
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
241 for ((ap) = first_autopat[(int)(event)]; (ap) != NULL; (ap) = (ap)->next)
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
242
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * 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
245 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 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
247 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
248 // use get_deleted_augroup() to get this
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 * 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
253 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 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
255
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
256 static int au_need_clean = FALSE; // need to delete marked patterns
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257
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 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
259 static int au_get_grouparg(char_u **argp);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
260 static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group);
15634
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 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
262 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
263 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
264
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 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
266 static int last_group;
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
267 static int autocmd_blocked = 0; // block all autocmds
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 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
270 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
271 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 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
273 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
274 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 * 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
279 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 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
281 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
282 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 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
284
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 // 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
286 // 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
287 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
288 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 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
290 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 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
293 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
294 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 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
296 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 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
298 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 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
300 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
301 else
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_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
303 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
304 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 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
306 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
307 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
308 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
309 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
310 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 }
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_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
313 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
314
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 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
316 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 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
318 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 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
320 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
321 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
322 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
323 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 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
325 #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
326 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
327 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
328 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 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
330 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 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
332 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 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
334 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
335 return;
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 * 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
343 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 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
345 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
346 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 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
348 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
349 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 * 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
354 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 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
356 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
357 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 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
359
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 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
361 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
362 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
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
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
365 // Delete one command from an autocmd pattern.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
366 static void au_del_cmd(AutoCmd *ac)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
367 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
368 VIM_CLEAR(ac->cmd);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
369 au_need_clean = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
370 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
371
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 * 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
374 * 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
375 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 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
377 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
378 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 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
380 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
381 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
382
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 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
384 return;
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 events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 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
388 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
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 // 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
391 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
392 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
393 {
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
394 int has_cmd = FALSE;
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
395
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 // 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
397 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
398 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
399 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 // 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
401 // 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
402 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
403 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 *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
405 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
406 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
407 }
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
408 else
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
409 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
410 has_cmd = TRUE;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 prev_ac = &(ac->next);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
412 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
413 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
414
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
415 if (ap->pat != NULL && !has_cmd)
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
416 // Pattern was not marked for deletion, but all of its
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
417 // commands were. So mark the pattern for deletion.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
418 au_remove_pat(ap);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 // 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
421 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
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 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
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 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
426 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
427 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 // 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
429 // 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
430 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
431 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 *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
433 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
434 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
435 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 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
438 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 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
442 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 * 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
446 * autocmds.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 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
450 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 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
452 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
453 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
454
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 // 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
456 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
457 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
458 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
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 // 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
461 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
462 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
463 // loop over all autocommand patterns
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
464 FOR_ALL_AUTOCMD_PATTERNS(event, ap)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 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
466 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 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
468 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
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 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
471 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
472 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
473 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
474 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 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
477 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478
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 * 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
481 * 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
482 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 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
484 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
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 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
487
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 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
489 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
490 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 // 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
492 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
493 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
494 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 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
496 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
497
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 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
499 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
500 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
501 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
502 ++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
503 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 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
506 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 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
509 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
510 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 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
512
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 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
514 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
515 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
516 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
517 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
518 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 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
521 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
522 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
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 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
525 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
526 {
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
527 FOR_ALL_AUTOCMD_PATTERNS(event, ap)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 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
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 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
531 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
532 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
533 break;
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 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
537 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
538 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
539 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 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
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
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 * 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
546 * 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
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 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
549 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
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 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
552
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 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
554 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
555 && 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
556 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
557 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
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
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 * 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
562 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int
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_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
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 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
567 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
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 * ":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
571 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 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
574 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 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
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 (*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
580 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
581 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 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
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 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
585 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
586 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
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 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
589 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
590 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
591 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 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
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 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
595 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
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 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
598 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 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
600 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
601 }
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 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
604 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
605 }
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 #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
609 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 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
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 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
613 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
614
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 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
616 ++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
617 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
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 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
620 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 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
622 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
623 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
624 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 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
626 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 * 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
631 * 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
632 * 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
633 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 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
635 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
636 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 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
638 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
639 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
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 // 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
642 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
643 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 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
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 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
647 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
648 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 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
651 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 *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
653 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
654 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
655 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 * 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
660 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 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
662 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
663 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 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
665
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 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
667 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
668 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
669 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
670 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 * 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
674 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 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
676 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
677 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
678 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
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 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
681 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
682
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 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
684 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 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
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 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
688 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
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 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
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 else
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 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
695 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 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
697 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 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
699 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
700 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 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
702 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
703 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 }
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 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
707 }
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 * 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
711 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 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
713 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
714 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 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
716
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 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
718 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 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
720 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
721 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
722 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
723 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 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
726 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727
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 * 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
730 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 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
733 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 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
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 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
737 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 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
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 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
741 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
742 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 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
745 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
746 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 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
749 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 # 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
752
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 * 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
755 * 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
756 * 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
757 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 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
759 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
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 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
762 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
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 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
765 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
766 {
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
767 new_ei = vim_strnsave(p_ei, STRLEN(p_ei) + STRLEN(what));
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 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
769 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 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
771 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
772 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 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
774 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
775 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
776 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
777 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 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
780 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 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
784 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 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
786 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 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
788 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
789 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
790 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 }
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
792 # endif // FEAT_SYN_HL
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 * 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
796 * 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
797 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 * :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
799 * 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
800 * 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
801 * 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
802 * :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
803 * <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
804 * :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
805 * <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 * :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
807 * :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
808 * <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
809 * <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
810 * :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
811 * <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
812 * :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
813 * <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
814 * :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
815 * group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 * 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
818 * 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
819 * :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
820 * :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
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 * :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
823 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 * 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
825 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 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
828 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 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
830 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
831 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
832 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
833 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
834 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
835 int nested = FALSE;
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
836 int once = FALSE;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 int group;
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
838 int i;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839
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 (*arg == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 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
843 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
844 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 * 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
849 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 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
851 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
852 return;
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 * 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
857 * 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
858 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 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
860 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
861 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 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
864 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
865 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 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
867 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
868 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 * 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
873 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 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
875 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
876 cmd++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 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
878 *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
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 // 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
881 // 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
882 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
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 #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
885 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
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 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
888 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890 #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
891 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
892 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 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
894 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
895 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 cmd = skipwhite(cmd);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
898 for (i = 0; i < 2; i++)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
900 if (*cmd != NUL)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
901 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
902 // Check for "++once" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
903 if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6]))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
904 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
905 if (once)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
906 semsg(_(e_duparg2), "++once");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
907 once = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
908 cmd = skipwhite(cmd + 6);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
909 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
910
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
911 // Check for "++nested" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
912 if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8])))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
913 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
914 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
915 semsg(_(e_duparg2), "++nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
916 nested = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
917 cmd = skipwhite(cmd + 8);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
918 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
919
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
920 // Check for the old "nested" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
921 if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
922 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
923 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
924 semsg(_(e_duparg2), "nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
925 nested = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
926 cmd = skipwhite(cmd + 6);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
927 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
928 }
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 * 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
933 * 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
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 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
936 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 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
938 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
939 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 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
941 }
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 * 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
946 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 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
948 // 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
949 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
950
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 * 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
953 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 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
955 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
956 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
957 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 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
959 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
960 if (do_autocmd_event(event, pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
961 once, nested, cmd, forceit, group) == FAIL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 break;
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 else
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 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
967 if (do_autocmd_event(event_name2nr(arg, &arg), pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
968 once, nested, cmd, forceit, group) == FAIL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 }
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 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
973 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
974 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
975 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 * 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
979 * 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
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 * 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
982 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 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
984 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
985 {
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 *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
987 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
988 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
989 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
990
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 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
992 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 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
994 {
20751
d9a2e5dcfd9f patch 8.2.0928: many type casts are used for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 19888
diff changeset
995 group_name = vim_strnsave(arg, p - arg);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 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
997 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
998 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
999 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
1000 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
1001 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 *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
1003 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
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 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
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
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 * 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
1010 * 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
1011 * 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
1012 * 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
1013 * 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
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 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
1016 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
1017 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
1018 char_u *pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1019 int once,
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 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
1021 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
1022 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
1023 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
1024 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 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
1027 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
1028 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
1029 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
1030 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
1031 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
1032 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
1033 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
1034 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
1035 int buflocal_nr;
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1036 char_u buflocal_pat[25]; // for "<buffer=X>"
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 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
1039 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
1040 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 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
1042 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
1043
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 * 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
1046 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 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
1048 {
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
1049 FOR_ALL_AUTOCMD_PATTERNS(event, ap)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 {
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 (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
1052 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 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
1054 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
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 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
1057 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
1058 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 * 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
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 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
1065 {
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 * 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
1068 * 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
1069 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 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
1071 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
1072 || (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
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 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
1075 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
1076 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
1077 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
1078 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 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
1080 continue;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 * 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
1085 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 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
1087 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
1088
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 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
1090 && 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
1091 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // "<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
1093 // 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
1094 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
1095 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
1096 // "<buffer>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 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
1098 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
1099 {
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 (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
1101 // "<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
1102 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
1103 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
1104 // "<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
1105 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
1106 }
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 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
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 // 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
1112 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
1113 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
1114 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
1115 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 * 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
1119 * 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
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 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
1122 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
1123 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 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
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 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
1128 {
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1129 /*
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1130 * Accept a pattern when:
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 * - 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
1132 * 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
1133 * 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
1134 * - 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
1135 * - 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
1136 * 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
1137 * 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
1138 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 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
1140 && 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
1141 && 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
1142 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 * 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
1145 * 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
1146 * 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
1147 * 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
1148 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 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
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 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
1152 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 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
1154 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 * 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
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 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
1163 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
1164
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 * 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
1167 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 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
1169 break;
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 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
1173 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 * 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
1177 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 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
1179 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 * 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
1182 * 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
1183 * 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
1184 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 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
1186 {
18757
c469e1930456 patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1187 // refuse to add buffer-local ap if buffer number is invalid
15634
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 (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
1189 || 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
1190 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 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
1192 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
1193 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
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
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
1196 ap = ALLOC_ONE(AutoPat);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 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
1198 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
1199 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
1200 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
1201 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
1202 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 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
1204 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
1205 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 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
1208 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 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
1210 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
1211 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 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
1215
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 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
1217 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
1218 &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
1219 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
1220 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
1221 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
1222 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
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 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
1225 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
1226 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
1227 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 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
1230 *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
1231 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
1232 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
1233 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
1234 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
1235 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 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
1237 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
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 * 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
1241 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 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
1243 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
1244 prev_ac = &ac->next;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
1245 ac = ALLOC_ONE(AutoCmd);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 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
1247 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
1248 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
1249 #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
1250 ac->script_ctx = current_sctx;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
1251 ac->script_ctx.sc_lnum += SOURCING_LNUM;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 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
1254 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 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
1256 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
1257 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 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
1259 *prev_ac = ac;
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1260 ac->once = once;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 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
1266 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
1267 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 * 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
1271 * 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
1272 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 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
1275 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
1276 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
1277 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
1278 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 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
1280 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
1281 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
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 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
1284 *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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 * 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
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 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
1290 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
1291 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
1292
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 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
1294 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 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
1296 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 * 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
1301 * 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
1302 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 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
1304 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
1305 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
1306
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 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
1308
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 * 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
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 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
1313 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
1314 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
1315 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
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 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
1318 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
1319 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
1320 *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
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 #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
1323 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
1324 #else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 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
1326 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328
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 * ":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
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 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 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
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 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 * 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
1345 * 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
1346 * 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
1347 * 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
1348 * 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
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 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
1351 {
16847
f8e28c6ae8ab patch 8.1.1425: win_execute() does not set window pointers properly
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1352 if (buf->b_ml.ml_mfp != NULL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 // 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
1355 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
1356 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
1357
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 // 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
1359 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
1360
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 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
1362 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 // 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
1364 // 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
1365 // buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 // 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
1370 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
1371
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 // 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
1373 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 * 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
1383 * 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
1384 * 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
1385 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 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
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 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
1390 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 *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
1392 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
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 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
1395 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 * 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
1399 * 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
1400 * 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
1401 * 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
1402 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 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
1405 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
1406 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
1407 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 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
1409 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
1410 #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
1411 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
1412 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 // 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
1415 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
1416 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
1417 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 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
1419 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
1420 break;
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 // 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
1423 // 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
1424 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
1425 {
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1426 aucmd_win = win_alloc_popup_win();
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 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
1428 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
1429 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 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
1431 // 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
1432 // 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
1433 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
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 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
1436 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
1437 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
1438 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
1439 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 // 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
1441 // 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
1442 // "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
1443 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
1444 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
1445 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 else
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 // 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
1449 // 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
1450 // 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
1451 // 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
1452 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
1453 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
1454
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1455 win_init_popup_win(aucmd_win, buf);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1456
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 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
1458 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
1459
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 // 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
1461 // 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
1462 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
1463 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
1464 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
1465 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
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 #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
1468 // 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
1469 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
1470 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
1471 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 (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
1474 (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
1475 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
1476 #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
1477 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
1478 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 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
1480 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
1481 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 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
1483 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
1484 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
1485 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 * 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
1489 * 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
1490 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 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
1493 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
1494 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 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
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 (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
1498 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 --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
1500 // 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
1501 // 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
1502 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
1503 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
1504 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 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
1506 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
1507
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 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
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 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
1511 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 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
1513 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
1514 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
1515 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 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
1520
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 // 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
1522 (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
1523 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
1524 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
1525 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
1526
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 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
1528 // 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
1529 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
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_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
1532 (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
1533 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
1534
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 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
1536 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
1537 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 // 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
1539 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
1540 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
1541 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
1542 #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
1543 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
1544 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
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 = 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
1547
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 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
1549 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
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 // 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
1552 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
1553 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
1554 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 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
1556 #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
1557 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
1558 #endif
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 #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
1561 // 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
1562 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
1563 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
1564 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
1565 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 else
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 // 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
1570 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
1571 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 // 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
1573 // 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
1574 // valid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 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
1576 && 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
1577 && 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
1578 && 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
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 # 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
1581 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
1582 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
1583 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 --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
1585 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
1586 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
1587 ++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
1588 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 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
1591 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
1592 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
1593 prevwin = aco->save_prevwin;
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1594 // In case the autocommand moves the cursor to a position that
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18450
diff changeset
1595 // does not exist in curbuf.
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 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
1602
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 * 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
1605 * 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
1606 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 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
1609 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
1610 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
1611 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
1612 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
1613 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
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 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
1616 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
1617 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618
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 * 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
1621 * 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
1622 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 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
1625 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
1626 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
1627 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
1628 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
1629 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
1630 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
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 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
1633 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
1634 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635
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 * 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
1638 * 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
1639 * 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
1640 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 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
1644 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
1645 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
1646 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
1647 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
1648 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
1649 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
1650 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 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
1652
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_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 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
1655 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
1656 #endif
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 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
1659 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
1660 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
1661 #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
1662 && aborting()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 #endif
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 *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
1666 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 * 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
1671 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
1672 static int
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 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
1674 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 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
1676 ? 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 * 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
1681 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 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
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 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
1686
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 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
1688 && 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
1689 && 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
1690 && typebuf.tb_len == 0
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1691 && !ins_compl_active())
15634
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 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
1694 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
1695 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
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 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
1698 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 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
1705 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 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
1707 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 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
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 (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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 * 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
1720 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 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
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 (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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 * 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
1729 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 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
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 (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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 * 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
1738 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 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
1741 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 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
1743 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 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
1750 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 * 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
1756 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 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
1759 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 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
1761 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 #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
1764 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 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
1769 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 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
1771 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773
16268
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1774 #if defined(FEAT_EVAL) || defined(PROTO)
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1775 /*
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1776 * Return TRUE when there is a CompleteChanged autocommand defined.
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1777 */
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1778 int
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1779 has_completechanged(void)
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1780 {
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1781 return (first_autopat[(int)EVENT_COMPLETECHANGED] != NULL);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1782 }
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1783 #endif
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1784
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 * 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
1787 * 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
1788 */
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 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
1791 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
1792 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
1793 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
1794 // 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
1795 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
1796 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
1797 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
1798 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
1799 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 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
1801 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
1802 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
1803 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
1804 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
1805 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
1806 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
1807 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
1808 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
1809 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
1810 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
1811 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
1812 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
1813 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
1814 #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
1815 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
1816 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
1817 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
1818 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
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 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
1821 #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
1822 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
1823 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 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
1825 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
1826 int save_KeyTyped = KeyTyped;
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1827 ESTACK_CHECK_DECLARATION
15634
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 * 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
1831 * 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
1832 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 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
1834 || 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
1835 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
1836
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 * 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
1839 * 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
1840 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 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
1842 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
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 #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
1845 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 * 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
1847 * 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
1848 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 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
1850 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
1851 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852
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 * 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
1855 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 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
1857 || 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
1858 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
1859
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 * 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
1862 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 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
1864 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
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 * 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
1868 * 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
1869 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 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
1871 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 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
1873 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
1874 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 * 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
1878 * ":ball".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 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
1881 && (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
1882 || (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
1883 && (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
1884 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
1885
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 * 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
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 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
1890 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
1891 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
1892 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
1893 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
1894 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
1895 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
1896 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 * 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
1900 * 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
1901 * invalid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 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
1904 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 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
1906 || 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
1907 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
1908 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
1909 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
1910 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
1911 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
1912 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 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
1914 }
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 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
1917 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
1918 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
1919 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
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 * 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
1923 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 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
1925 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
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 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
1928
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 * 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
1931 * 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
1932 * "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
1933 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 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
1935 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 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
1937 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
1938 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 #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
1941 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
1942 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
1943 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 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
1946 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
1947 else
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 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
1950 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
1951 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
1952 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 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
1955 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
1956 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
1957 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 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
1961 // 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
1962 // 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
1963 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
1964 || 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
1965 || 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
1966 || 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
1967 || 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
1968 || 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
1969 || 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
1970 || 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
1971 || 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
1972 || 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
1973 || 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
1974 || 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
1975 || 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
1976 || 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
1977 || 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
1978 || 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
1979 || 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
1980 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 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
1982 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
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 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 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
1986 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 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
1988 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 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
1990 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
1991 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
1992 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 #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
1995 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 * 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
1997 * 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
1998 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 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
2000 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
2001 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
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 #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
2005 // 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
2006 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
2007 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
2008 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
2009 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 * 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
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 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
2015
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 // 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
2018 ++RedrawingDisabled;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2019
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2020 // name and lnum are filled in later
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2021 estack_push(ETYPE_AUCMD, NULL, 0);
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
2022 ESTACK_CHECK_SETUP
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 #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
2025 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
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 # 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
2028 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
2029 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
2030 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 // 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
2033 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
2034 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 * 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
2038 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 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
2040 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 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
2042 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
2043 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 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
2045 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
2046 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2047 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
2048 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 * 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
2052 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2053 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
2054 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
2055 ++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
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 // 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
2058 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
2059 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
2060
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 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
2062
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 // 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
2064 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
2065 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
2066 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
2067 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
2068 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
2069 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
2070 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
2071 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
2072 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
2073 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
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 // 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
2076 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
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 // 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
2079 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
2080 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
2081
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 #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
2083 // 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
2084 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
2085 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
2086 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 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
2088 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
2089 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 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
2092 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 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
2094 // 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
2095 // 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
2096 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
2097 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
2098 ap->last = TRUE;
16401
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2099
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2100 // make sure cursor and topline are valid
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2101 check_lnums(TRUE);
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2102
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 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
2104 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
16401
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2105
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2106 // restore cursor and topline, unless they were changed
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2107 reset_lnums();
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2108
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 #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
2110 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
2111 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 (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
2113 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
2114 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 // 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
2117 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
2118 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
2119 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 --RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 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
2123 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
2124 autocmd_nested = save_autocmd_nested;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2125 vim_free(SOURCING_NAME);
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
2126 ESTACK_CHECK_NOW
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2127 estack_pop();
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 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
2129 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
2130 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
2131 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
2132 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
2133 #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
2134 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
2135 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
2136 # 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
2137 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
2138 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
2139 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 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
2142 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
2143 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
2144 --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
2145
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 * 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
2148 * 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
2149 * 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
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 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
2152 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 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
2154 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
2155 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
2156 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
2157 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
2158 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 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
2160 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
2161 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
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 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
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 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
2166 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
2167 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
2168 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 * 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
2173 * 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
2174 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 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
2176 && (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
2177 || 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
2178 || 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
2179 || 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
2180 || 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
2181 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 #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
2183 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
2184 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
2185 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 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
2190
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 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
2192 // 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
2193 // 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
2194 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
2195 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
2196
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 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
2198 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
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 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
2201 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 # 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
2204 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
2205 # endif
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 * 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
2209 * 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
2210 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 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
2213 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 # 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
2215 // 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
2216 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
2217 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
2218 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 ++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
2220 }
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 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 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
2224 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 --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
2226
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 # 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
2228 // 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
2229 // 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
2230 // 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
2231 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
2232 && 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
2233 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
2234 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 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
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 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
2241 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2242
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 * 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
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 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
2247 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
2248 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
2249 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
2250 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2251 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
2252 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
2253 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
2254 char *s;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2255 char_u **sourcing_namep = &SOURCING_NAME;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2257 VIM_CLEAR(*sourcing_namep);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258
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 (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
2260 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 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
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 // 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
2264 // 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
2265 // 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
2266 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
2267 && (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
2268 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 // 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
2270 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
2271 ? (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
2272 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
2273 : 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
2274 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 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
2276 s = _("%s Autocommands for \"%s\"");
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2277 *sourcing_namep = alloc(STRLEN(s)
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16401
diff changeset
2278 + STRLEN(name) + ap->patlen + 1);
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2279 if (*sourcing_namep != NULL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2281 sprintf((char *)*sourcing_namep, s,
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 (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
2283 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
2284 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 verbose_enter();
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18757
diff changeset
2286 smsg(_("Executing %s"), *sourcing_namep);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 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
2288 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 }
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 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
2292 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
2293 // 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
2294 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
2295 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
2296 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
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 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
2299 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
2300 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 }
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 (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
2303 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 * 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
2309 * 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
2310 * 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
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 char_u *
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 16906
diff changeset
2313 getnextac(int c UNUSED, void *cookie, int indent UNUSED, int do_concat UNUSED)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 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
2316 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
2317 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
2318
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 // 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
2320 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
2321 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
2322
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 // 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
2324 for (;;)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 // 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
2327 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
2328 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
2329 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
2330 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 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
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 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
2334 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 // 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
2337 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
2338 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
2339 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 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
2341 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
2342 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
2343 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
2344 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 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
2348
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 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
2350 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 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
2352 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
2353 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
2354 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
2355 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 retval = vim_strsave(ac->cmd);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2357 // Remove one-shot ("once") autocmd in anticipation of its execution.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2358 if (ac->once)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2359 au_del_cmd(ac);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 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
2361 #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
2362 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
2363 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 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
2365 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
2366 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 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
2368 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
2369 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370
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 * 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
2373 * 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
2374 * 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
2375 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 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
2378 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 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
2380 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
2381 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
2382 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
2383
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 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
2385 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
2386 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
2387
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 #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
2389 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 * 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
2391 * 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
2392 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 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
2394 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
2395 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
2396 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
2397 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398
19888
435726a03481 patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents: 19199
diff changeset
2399 FOR_ALL_AUTOCMD_PATTERNS(event, ap)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 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
2401 && (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
2402 ? 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
2403 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
2404 : 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
2405 ))
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 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
2408 break;
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 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
2412 #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
2413 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
2414 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 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
2417 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 * 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
2421 * names.
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 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
2424 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
2425 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 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
2427 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
2428 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
2429 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
2430 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
2431 // 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
2432 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
2433 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
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 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
2437
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 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
2439 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
2440 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
2441 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
2442 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
2443 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 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
2445 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
2446
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 // 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
2448 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
2449 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
2450 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
2451 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
2452 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
2453 // 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
2454 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
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 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
2457 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
2458 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 // 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
2461 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
2462 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
2463 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
2464 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
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 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
2467 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
2468 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
2469 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
2470 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 // 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
2474 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
2475 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
2476 arg++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 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
2478 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
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 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
2481 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
2482 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 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
2484 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
2485 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 * 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
2489 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 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
2491 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
2492 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 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
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 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
2496 || 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
2497 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
2498 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
2499 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 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
2501 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 #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
2505 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 * 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
2507 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 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
2510 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 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
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 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
2514 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515
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 * 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
2518 * 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
2519 * 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
2520 * 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
2521 * 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
2522 * 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
2523 * 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
2524 * 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
2525 * 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
2526 * 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
2527 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 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
2530 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 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
2532 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
2533 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
2534 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
2535 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
2536 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
2537 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
2538 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
2539 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
2540
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 // 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
2542 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
2543 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
2544 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
2545 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
2546 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
2547 *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
2548
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 // 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
2550 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
2551 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
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 // 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
2554 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
2555 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
2556 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 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
2560 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 // "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
2562 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
2563 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
2564 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 // 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
2567 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
2568 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
2569 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
2570 *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
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 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
2574
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 // 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
2576 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
2577
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 // 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
2579 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
2580 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
2581
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 // 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
2583 // 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
2584 // 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
2585 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
2586 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
2587 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
2588
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 // 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
2590 // 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
2591 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
2592 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
2593
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 // 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
2595 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
2596 // 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
2597 // 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
2598 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
2599 && (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
2600 && (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
2601 || (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
2602 ? 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
2603 : 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
2604 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 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
2606 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 theend:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 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
2611 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
2612 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 #endif