annotate src/autocmd.c @ 16221:331dc836f866 v8.1.1115

patch 8.1.1115: cannot build with older C compiler commit https://github.com/vim/vim/commit/8f4aeb5572d604d1540ee0cb7e721b5f0cc6d612 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 4 15:40:56 2019 +0200 patch 8.1.1115: cannot build with older C compiler Problem: Cannot build with older C compiler. Solution: Move variable declaration to start of block.
author Bram Moolenaar <Bram@vim.org>
date Thu, 04 Apr 2019 15:45:05 +0200
parents 81e6940504e8
children 0f65f2808470
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},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 {"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
116 {"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
117 {"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
118 {"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
119 {"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
120 {"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
121 {"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
122 {"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
123 {"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
124 {"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
125 {"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
126 {"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
127 {"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
128 {"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
129 {"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
130 {"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
131 {"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
132 {"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
133 {"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
134 {"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
135 {"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
136 {"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
137 {"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
138 {"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
139 {"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
140 {"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
141 {"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
142 {"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
143 {"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
144 {"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
145 {"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
146 {"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
147 {"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
148 {"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
149 {"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
150 {"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
151 {"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
152 {"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
153 {"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
154 {"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
155 {"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
156 {"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
157 {"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
158 {"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
159 {"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
160 {"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
161 {"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
162 {"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
163 {"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
164 {"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
165 {"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
166 {"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
167 {"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
168 {"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
169 {"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
170 {"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
171 {"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
172 {"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
173 {"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
174 {"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
175 {"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
176 {"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
177 {"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
178 {"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
179 {"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
180 {"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
181 {"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
182 {"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
183 {"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
184 {"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
185 {"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
186 {"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
187 {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
188 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 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
191 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 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 };
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 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
201 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 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 };
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 #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
211 #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
212 #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
213
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 * 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
216 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 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
218 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 // 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
228 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
229 } AutoPatCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 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
232
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 * 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
235 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 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
237 #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
238 /* 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
239 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
240
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 * 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
243 * 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
244 * 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
245 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 * 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
247 * 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
248 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 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
250
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 * The ID of the current group. Group 0 is the default one.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 static int current_augroup = AUGROUP_DEFAULT;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 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
257
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 static char_u *event_nr2name(event_T event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 static int au_get_grouparg(char_u **argp);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
260 static int do_autocmd_event(event_T event, char_u *pat, int once, int nested, char_u *cmd, int forceit, int group);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 static int apply_autocmds_group(event_T event, char_u *fname, char_u *fname_io, int force, int group, buf_T *buf, exarg_T *eap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 static void auto_next_pat(AutoPatCmd *apc, int stop_at_last);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 static int au_find_group(char_u *name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 static event_T last_event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 static int last_group;
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 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
268
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 get_deleted_augroup(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 if (deleted_augroup == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 deleted_augroup = (char_u *)_("--Deleted--");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 return deleted_augroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 * Show the autocommands for one AutoPat.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 show_autocmd(AutoPat *ap, event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 // Check for "got_int" (here and at various places below), which is set
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 // when "q" has been hit for the "--more--" prompt
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 if (ap->pat == NULL) // pattern has been removed
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 if (event != last_event || ap->group != last_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 if (ap->group != AUGROUP_DEFAULT)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 if (AUGROUP_NAME(ap->group) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 msg_puts_attr((char *)get_deleted_augroup(), HL_ATTR(HLF_E));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 msg_puts_attr((char *)AUGROUP_NAME(ap->group), HL_ATTR(HLF_T));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 msg_puts(" ");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 msg_puts_attr((char *)event_nr2name(event), HL_ATTR(HLF_T));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 last_event = event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 last_group = ap->group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 msg_col = 4;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 msg_outtrans(ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 for (ac = ap->cmds; ac != NULL; ac = ac->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 if (ac->cmd != NULL) // skip removed commands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 if (msg_col >= 14)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 msg_col = 14;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 msg_outtrans(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 if (p_verbose > 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 last_set_msg(ac->script_ctx);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 if (ac->next != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 msg_putchar('\n');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 * Mark an autocommand pattern for deletion.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 au_remove_pat(AutoPat *ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 VIM_CLEAR(ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 ap->buflocal_nr = -1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 au_need_clean = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 * Mark all commands for a pattern for deletion.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 au_remove_cmds(AutoPat *ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 for (ac = ap->cmds; ac != NULL; ac = ac->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 VIM_CLEAR(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 au_need_clean = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
365 // Delete one command from an autocmd pattern.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
366 static void au_del_cmd(AutoCmd *ac)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
367 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
368 VIM_CLEAR(ac->cmd);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
369 au_need_clean = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
370 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
371
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 * Cleanup autocommands and patterns that have been deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 * This is only done when not executing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 au_cleanup(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 AutoPat *ap, **prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 AutoCmd *ac, **prev_ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 if (autocmd_busy || !au_need_clean)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 // loop over all events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 // loop over all autocommand patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 prev_ap = &(first_autopat[(int)event]);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 for (ap = *prev_ap; ap != NULL; ap = *prev_ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
394 int has_cmd = FALSE;
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
395
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 // loop over all commands for this pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 prev_ac = &(ap->cmds);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 for (ac = *prev_ac; ac != NULL; ac = *prev_ac)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 // remove the command if the pattern is to be deleted or when
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 // the command has been marked for deletion
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 if (ap->pat == NULL || ac->cmd == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 *prev_ac = ac->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 vim_free(ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 vim_free(ac);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 }
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
408 else
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
409 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
410 has_cmd = TRUE;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 prev_ac = &(ac->next);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
412 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
413 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
414
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
415 if (ap->pat != NULL && !has_cmd)
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
416 // Pattern was not marked for deletion, but all of its
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
417 // commands were. So mark the pattern for deletion.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
418 au_remove_pat(ap);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 // remove the pattern if it has been marked for deletion
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 if (ap->pat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 if (ap->next == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 if (prev_ap == &(first_autopat[(int)event]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 last_autopat[(int)event] = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 // this depends on the "next" field being the first in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 // the struct
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 last_autopat[(int)event] = (AutoPat *)prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 *prev_ap = ap->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 vim_regfree(ap->reg_prog);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 vim_free(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 prev_ap = &(ap->next);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 au_need_clean = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 * Called when buffer is freed, to remove/invalidate related buffer-local
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 * autocmds.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 aubuflocal_remove(buf_T *buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 AutoPatCmd *apc;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 // invalidate currently executing autocommands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 for (apc = active_apc_list; apc; apc = apc->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 if (buf->b_fnum == apc->arg_bufnr)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 apc->arg_bufnr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 // invalidate buflocals looping through events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 // loop over all autocommand patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 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
465 if (ap->buflocal_nr == buf->b_fnum)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 au_remove_pat(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 if (p_verbose >= 6)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 verbose_enter();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 smsg(_("auto-removing autocommand: %s <buffer=%d>"),
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 event_nr2name(event), buf->b_fnum);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 verbose_leave();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 au_cleanup();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 * Add an autocmd group name.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 * Return its ID. Returns AUGROUP_ERROR (< 0) for error.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 au_new_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 i = au_find_group(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 if (i == AUGROUP_ERROR) // the group doesn't exist yet, add it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 // First try using a free entry.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 if (AUGROUP_NAME(i) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 if (i == augroups.ga_len && ga_grow(&augroups, 1) == FAIL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 AUGROUP_NAME(i) = vim_strsave(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 if (AUGROUP_NAME(i) == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 if (i == augroups.ga_len)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 ++augroups.ga_len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 return i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 au_del_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 i = au_find_group(name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 if (i == AUGROUP_ERROR) // the group doesn't exist
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 semsg(_("E367: No such group: \"%s\""), name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 else if (i == current_augroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 emsg(_("E936: Cannot delete the current group"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 int in_use = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 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
528 if (ap->group == i && ap->pat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 give_warning((char_u *)_("W19: Deleting augroup that is still in use"), TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 in_use = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 event = NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 vim_free(AUGROUP_NAME(i));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 if (in_use)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 AUGROUP_NAME(i) = get_deleted_augroup();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 AUGROUP_NAME(i) = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 * Find the ID of an autocmd group name.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 * Return its ID. Returns AUGROUP_ERROR (< 0) for error.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 au_find_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 if (AUGROUP_NAME(i) != NULL && AUGROUP_NAME(i) != get_deleted_augroup()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 && STRCMP(AUGROUP_NAME(i), name) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 return i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 * Return TRUE if augroup "name" exists.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 au_has_group(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 return au_find_group(name) != AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 * ":augroup {name}".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 do_augroup(char_u *arg, int del_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 if (del_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (*arg == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 emsg(_(e_argreq));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 au_del_group(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 else if (STRICMP(arg, "end") == 0) // ":aug end": back to group 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 current_augroup = AUGROUP_DEFAULT;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 else if (*arg) // ":aug xxx": switch to group xxx
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 i = au_new_group(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 if (i != AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 current_augroup = i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 else // ":aug": list the group names
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 msg_start();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 if (AUGROUP_NAME(i) != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 msg_puts((char *)AUGROUP_NAME(i));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 msg_puts(" ");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 msg_clr_eos();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 msg_end();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 #if defined(EXITFREE) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 free_all_autocmds(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 char_u *s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 for (current_augroup = -1; current_augroup < augroups.ga_len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 ++current_augroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 do_autocmd((char_u *)"", TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 for (i = 0; i < augroups.ga_len; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 s = ((char_u **)(augroups.ga_data))[i];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 if (s != get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 vim_free(s);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 ga_clear(&augroups);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 * Return the event number for event name "start".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 * Return NUM_EVENTS if the event name was not found.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 * Return a pointer to the next event name in "end".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 static event_T
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 event_name2nr(char_u *start, char_u **end)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 int len;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 // the event name ends with end of line, '|', a blank or a comma
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 for (p = start; *p && !VIM_ISWHITE(*p) && *p != ',' && *p != '|'; ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 for (i = 0; event_names[i].name != NULL; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 len = (int)STRLEN(event_names[i].name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 *end = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 if (event_names[i].name == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 return NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 return event_names[i].event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 * Return the name for event "event".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 event_nr2name(event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 int i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 for (i = 0; event_names[i].name != NULL; ++i)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 if (event_names[i].event == event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 return (char_u *)event_names[i].name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 return (char_u *)"Unknown";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 * Scan over the events. "*" stands for all events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 static char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 find_end_event(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 char_u *arg,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 int have_group) // TRUE when group name was found
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 char_u *pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 if (*arg == '*')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 if (arg[1] && !VIM_ISWHITE(arg[1]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 semsg(_("E215: Illegal character after *: %s"), arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 pat = arg + 1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 for (pat = arg; *pat && *pat != '|' && !VIM_ISWHITE(*pat); pat = p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 if ((int)event_name2nr(pat, &p) >= (int)NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 if (have_group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 semsg(_("E216: No such event: %s"), pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 semsg(_("E216: No such group or event: %s"), pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 return pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 * Return TRUE if "event" is included in 'eventignore'.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 event_ignored(event_T event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 char_u *p = p_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 while (*p != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 if (event_name2nr(p, &p) == event)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 * Return OK when the contents of p_ei is valid, FAIL otherwise.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 check_ei(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 char_u *p = p_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 while (*p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 if (STRNICMP(p, "all", 3) == 0 && (p[3] == NUL || p[3] == ','))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 p += 3;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 else if (event_name2nr(p, &p) == NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 return OK;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 # if defined(FEAT_SYN_HL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 * Add "what" to 'eventignore' to skip loading syntax highlighting for every
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 * buffer loaded into the window. "what" must start with a comma.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 * Returns the old value of 'eventignore' in allocated memory.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 au_event_disable(char *what)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 char_u *new_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 char_u *save_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 save_ei = vim_strsave(p_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 if (save_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 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
768 if (new_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 if (*what == ',' && *p_ei == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 STRCPY(new_ei, what + 1);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 STRCAT(new_ei, what);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 set_string_option_direct((char_u *)"ei", -1, new_ei,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 OPT_FREE, SID_NONE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 vim_free(new_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 return save_ei;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 au_event_restore(char_u *old_ei)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 if (old_ei != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 set_string_option_direct((char_u *)"ei", -1, old_ei,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 OPT_FREE, SID_NONE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 vim_free(old_ei);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 # 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
793
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 * do_autocmd() -- implements the :autocmd command. Can be used in the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 * following ways:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 * :autocmd <event> <pat> <cmd> Add <cmd> to the list of commands that
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 * will be automatically executed for <event>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 * when editing a file matching <pat>, in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 * the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 * :autocmd <event> <pat> Show the autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 * <event> and <pat>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 * :autocmd <event> Show the autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 * <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 * :autocmd Show all autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 * :autocmd! <event> <pat> <cmd> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 * <event> and <pat>, and add the command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 * <cmd>, for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 * :autocmd! <event> <pat> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 * <event> and <pat> for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 * :autocmd! <event> Remove all autocommands associated with
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 * <event> for the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 * :autocmd! Remove ALL autocommands for the current
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 * group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 * Multiple events and patterns may be given separated by commas. Here are
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 * some examples:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 * :autocmd bufread,bufenter *.c,*.h set tw=0 smartindent noic
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 * :autocmd bufleave * set tw=79 nosmartindent ic infercase
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 * :autocmd * *.c show all autocommands for *.c files.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 * Mostly a {group} argument can optionally appear before <event>.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 do_autocmd(char_u *arg_in, int forceit)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 char_u *arg = arg_in;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 char_u *pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 char_u *envpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 char_u *cmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 int need_free = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 int nested = FALSE;
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
836 int once = FALSE;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 int group;
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
838 int i;
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 if (*arg == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 arg = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 group = AUGROUP_ALL; // no argument, use all groups
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 * Check for a legal group name. If not, use AUGROUP_ALL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 group = au_get_grouparg(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 if (arg == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 * Scan over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 * If we find an illegal name, return here, don't do anything.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 pat = find_end_event(arg, group != AUGROUP_ALL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 if (pat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 pat = skipwhite(pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 if (*pat == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 pat = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 cmd = (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 * Scan over the pattern. Put a NUL at the end.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 cmd = pat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 while (*cmd && (!VIM_ISWHITE(*cmd) || cmd[-1] == '\\'))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 cmd++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 if (*cmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 *cmd++ = NUL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 // Expand environment variables in the pattern. Set 'shellslash', we
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 // want forward slashes here.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 if (vim_strchr(pat, '$') != NULL || vim_strchr(pat, '~') != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 int p_ssl_save = p_ssl;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 p_ssl = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 envpat = expand_env_save(pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 p_ssl = p_ssl_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 if (envpat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 pat = envpat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 cmd = skipwhite(cmd);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
898 for (i = 0; i < 2; i++)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
900 if (*cmd != NUL)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
901 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
902 // Check for "++once" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
903 if (STRNCMP(cmd, "++once", 6) == 0 && VIM_ISWHITE(cmd[6]))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
904 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
905 if (once)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
906 semsg(_(e_duparg2), "++once");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
907 once = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
908 cmd = skipwhite(cmd + 6);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
909 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
910
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
911 // Check for "++nested" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
912 if ((STRNCMP(cmd, "++nested", 8) == 0 && VIM_ISWHITE(cmd[8])))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
913 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
914 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
915 semsg(_(e_duparg2), "++nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
916 nested = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
917 cmd = skipwhite(cmd + 8);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
918 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
919
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
920 // Check for the old "nested" flag.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
921 if (STRNCMP(cmd, "nested", 6) == 0 && VIM_ISWHITE(cmd[6]))
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
922 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
923 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
924 semsg(_(e_duparg2), "nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
925 nested = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
926 cmd = skipwhite(cmd + 6);
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
927 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
928 }
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 * Find the start of the commands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 * Expand <sfile> in it.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 if (*cmd != NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 cmd = expand_sfile(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 if (cmd == NULL) // some error
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 need_free = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 * Print header when showing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 if (!forceit && *cmd == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 // Highlight title
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 msg_puts_title(_("\n--- Autocommands ---"));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 * Loop over the events.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 last_event = (event_T)-1; // for listing the event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 last_group = AUGROUP_ERROR; // for listing the group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 if (*arg == '*' || *arg == NUL || *arg == '|')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 if (do_autocmd_event(event, pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
961 once, nested, cmd, forceit, group) == FAIL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 while (*arg && *arg != '|' && !VIM_ISWHITE(*arg))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 if (do_autocmd_event(event_name2nr(arg, &arg), pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
968 once, nested, cmd, forceit, group) == FAIL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 if (need_free)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 vim_free(cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 vim_free(envpat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 * Find the group ID in a ":autocmd" or ":doautocmd" argument.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 * The "argp" argument is advanced to the following argument.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 * Returns the group ID, AUGROUP_ERROR for error (out of memory).
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 au_get_grouparg(char_u **argp)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 char_u *group_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 char_u *arg = *argp;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 int group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 for (p = arg; *p && !VIM_ISWHITE(*p) && *p != '|'; ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 if (p > arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 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
996 if (group_name == NULL) // out of memory
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 return AUGROUP_ERROR;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 group = au_find_group(group_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 group = AUGROUP_ALL; // no match, use all groups
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 *argp = skipwhite(p); // match, skip over group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 vim_free(group_name);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 return group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 * do_autocmd() for one event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 * If *pat == NUL do for all patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 * If *cmd == NUL show entries.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 * If forceit == TRUE delete entries.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 * If group is not AUGROUP_ALL, only use this group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 do_autocmd_event(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 char_u *pat,
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
1019 int once,
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 int nested,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 char_u *cmd,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 int forceit,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 int group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 AutoPat **prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 AutoCmd **prev_ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 int brace_level;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 char_u *endpat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 int findgroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 int allgroups;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 int patlen;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 int is_buflocal;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 int buflocal_nr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 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
1037
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 if (group == AUGROUP_ALL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 findgroup = current_augroup;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 findgroup = group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 allgroups = (group == AUGROUP_ALL && !forceit && *cmd == NUL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 * Show or delete all patterns for an event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if (*pat == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 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
1050 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 if (forceit) // delete the AutoPat, if it's in the current group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 if (ap->group == findgroup)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 au_remove_pat(ap);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 else if (group == AUGROUP_ALL || ap->group == group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 show_autocmd(ap, event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 * Loop through all the specified patterns.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 for ( ; *pat; pat = (*endpat == ',' ? endpat + 1 : endpat))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 * Find end of the pattern.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 * Watch out for a comma in braces, like "*.\{obj,o\}".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 brace_level = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 for (endpat = pat; *endpat && (*endpat != ',' || brace_level
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 || (endpat > pat && endpat[-1] == '\\')); ++endpat)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 if (*endpat == '{')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 brace_level++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 else if (*endpat == '}')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 brace_level--;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 if (pat == endpat) // ignore single comma
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 continue;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 patlen = (int)(endpat - pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 * detect special <buflocal[=X]> buffer-local patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 is_buflocal = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 buflocal_nr = 0;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 if (patlen >= 8 && STRNCMP(pat, "<buffer", 7) == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 && pat[patlen - 1] == '>')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // "<buffer...>": Error will be printed only for addition.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 // printing and removing will proceed silently.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 is_buflocal = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 if (patlen == 8)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 // "<buffer>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 buflocal_nr = curbuf->b_fnum;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 else if (patlen > 9 && pat[7] == '=')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 if (patlen == 13 && STRNICMP(pat, "<buffer=abuf>", 13) == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 // "<buffer=abuf>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 buflocal_nr = autocmd_bufnr;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 else if (skipdigits(pat + 8) == pat + patlen - 1)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 // "<buffer=123>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 buflocal_nr = atoi((char *)pat + 8);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 if (is_buflocal)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 // normalize pat into standard "<buffer>#N" form
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 sprintf((char *)buflocal_pat, "<buffer=%d>", buflocal_nr);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 pat = buflocal_pat; // can modify pat and patlen
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 patlen = (int)STRLEN(buflocal_pat); // but not endpat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 * Find AutoPat entries with this pattern. When adding a command it
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 * always goes at or after the last one, so start at the end.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 if (!forceit && *cmd != NUL && last_autopat[(int)event] != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 prev_ap = &last_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 prev_ap = &first_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 while ((ap = *prev_ap) != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 if (ap->pat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 /* 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
1130 * - 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
1131 * 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
1132 * 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
1133 * - 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
1134 * - 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 * 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
1136 * 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
1137 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 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
1139 && 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
1140 && 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
1141 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 * 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
1144 * 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
1145 * 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
1146 * 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
1147 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 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
1149 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 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
1151 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 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
1153 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 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
1156 }
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 * 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
1160 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 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
1162 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
1163
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 * 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
1166 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 else 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
1168 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 }
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 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
1172 }
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 * 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
1176 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 if (*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
1178 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 * 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
1181 * 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
1182 * 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
1183 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 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
1185 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 /* 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
1187 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
1188 || 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
1189 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 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
1191 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
1192 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
1193 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 ap = (AutoPat *)alloc((unsigned)sizeof(AutoPat));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 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
1197 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
1198 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
1199 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
1200 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
1201 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 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
1203 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
1204 }
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 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
1207 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 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
1209 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
1210 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 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
1214
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 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
1216 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
1217 &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
1218 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
1219 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
1220 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
1221 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
1222 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 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
1224 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
1225 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
1226 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 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
1229 *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
1230 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
1231 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
1232 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
1233 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
1234 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 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
1236 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237
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 * 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
1240 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 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
1242 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
1243 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
1244 ac = (AutoCmd *)alloc((unsigned)sizeof(AutoCmd));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 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
1246 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
1247 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
1248 #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
1249 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
1250 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
1251 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 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
1253 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 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
1255 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
1256 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 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
1258 *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
1259 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
1260 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
1261 }
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 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
1265 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
1266 }
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 * 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
1270 * 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
1271 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 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
1274 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
1275 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
1276 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
1277 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 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
1279 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
1280 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
1281
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 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
1283 *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
1284
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 * 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
1287 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 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
1289 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
1290 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
1291
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 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
1293 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 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
1295 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
1296 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 * 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
1300 * 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
1301 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 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
1303 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
1304 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
1305
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 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
1307
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 * 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
1310 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 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
1312 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
1313 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
1314 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
1315
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 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
1317 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
1318 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
1319 *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
1320
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 #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
1322 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
1323 #else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 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
1325 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 }
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 * ":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
1330 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 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
1333 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 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
1335 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
1336 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
1337 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
1338 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
1339 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
1340 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
1341
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 * 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
1344 * 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
1345 * 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
1346 * 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
1347 * 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
1348 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 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
1350 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 if (buf->b_ml.ml_mfp != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 // 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
1354 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
1355 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
1356
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 // 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
1358 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
1359
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 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
1361 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 // 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
1363 // 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
1364 // buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 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
1366 }
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 // 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
1369 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
1370
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 // 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
1372 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
1373 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 }
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 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
1378 }
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 * 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
1382 * 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
1383 * 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
1384 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 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
1387 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 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
1389 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 *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
1391 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
1392 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 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
1394 }
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 * 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
1398 * 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
1399 * 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
1400 * 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
1401 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 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
1404 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
1405 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
1406 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 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
1408 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
1409 #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
1410 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
1411 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 // 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
1414 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
1415 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
1416 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 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
1418 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
1419 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 // 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
1422 // 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
1423 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
1424 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 win_alloc_aucmd_win();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 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
1427 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
1428 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 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
1430 // 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
1431 // 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
1432 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
1433
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 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
1435 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
1436 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
1437 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
1438 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 // 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
1440 // 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
1441 // "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
1442 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
1443 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
1444 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 // 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
1448 // 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
1449 // 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
1450 // 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
1451 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
1452 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
1453 aucmd_win->w_buffer = buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 #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
1455 aucmd_win->w_s = &buf->b_s;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 ++buf->b_nwindows;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 win_init_empty(aucmd_win); // set cursor and topline to safe values
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
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 // Make sure w_localdir and globaldir are NULL to avoid a chdir() in
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 // win_enter_ext().
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 VIM_CLEAR(aucmd_win->w_localdir);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 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
1464 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
1465
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 // 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
1468 // 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
1469 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
1470 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
1471 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
1472 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
1473
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 #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
1475 // 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
1476 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
1477 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 (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
1481 (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
1482 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
1483 #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
1484 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
1485 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 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
1487 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
1488 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 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
1490 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
1491 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
1492 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493
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 * 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
1496 * 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
1497 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 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
1500 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
1501 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 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
1503
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 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
1505 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 --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
1507 // 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
1508 // 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
1509 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
1510 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
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 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
1513 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
1514
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 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
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 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
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 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
1520 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
1521 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
1522 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
1523 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 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
1527
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 // 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
1529 (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
1530 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
1531 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
1532 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
1533
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 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
1535 // 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
1536 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
1537
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 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
1539 (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
1540 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
1541
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 if (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
1543 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
1544 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 // 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
1546 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
1547 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
1548 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
1549 #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
1550 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
1551 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
1552 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 curbuf = curwin->w_buffer;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 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
1556 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
1557
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 // 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
1559 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
1560 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
1561 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563 #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
1564 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
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 #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
1568 // 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
1569 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
1570 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
1571 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
1572 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 // 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
1577 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
1578 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 // 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
1580 // 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
1581 // valid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 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
1583 && 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
1584 && 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
1585 && 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
1586 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 # 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
1588 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
1589 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
1590 # endif
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->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
1592 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
1593 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
1594 ++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
1595 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 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
1598 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
1599 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
1600 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
1601 // 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
1602 // 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
1603 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
1604 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 }
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 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
1609
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 * 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
1612 * 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
1613 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 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
1616 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
1617 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
1618 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
1619 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
1620 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
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 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
1623 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 * 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
1628 * 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
1629 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 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
1632 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
1633 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
1634 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
1635 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
1636 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
1637 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
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 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
1640 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
1641 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642
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 * 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
1645 * 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
1646 * 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
1647 * 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
1648 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 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
1651 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
1652 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
1653 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
1654 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
1655 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
1656 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
1657 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 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
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 #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
1661 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
1662 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 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
1666 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
1667 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
1668 #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
1669 && aborting()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 #endif
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 *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
1673 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
1674 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675
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 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
1678 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 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
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 (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
1683 ? 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
1684 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 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
1691 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 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
1693
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 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
1695 && 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
1696 && 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
1697 && 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
1698 #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
1699 && !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
1700 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 )
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 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
1704 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
1705 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
1706 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 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
1708 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 /*
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 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
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 (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
1717 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 #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
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 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
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 (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
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 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 /*
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 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
1737 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 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
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 (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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 #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
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 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
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 (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
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 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 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
1764 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 return (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
1766 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 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
1773 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 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
1775 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 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
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 (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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 #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
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 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 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
1792 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 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
1794 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 * 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
1799 * 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
1800 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 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
1802 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
1803 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
1804 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
1805 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
1806 // 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
1807 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
1808 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
1809 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
1810 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
1811 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 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
1813 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
1814 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
1815 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
1816 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
1817 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
1818 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
1819 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
1820 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
1821 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
1822 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
1823 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
1824 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
1825 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
1826 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
1827 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
1828 #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
1829 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
1830 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
1831 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
1832 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
1833 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 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
1835 #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
1836 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
1837 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 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
1839 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
1840 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
1841
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 * 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
1844 * 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
1845 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 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
1847 || 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
1848 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
1849
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 * 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
1852 * 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
1853 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 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
1855 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
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 #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
1858 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 * 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
1860 * 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
1861 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 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
1863 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
1864 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 * 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
1868 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 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
1870 || 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
1871 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 * 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
1875 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 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
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 * 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
1881 * 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
1882 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 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
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 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
1886 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
1887 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 * 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
1891 * ":ball".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 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
1894 && (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
1895 || (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
1896 && (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
1897 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 * 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
1901 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 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
1903 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
1904 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
1905 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
1906 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
1907 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
1908 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
1909 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
1910
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 * 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
1913 * 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
1914 * invalid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 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
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 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
1919 || 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
1920 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
1921 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
1922 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
1923 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
1924 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
1925 else
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 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
1930 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
1931 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
1932 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 * 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
1936 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 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
1938 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
1939 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 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
1941
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 * 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
1944 * 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
1945 * "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
1946 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 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
1948 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 if (buf == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 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
1951 else
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 #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
1954 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
1955 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
1956 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 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
1959 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
1960 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 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
1963 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
1964 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
1965 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 if (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
1968 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
1969 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
1970 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 else
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 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
1974 // 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
1975 // 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
1976 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
1977 || 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
1978 || 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
1979 || 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
1980 || 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
1981 || 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
1982 || 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
1983 || 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
1984 || 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
1985 || 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
1986 || 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
1987 || 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
1988 || 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
1989 || 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
1990 || 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
1991 || 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
1992 || 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
1993 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 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
1995 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
1996 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 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
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 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
2001 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 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
2003 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
2004 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 #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
2008 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 * 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
2010 * 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
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 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
2013 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
2014 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
2015 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 #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
2018 // 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
2019 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
2020 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
2021 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
2022 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 * 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
2026 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 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
2028
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 // 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
2031 ++RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032 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
2033 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
2034 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
2035 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
2036
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 #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
2038 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
2039
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 # 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
2041 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
2042 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
2043 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 // 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
2046 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
2047 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 * 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
2051 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 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
2053 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 save_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
2055 #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
2056 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
2057 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 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
2060 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
2061 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 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
2063 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2066 * 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
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 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
2069 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
2070 ++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
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 // 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
2073 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
2074 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
2075
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076 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
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 // 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
2079 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
2080 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
2081 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
2082 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
2083 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
2084 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
2085 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
2086 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
2087 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
2088 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
2089
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 // 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
2091 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
2092 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093 // 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
2094 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
2095 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
2096
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 #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
2098 // 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
2099 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
2100 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
2101 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 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
2103 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
2104 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 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
2107 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 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
2109 // 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
2110 // 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
2111 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
2112 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
2113 ap->last = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 check_lnums(TRUE); // make sure cursor and topline are valid
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 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
2116 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 #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
2118 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
2119 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 (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
2121 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
2122 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 // 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
2125 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
2126 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
2127 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 --RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 autocmd_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
2131 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
2132 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
2133 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
2134 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
2135 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
2136 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
2137 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
2138 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
2139 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
2140 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
2141 #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
2142 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
2143 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
2144 # 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
2145 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
2146 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
2147 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 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
2150 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
2151 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
2152 --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
2153
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 * When 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
2156 * 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
2157 * 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
2158 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 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
2160 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 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
2162 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
2163 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
2164 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
2165 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
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 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
2168 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
2169 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
2170 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 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
2172 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 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
2174 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
2175 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
2176 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178
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 * 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
2181 * 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
2182 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 if (curbuf == 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
2184 && (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
2185 || 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
2186 || 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
2187 || 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
2188 || 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
2189 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 #ifdef FEAT_TITLE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 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
2192 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
2193 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 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
2198
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 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
2200 // 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
2201 // 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
2202 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
2203 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
2204
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 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
2206 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
2207
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 # 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
2212 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
2213 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 * 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
2217 * 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
2218 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 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
2221 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 # 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
2223 // 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
2224 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
2225 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
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 ++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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2231 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
2232 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 --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
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 // 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
2237 // 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
2238 // 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
2239 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
2240 && 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
2241 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
2242 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 #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
2246 || 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
2247 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2248 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
2249 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2250 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
2251 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2253
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 * 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
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 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
2258 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
2259 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
2260 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
2261 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 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
2263 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
2264 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
2265 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
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 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
2268
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 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
2270 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 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
2272
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 // 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
2274 // 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
2275 // 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
2276 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
2277 && (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
2278 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 // 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
2280 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
2281 ? (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
2282 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
2283 : 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
2284 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 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
2286 s = _("%s Autocommands for \"%s\"");
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 sourcing_name = alloc((unsigned)(STRLEN(s)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 + STRLEN(name) + ap->patlen + 1));
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 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
2290 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 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
2292 (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
2293 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
2294 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 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
2296 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
2297 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
2298 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 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
2302 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
2303 // 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
2304 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
2305 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
2306 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
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 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
2309 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
2310 break;
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 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
2313 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318 * 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
2319 * 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
2320 * 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
2321 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 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
2323 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
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 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
2326 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
2327 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
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 // 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
2330 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
2331 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
2332
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 // 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
2334 for (;;)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 // 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
2337 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
2338 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
2339 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
2340 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 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
2342
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->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
2344 break;
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 // 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
2347 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
2348 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
2349 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 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
2351 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
2352 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
2353 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
2354 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357 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
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 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
2360 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 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
2362 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
2363 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
2364 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
2365 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 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
2367 // 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
2368 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
2369 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
2370 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
2371 #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
2372 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
2373 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 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
2375 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
2376 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 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
2378 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 * 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
2383 * 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
2384 * 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
2385 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 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
2388 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 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
2390 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
2391 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
2392 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
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 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
2395 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
2396 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
2397
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 #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
2399 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 * 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
2401 * 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
2402 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 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
2404 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
2405 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
2406 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
2407 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 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
2410 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
2411 && (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
2412 ? 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
2413 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
2414 : 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
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 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 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
2418 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 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
2422 #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
2423 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
2424 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 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
2427 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 #if 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
2430 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 * 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
2432 * names.
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 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
2435 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
2436 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 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
2438 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
2439 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
2440 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
2441 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
2442 // 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
2443 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
2444 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
2445 }
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 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
2448
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 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
2450 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
2451 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
2452 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
2453 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
2454 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 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
2456 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
2457
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 // 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
2459 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
2460 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
2461 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
2462 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
2463 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
2464 // 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
2465 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
2466 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 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
2468 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
2469 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 // 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
2472 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
2473 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
2474 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
2475 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
2476 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 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
2478 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
2479 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
2480 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
2481 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
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 pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 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
2486 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
2487 arg++;
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 (*arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 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
2490
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 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
2492 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
2493 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 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
2495 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 * 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
2500 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 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
2502 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
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 (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
2505 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 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
2507 || 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
2508 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
2509 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
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 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
2512 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 #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
2515
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 #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
2517 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 * 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
2519 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 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
2522 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 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
2524
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 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
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
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 * 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
2530 * 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
2531 * 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
2532 * 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
2533 * 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
2534 * 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
2535 * 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
2536 * 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
2537 * 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
2538 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 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
2542 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 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
2544 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
2545 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
2546 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
2547 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
2548 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
2549 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
2550 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
2551 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
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 // 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
2554 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
2555 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
2556 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
2557 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
2558 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
2559 *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
2560
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 // 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
2562 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
2563 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
2564 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 // 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
2566 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
2567 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
2568 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 {
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 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 // "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
2574 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
2575 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
2576 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 // 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
2579 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
2580 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
2581 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
2582 *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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 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
2586
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 // 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
2588 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
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 // 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
2591 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
2592 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
2593
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 // 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
2595 // 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
2596 // 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
2597 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
2598 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
2599 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
2600
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 // 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
2602 // 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
2603 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
2604 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
2605
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 // 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
2607 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
2608 // 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
2609 // 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
2610 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
2611 && (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
2612 && (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
2613 || (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
2614 ? 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
2615 : 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
2616 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 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
2618 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2621 theend:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 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
2623 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
2624 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 #endif