annotate src/autocmd.c @ 16825:ce04ebdf26b8 v8.1.1414

patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts commit https://github.com/vim/vim/commit/c799fe206e61f2e2c1231bc46cbe4bb354f3da69 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 28 23:08:19 2019 +0200 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts Problem: Alloc() returning "char_u *" causes a lot of type casts. Solution: Have it return "void *". (Mike Williams) Define ALLOC_ONE() to check the simple allocations.
author Bram Moolenaar <Bram@vim.org>
date Tue, 28 May 2019 23:15:10 +0200
parents eda4d65f232c
children f8e28c6ae8ab
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},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 {"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
118 {"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
119 {"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
120 {"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
121 {"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
122 {"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
123 {"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
124 {"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
125 {"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
126 {"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
127 {"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
128 {"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
129 {"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
130 {"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
131 {"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
132 {"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
133 {"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
134 {"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
135 {"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
136 {"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
137 {"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
138 {"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
139 {"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
140 {"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
141 {"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
142 {"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
143 {"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
144 {"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
145 {"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
146 {"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
147 {"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
148 {"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
149 {"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
150 {"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
151 {"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
152 {"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
153 {"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
154 {"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
155 {"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
156 {"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
157 {"RemoteReply", EVENT_REMOTEREPLY},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 {"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
159 {"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
160 {"ShellFilterPost", EVENT_SHELLFILTERPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 {"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
162 {"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
163 {"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
164 {"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
165 {"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
166 {"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
167 {"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
168 {"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
169 {"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
170 {"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
171 {"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
172 {"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
173 {"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
174 {"TerminalOpen", EVENT_TERMINALOPEN},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 {"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
176 {"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
177 {"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
178 {"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
179 {"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
180 {"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
181 {"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
182 {"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
183 {"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
184 {"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
185 {"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
186 {"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
187 {"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
188 {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
189 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 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
192 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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
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 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 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
202 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 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
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 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 #define AUGROUP_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
212 #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
213 #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
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 * 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
217 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 typedef struct AutoPatCmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 // buf is deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 struct AutoPatCmd *next; // chain of active apc-s for auto-invalidation
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 } AutoPatCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 * 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
236 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 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
238 #define AUGROUP_NAME(i) (((char_u **)augroups.ga_data)[i])
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 /* use get_deleted_augroup() to get this */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 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
241
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 * Set by the apply_autocmds_group function if the given event is equal to
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * EVENT_FILETYPE. Used by the readfile function in order to determine if
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 * EVENT_BUFREADPOST triggered the EVENT_FILETYPE.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 * Relying on this value requires one to reset it prior calling
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 * 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
249 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 int au_did_filetype INIT(= FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 * 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
254 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 static int 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
256
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 static int au_need_clean = FALSE; /* need to delete marked patterns */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258
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 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
260 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
261 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
262 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
263 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
264 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
265
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 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
267 static int last_group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 static int autocmd_blocked = 0; /* block all autocmds */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 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
271 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
272 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 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
274 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
275 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 * 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
280 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 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
282 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
283 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 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
285
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 // 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
287 // 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
288 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
289 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 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
291 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 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
294 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
295 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 if (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
297 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 if (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
299 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 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
301 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
302 else
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_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
304 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
305 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 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
307 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
308 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
309 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
310 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
311 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 }
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_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
314 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
315
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 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
317 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 if (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
319 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 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
321 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
322 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
323 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
324 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 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
326 #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
327 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
328 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
329 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (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
331 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 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
333 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 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
335 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
336 return;
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 * 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
344 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 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
346 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
347 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 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
349 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
350 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 * 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
355 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 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
357 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
358 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 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
360
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 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
362 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
363 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
364 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
366 // 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
367 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
368 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
369 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
370 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
371 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
372
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 * 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
375 * 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
376 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 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
378 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
379 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 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
381 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
382 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
383
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 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
385 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 // 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
388 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
389 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
390 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 // 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
392 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
393 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
394 {
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
395 int has_cmd = FALSE;
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
396
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 // 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
398 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
399 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
400 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 // 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
402 // 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
403 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
404 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 *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
406 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
407 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
408 }
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
409 else
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
410 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
411 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
412 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
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 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
415
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
416 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
417 // 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
418 // 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
419 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
420
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 // 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
422 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
423 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 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
425 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 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
427 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
428 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 // 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
430 // 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
431 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
432 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 *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
434 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
435 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
436 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 * 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
447 * autocmds.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 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
451 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 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
453 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
454 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
455
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 // 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
457 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
458 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
459 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
460
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 // 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
462 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
463 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
464 // 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
465 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 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
467 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 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
469 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
470 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 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
473 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
474 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 * 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
482 * 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
483 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 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
485 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
486 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 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
488
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 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
490 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
491 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 // 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
493 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
494 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
495 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 if (i == 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
497 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
498
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 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
500 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
501 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
502 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
503 ++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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 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
510 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
511 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 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
513
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 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
515 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
516 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
517 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
518 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
519 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 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
522 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
523 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
524
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 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
526 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
527 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 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
530 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 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
533 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
534 break;
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 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
538 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
539 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
540 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 * 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
547 * 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
548 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 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
550 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
551 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 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
553
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 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
555 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
556 && 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
557 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
558 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 * 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
563 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 * ":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
572 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 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
575 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 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
579 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 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
581 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
582 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 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
584 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 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
586 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
587 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
588 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 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
591 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
592 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 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
594 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 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
597 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 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
599 {
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((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
601 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
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 }
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_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
605 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 #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
610 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 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
612 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 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
614 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
615
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 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
617 ++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
618 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
619
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 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
621 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 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
623 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
624 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
625 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 #endif
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 /*
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 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
632 * 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
633 * 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
634 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 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
636 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
637 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 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
639 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
640 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
641
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 // 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
643 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
644 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 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
646 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 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
648 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
649 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 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
652 ++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 *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
654 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
655 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
656 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 * 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
661 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 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
664 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 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
666
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 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
668 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
669 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
670 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 * 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
675 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 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
677 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
678 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
679 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
680 {
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 *pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 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
683
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 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
685 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 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
687 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 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
689 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
690 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 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
692 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 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
696 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 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
698 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 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
700 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
701 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 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
703 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 return pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * Return 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
712 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 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
714 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
715 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 char_u *p = p_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 while (*p != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 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
722 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
723 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 * Return OK 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
731 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 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
734 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 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
736
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 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
738 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 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
740 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 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
742 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
743 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 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
746 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 # if 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 * 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
756 * 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
757 * 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
758 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 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
761 {
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 *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
763 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
764
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 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
766 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
767 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 new_ei = vim_strnsave(p_ei, (int)(STRLEN(p_ei) + STRLEN(what)));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 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
770 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 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
772 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
773 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 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
776 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
777 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 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
785 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 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
787 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 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
789 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
790 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
791 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 # endif /* FEAT_SYN_HL */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 * 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
797 * 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
798 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 * :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
800 * 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
801 * 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
802 * 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
803 * :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
804 * <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
805 * :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
806 * <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 * :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
808 * :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
809 * <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
810 * <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
811 * :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
812 * <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
813 * :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
814 * <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
815 * :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
816 * group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 * 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
819 * 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
820 * :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
821 * :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
822 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 * :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
824 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 * 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
826 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 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
829 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 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
831 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
832 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
833 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
834 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
835 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
836 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
837 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
838 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
839 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
840
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 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
842 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 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
844 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
845 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 else
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 * 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
850 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 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
852 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
853 return;
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 * 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
858 * 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
859 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 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
861 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
862 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 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
865 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
866 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 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
868 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
869 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 else
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 * 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
874 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 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
876 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
877 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 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
879 *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
880
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 // 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
882 // 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
883 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
884 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 #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
886 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
887
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 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
889 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 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
891 #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
892 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
893 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 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
895 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 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
899 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
900 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
901 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
902 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
903 // 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
904 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
905 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
906 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
907 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
908 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
909 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
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
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
912 // 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
913 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
914 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
915 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
916 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
917 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
918 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
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
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
921 // 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
922 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
923 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
924 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
925 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
926 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
927 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
928 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
929 }
15634
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 * 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
934 * 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
935 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 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
937 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 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
939 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
940 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 * 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
947 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 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
949 // 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
950 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 * 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
954 */
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_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
956 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
957 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
958 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 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
960 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
961 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
962 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
963 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 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
968 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
969 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
970 break;
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 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
974 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
975 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 * 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
980 * 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
981 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 * 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
983 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985 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
986 {
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 *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
988 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
989 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
990 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
991
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 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
993 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 if (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
995 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 group_name = vim_strnsave(arg, (int)(p - arg));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 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
998 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
999 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
1000 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
1001 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
1002 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 *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
1004 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
1005 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 * 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
1011 * 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
1012 * 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
1013 * 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
1014 * 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
1015 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 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
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 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
1027 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
1028 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
1029 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
1030 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
1031 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
1032 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
1033 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
1034 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
1035 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
1036 int buflocal_nr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 char_u buflocal_pat[25]; /* for "<buffer=X>" */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 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
1040 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
1041 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 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
1043 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 * 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
1047 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 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
1049 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 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
1053 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 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
1055 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
1056 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 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
1058 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 * 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
1064 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 * 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
1069 * 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
1070 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 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
1072 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
1073 || (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
1074 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 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
1076 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
1077 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
1078 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
1079 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 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
1081 continue;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 * 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
1086 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 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
1088 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
1089
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 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
1091 && 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
1092 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 // "<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
1094 // 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
1095 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
1096 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
1097 // "<buffer>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 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
1099 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
1100 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 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
1102 // "<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
1103 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
1104 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
1105 // "<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
1106 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 // 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
1113 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
1114 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
1115 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 * 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
1120 * 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
1121 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 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
1123 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
1124 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 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
1126 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
1127 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 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
1129 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 /* Accept a pattern when:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 /* refuse to add buffer-local ap if buffer number is invalid */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 ac->script_ctx.sc_lnum += sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 {
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1352 if (buf->b_ml.ml_mfp != NULL && !bt_popup(buf))
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;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 // In case the autocommand move the cursor to a position that that
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 // not exist in curbuf.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 {
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1615 if (bt_popup(buf))
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1616 return 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
1617 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
1618 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 * 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
1623 * 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
1624 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 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
1627 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
1628 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
1629 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
1630 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
1631 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
1632 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
1633 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 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
1635 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 * 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
1640 * 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
1641 * 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
1642 * 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
1643 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 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
1646 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
1647 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
1648 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
1649 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
1650 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
1651 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
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 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
1654
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 #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
1656 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
1657 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
1658 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 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
1661 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
1662 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
1663 #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
1664 && aborting()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 )
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 *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
1668 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 * 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
1673 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 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
1676 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 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
1678 ? 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
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
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 * 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
1683 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 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
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 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
1688
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 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
1690 && 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
1691 && 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
1692 && typebuf.tb_len == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 #ifdef FEAT_INS_EXPAND
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 && !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
1695 #endif
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 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 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
1699 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
1700 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
1701 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 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
1703 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 /*
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 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
1710 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 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
1712 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 #if defined(FEAT_CONCEAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 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
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 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
1722 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724
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 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 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
1730 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 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
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
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 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 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
1739 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 * 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
1746 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 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
1749 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 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
1751 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 #endif
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 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
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_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
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_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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 * 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
1765 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 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
1768 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 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
1770 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 * Return TRUE when there is an FuncUndefined autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 has_funcundefined(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 #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
1782 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 * 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
1784 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 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
1787 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 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
1789 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791
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
1792 #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
1793 /*
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1794 * 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
1795 */
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1796 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
1797 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
1798 {
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1799 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
1800 }
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1801 #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
1802
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 * 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
1805 * 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
1806 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 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
1808 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
1809 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
1810 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
1811 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
1812 // 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
1813 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
1814 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
1815 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
1816 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
1817 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 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
1819 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
1820 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
1821 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
1822 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
1823 char_u *save_sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 linenr_T save_sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826 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
1827 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
1828 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
1829 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
1830 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
1831 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
1832 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
1833 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
1834 #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
1835 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
1836 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
1837 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
1838 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
1839 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 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
1841 #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
1842 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
1843 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 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
1845 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
1846 int save_KeyTyped = KeyTyped;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 * 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
1850 * 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
1851 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 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
1853 || 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
1854 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 * 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
1858 * 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
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 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
1861 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
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 #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
1864 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 * 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
1866 * 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
1867 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 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
1869 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
1870 #endif
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 * 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
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 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
1876 || 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
1877 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
1878
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 * 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
1881 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 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
1883 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
1884
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 * 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
1887 * 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
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 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
1890 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 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
1892 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
1893 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 * 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
1897 * ":ball".
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 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
1900 && (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
1901 || (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
1902 && (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
1903 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 * 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
1907 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 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
1909 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
1910 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
1911 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
1912 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
1913 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
1914 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
1915 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
1916
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 * 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
1919 * 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
1920 * invalid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 if (fname_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
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 (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
1925 || 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
1926 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
1927 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
1928 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
1929 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
1930 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
1931 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 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
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 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 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
1936 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
1937 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
1938 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 * 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
1942 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 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
1944 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
1945 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 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
1947
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 * 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
1950 * 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
1951 * "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
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 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
1954 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 if (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
1956 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
1957 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 #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
1960 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
1961 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
1962 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 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
1965 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
1966 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 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
1969 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
1970 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
1971 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 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
1974 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
1975 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
1976 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979 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
1980 // 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
1981 // 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
1982 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
1983 || 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
1984 || 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
1985 || 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
1986 || 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
1987 || 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
1988 || 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
1989 || 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
1990 || 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
1991 || 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
1992 || 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
1993 || 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
1994 || 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
1995 || 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
1996 || 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
1997 || 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
1998 || 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
1999 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 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
2001 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
2002 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 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
2005 }
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 (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
2007 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 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
2009 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
2010 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 #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
2014 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 * 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
2016 * 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
2017 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 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
2019 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
2020 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
2021 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 #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
2024 // 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
2025 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
2026 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
2027 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
2028 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 * 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
2032 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 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
2034
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 // 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
2037 ++RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 save_sourcing_name = sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 sourcing_name = NULL; // don't free this one
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 save_sourcing_lnum = sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 sourcing_lnum = 0; // no line number here
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 #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
2044 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
2045
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 # 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
2047 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
2048 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
2049 # endif
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 // 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
2052 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
2053 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 * 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
2057 */
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 (!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
2059 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 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
2061 #ifdef FEAT_INS_EXPAND
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 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
2063 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 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
2066 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
2067 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 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
2069 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 * 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
2073 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 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
2075 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
2076 ++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
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 // 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
2079 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
2080 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
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 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
2083
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 // 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
2085 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
2086 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
2087 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
2088 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
2089 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
2090 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
2091 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
2092 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
2093 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
2094 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
2095
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 // 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
2097 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
2098 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 // 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
2100 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
2101 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
2102
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 #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
2104 // 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
2105 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
2106 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
2107 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 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
2109 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
2110 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112 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
2113 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 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
2115 // 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
2116 // 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
2117 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
2118 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
2119 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
2120
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2121 // 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
2122 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
2123
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 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
2125 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
2126
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2127 // 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
2128 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
2129
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 #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
2131 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
2132 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 (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
2134 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
2135 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 // 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
2138 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
2139 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
2140 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 --RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 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
2144 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
2145 autocmd_nested = save_autocmd_nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 vim_free(sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 sourcing_name = save_sourcing_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 sourcing_lnum = save_sourcing_lnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 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
2150 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
2151 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
2152 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
2153 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
2154 #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
2155 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
2156 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
2157 # 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
2158 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
2159 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
2160 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 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
2163 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
2164 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
2165 --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
2166
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 * 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
2169 * 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
2170 * 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
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 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
2173 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 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
2175 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
2176 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
2177 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
2178 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
2179 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 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
2181 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
2182 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
2183 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 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
2185 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 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
2187 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
2188 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
2189 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 * 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
2194 * 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
2195 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 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
2197 && (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
2198 || 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
2199 || 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
2200 || 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
2201 || 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
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_TITLE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 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
2205 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
2206 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 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
2208 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 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
2211
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 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
2213 // 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
2214 // 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
2215 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
2216 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
2217
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 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
2219 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
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 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
2222 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 # 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
2225 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
2226 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 * 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
2230 * 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
2231 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2232 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 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
2234 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2235 # 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
2236 // 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
2237 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
2238 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
2239 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2240 ++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
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 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 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
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 --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
2247
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 # 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
2249 // 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
2250 // 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
2251 // 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
2252 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
2253 && 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
2254 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
2255 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2257
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 #if defined(FEAT_EVAL) && (defined(FEAT_XIM) || defined(IME_WITHOUT_XIM)) \
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 || 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
2260 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 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
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 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
2264 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 * 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
2269 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 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
2271 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
2272 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
2273 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
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 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
2276 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
2277 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
2278 char *s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 VIM_CLEAR(sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 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
2283 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 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
2285
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 // 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
2287 // 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
2288 // 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
2289 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
2290 && (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
2291 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 // 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
2293 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
2294 ? (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
2295 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
2296 : 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
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 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
2299 s = _("%s Autocommands for \"%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
2300 sourcing_name = alloc(STRLEN(s)
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16401
diff changeset
2301 + STRLEN(name) + ap->patlen + 1);
15634
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 (sourcing_name != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 sprintf((char *)sourcing_name, s,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 (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
2306 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
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 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
2309 smsg(_("Executing %s"), sourcing_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2313
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 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
2315 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
2316 // 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
2317 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
2318 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
2319 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
2320 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 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
2322 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
2323 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 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
2326 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 * 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
2332 * 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
2333 * 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
2334 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 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
2336 getnextac(int c UNUSED, void *cookie, int indent UNUSED)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 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
2339 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
2340 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
2341
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 // 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
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 // 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
2347 for (;;)
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 // 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
2350 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
2351 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
2352 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
2353 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 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
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 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
2357 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 // 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
2360 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
2361 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
2362 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 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
2364 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
2365 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
2366 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
2367 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
2368 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 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
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 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
2373 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 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
2375 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
2376 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
2377 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
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 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
2380 // 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
2381 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
2382 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
2383 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
2384 #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
2385 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
2386 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 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
2388 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
2389 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 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
2391 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 * Return 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
2396 * 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
2397 * 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
2398 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 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
2401 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 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
2403 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
2404 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
2405 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
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 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
2408 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
2409 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
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 #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
2412 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 * 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
2414 * 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
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 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
2417 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
2418 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
2419 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
2420 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 for (ap = first_autopat[(int)event]; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 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
2424 && (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
2425 ? 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
2426 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
2427 : 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
2428 ))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 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
2431 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 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
2435 #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
2436 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
2437 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 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
2440 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 * 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
2445 * names.
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 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
2448 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
2449 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 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
2451 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
2452 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
2453 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
2454 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
2455 // 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
2456 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
2457 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
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 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
2461
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 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
2463 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
2464 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
2465 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
2466 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
2467 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 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
2469 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
2470
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 // 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
2472 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
2473 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
2474 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
2475 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
2476 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
2477 // 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
2478 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
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 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
2481 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
2482 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 // 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
2485 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
2486 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
2487 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
2488 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
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 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
2491 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
2492 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
2493 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
2494 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
2495 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 // 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
2498 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
2499 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
2500 arg++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 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
2502 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
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 (doautocmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 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
2506 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 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
2508 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
2509 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512 * 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
2513 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 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
2515 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
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 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
2518 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 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
2520 || 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
2521 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
2522 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
2523 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 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
2525 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 #endif // FEAT_CMDL_COMPL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 #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
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 * 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
2532 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 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
2535 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 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
2537
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 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
2539 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 * Return 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
2543 * 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
2544 * 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
2545 * 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
2546 * 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
2547 * 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
2548 * 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
2549 * 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
2550 * 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
2551 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 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
2555 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 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
2557 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
2558 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
2559 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
2560 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
2561 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
2562 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
2563 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
2564 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
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 // 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
2567 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
2568 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
2569 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
2570 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
2571 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
2572 *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
2573
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 // 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
2575 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
2576 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
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 // 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
2579 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
2580 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
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 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 {
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 (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
2585 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 // "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
2587 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
2588 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
2589 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 // 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
2592 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
2593 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
2594 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
2595 *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
2596 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 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
2599
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 // 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
2601 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
2602
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 // 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
2604 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
2605 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
2606
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 // 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
2608 // 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
2609 // 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
2610 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
2611 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
2612 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
2613
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 // 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
2615 // 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
2616 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
2617 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
2618
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 // 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
2620 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
2621 // 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
2622 // 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
2623 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
2624 && (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
2625 && (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
2626 || (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
2627 ? 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
2628 : 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
2629 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2630 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
2631 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 theend:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 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
2636 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
2637 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 #endif