annotate src/autocmd.c @ 18098:a2870e6f5b45 v8.1.2044

patch 8.1.2044: no easy way to process postponed work Commit: https://github.com/vim/vim/commit/8aeec40207b5adcd3a155277dc4f29189343b963 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 15 23:02:04 2019 +0200 patch 8.1.2044: no easy way to process postponed work Problem: No easy way to process postponed work. (Paul Jolly) Solution: Add the SafeState autocommand event.
author Bram Moolenaar <Bram@vim.org>
date Sun, 15 Sep 2019 23:15:03 +0200
parents 59f8948b7590
children 0d9ec3a2821f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * autocmd.c: Autocommand related functions
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 * The autocommands are stored in a list for each event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 * Autocommands for the same pattern, that are consecutive, are joined
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * together, to avoid having to match the pattern too often.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * The result is an array of Autopat lists, which point to AutoCmd lists:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * last_autopat[0] -----------------------------+
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 * first_autopat[0] --> Autopat.next --> Autopat.next --> NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 * Autopat.cmds Autopat.cmds
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 * | |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 * V V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 * AutoCmd.next AutoCmd.next
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 * | |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 * V V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 * AutoCmd.next NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 * NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 * last_autopat[1] --------+
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 * first_autopat[1] --> Autopat.next --> NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 * Autopat.cmds
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 * AutoCmd.next
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * |
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 * V
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 * NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 * etc.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 * The order of AutoCmds is important, this is the order in which they were
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 * defined and will have to be executed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 typedef struct AutoCmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 char_u *cmd; // The command to be executed (NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 // when command has been removed).
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
55 char once; // "One shot": removed after execution
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 char nested; // If autocommands nest here.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 char last; // last command in list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 sctx_T script_ctx; // script context where defined
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 struct AutoCmd *next; // next AutoCmd in list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 } AutoCmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 typedef struct AutoPat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 struct AutoPat *next; // Next AutoPat in AutoPat list; MUST
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 // be the first entry.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 char_u *pat; // pattern as typed (NULL when pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 // has been removed)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 regprog_T *reg_prog; // compiled regprog for pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 AutoCmd *cmds; // list of commands to do
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 int group; // group ID
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 int patlen; // strlen() of pat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 int buflocal_nr; // !=0 for buffer-local AutoPat
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 char allow_dirs; // Pattern may match whole path
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 char last; // last pattern for apply_autocmds()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 } AutoPat;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 static struct event_name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 char *name; // event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 event_T event; // event number
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 } event_names[] =
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 {"BufAdd", EVENT_BUFADD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 {"BufCreate", EVENT_BUFADD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 {"BufDelete", EVENT_BUFDELETE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 {"BufEnter", EVENT_BUFENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 {"BufFilePost", EVENT_BUFFILEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 {"BufFilePre", EVENT_BUFFILEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 {"BufHidden", EVENT_BUFHIDDEN},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 {"BufLeave", EVENT_BUFLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 {"BufNew", EVENT_BUFNEW},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 {"BufNewFile", EVENT_BUFNEWFILE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 {"BufRead", EVENT_BUFREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 {"BufReadCmd", EVENT_BUFREADCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {"BufReadPost", EVENT_BUFREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 {"BufReadPre", EVENT_BUFREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 {"BufUnload", EVENT_BUFUNLOAD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 {"BufWinEnter", EVENT_BUFWINENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 {"BufWinLeave", EVENT_BUFWINLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 {"BufWipeout", EVENT_BUFWIPEOUT},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 {"BufWrite", EVENT_BUFWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 {"BufWritePost", EVENT_BUFWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 {"BufWritePre", EVENT_BUFWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 {"BufWriteCmd", EVENT_BUFWRITECMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 {"CmdlineChanged", EVENT_CMDLINECHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 {"CmdlineEnter", EVENT_CMDLINEENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 {"CmdlineLeave", EVENT_CMDLINELEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 {"CmdwinEnter", EVENT_CMDWINENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 {"CmdwinLeave", EVENT_CMDWINLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 {"CmdUndefined", EVENT_CMDUNDEFINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 {"ColorScheme", EVENT_COLORSCHEME},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 {"ColorSchemePre", EVENT_COLORSCHEMEPRE},
16268
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
115 {"CompleteChanged", EVENT_COMPLETECHANGED},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 {"CompleteDone", EVENT_COMPLETEDONE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 {"CursorHold", EVENT_CURSORHOLD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 {"CursorHoldI", EVENT_CURSORHOLDI},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {"CursorMoved", EVENT_CURSORMOVED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 {"CursorMovedI", EVENT_CURSORMOVEDI},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 {"DiffUpdated", EVENT_DIFFUPDATED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 {"DirChanged", EVENT_DIRCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 {"EncodingChanged", EVENT_ENCODINGCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 {"ExitPre", EVENT_EXITPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 {"FileEncoding", EVENT_ENCODINGCHANGED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 {"FileAppendPost", EVENT_FILEAPPENDPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 {"FileAppendPre", EVENT_FILEAPPENDPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 {"FileAppendCmd", EVENT_FILEAPPENDCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 {"FileChangedShell",EVENT_FILECHANGEDSHELL},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 {"FileChangedShellPost",EVENT_FILECHANGEDSHELLPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 {"FileChangedRO", EVENT_FILECHANGEDRO},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 {"FileReadPost", EVENT_FILEREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 {"FileReadPre", EVENT_FILEREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 {"FileReadCmd", EVENT_FILEREADCMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 {"FileType", EVENT_FILETYPE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 {"FileWritePost", EVENT_FILEWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137 {"FileWritePre", EVENT_FILEWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 {"FileWriteCmd", EVENT_FILEWRITECMD},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 {"FilterReadPost", EVENT_FILTERREADPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {"FilterReadPre", EVENT_FILTERREADPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 {"FilterWritePost", EVENT_FILTERWRITEPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 {"FilterWritePre", EVENT_FILTERWRITEPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 {"FocusGained", EVENT_FOCUSGAINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 {"FocusLost", EVENT_FOCUSLOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 {"FuncUndefined", EVENT_FUNCUNDEFINED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 {"GUIEnter", EVENT_GUIENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 {"GUIFailed", EVENT_GUIFAILED},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 {"InsertChange", EVENT_INSERTCHANGE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 {"InsertEnter", EVENT_INSERTENTER},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 {"InsertLeave", EVENT_INSERTLEAVE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 {"InsertCharPre", EVENT_INSERTCHARPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 {"MenuPopup", EVENT_MENUPOPUP},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 {"OptionSet", EVENT_OPTIONSET},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 {"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 {"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 {"QuitPre", EVENT_QUITPRE},
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 {"RemoteReply", EVENT_REMOTEREPLY},
18098
a2870e6f5b45 patch 8.1.2044: no easy way to process postponed work
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
158 {"SafeState", EVENT_SAFESTATE},
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 {"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
160 {"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
161 {"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
162 {"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
163 {"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
164 {"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
165 {"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
166 {"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
167 {"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
168 {"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
169 {"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
170 {"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
171 {"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
172 {"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
173 {"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
174 {"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
175 {"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
176 {"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
177 {"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
178 {"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
179 {"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
180 {"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
181 {"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
182 {"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
183 {"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
184 {"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
185 {"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
186 {"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
187 {"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
188 {"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
189 {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
190 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 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
193 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 };
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 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
203 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 };
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211
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_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
213 #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
214 #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
215
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 * 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
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 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
220 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 // 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
230 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
231 } AutoPatCmd;
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 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
234
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 * 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
237 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 static 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
239 #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
240 /* 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
241 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
242
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 * 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
245 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 static 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
247
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 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
249
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 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
251 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
252 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
253 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
254 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
255 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
256
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 static 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
258 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
259 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
260
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 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
262 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
263 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 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
265 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
266 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
267 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 * 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
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 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
273 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
274 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 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
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 // 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
278 // 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
279 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
280 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 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
282 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 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
285 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
286 return;
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 (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
288 {
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->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
290 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 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
292 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
293 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 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
295 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
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 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
298 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
299 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
300 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
301 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
302 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 msg_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
305 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
306
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 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
308 {
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 (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
310 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 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
312 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
313 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
314 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
315 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 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
317 #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
318 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
319 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
320 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (got_int)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 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
324 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 msg_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
326 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
327 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 * 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
335 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 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
337 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
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 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
340 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
341 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
342 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 * 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
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 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
348 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
349 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 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
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 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
353 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
354 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
355 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
357 // 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
358 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
359 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
360 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
361 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
362 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
363
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 * Cleanup autocommands and patterns that have been deleted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 * This is only done when not executing autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 static void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 au_cleanup(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 AutoPat *ap, **prev_ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 AutoCmd *ac, **prev_ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 if (autocmd_busy || !au_need_clean)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 // loop over all events
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 for (event = (event_T)0; (int)event < (int)NUM_EVENTS;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 event = (event_T)((int)event + 1))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 // loop over all autocommand patterns
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 prev_ap = &(first_autopat[(int)event]);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 for (ap = *prev_ap; ap != NULL; ap = *prev_ap)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 {
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
386 int has_cmd = FALSE;
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
387
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 // 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
389 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
390 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
391 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 // 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
393 // 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
394 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
395 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 *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
397 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
398 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
399 }
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
400 else
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
401 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
402 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
403 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
404 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
405 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
406
16221
331dc836f866 patch 8.1.1115: cannot build with older C compiler
Bram Moolenaar <Bram@vim.org>
parents: 16217
diff changeset
407 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
408 // 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
409 // 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
410 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
411
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 // 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
413 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
414 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 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
416 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 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
418 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
419 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 // 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
421 // 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
422 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
423 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 *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
425 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
426 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
427 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 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
430 }
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 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
434 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 * 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
438 * autocmds.
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 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 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
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 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
444 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
445 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
446
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 // 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
448 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
449 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
450 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
451
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 // 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
453 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
454 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
455 // 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
456 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
457 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
458 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 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
460 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
461 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 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
463 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
464 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
465 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 au_cleanup();
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 * 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
473 * 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
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 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
476 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
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 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
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 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
481 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
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 // 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
484 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
485 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
486 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 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
488 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
489
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 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
492 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
493 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
494 ++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
495 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 return i;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 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
501 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
502 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 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
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 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
506 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
507 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
508 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
509 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
510 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 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
513 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
514 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
515
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 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
517 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
518 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 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
520 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
521 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 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
523 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
524 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
525 break;
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 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
529 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
530 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
531 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 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
533 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 * 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
538 * 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
539 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 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
541 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
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 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
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 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
546 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
547 && 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
548 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
549 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
550 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * 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
554 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 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
557 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 return 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
559 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 * ":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
563 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 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
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 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
570 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 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
572 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
573 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 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
575 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577 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
578 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
579 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 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
581 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
582 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
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 // ":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
585 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 msg_start();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 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
588 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 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
592 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 msg_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
596 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
597 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 #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
601 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 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
603 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 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
605 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
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 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
608 ++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
609 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
610
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 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
612 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 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
614 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
615 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
616 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 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
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 #endif
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 * 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
623 * 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
624 * 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
625 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 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
627 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
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 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
630 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
631 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
632
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 // 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
634 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
635 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 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
637 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 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
639 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
640 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 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
643 ++p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 *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
645 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
646 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
647 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
648 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 * Return 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
652 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 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
654 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
655 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 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
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 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
659 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
660 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
661 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
662 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 * 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
666 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 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
668 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
669 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
670 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
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 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
673 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
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 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
676 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 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
678 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 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
680 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
681 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 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
683 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 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
687 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 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
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 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
691 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
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 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
694 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
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 }
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 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
699 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 * Return TRUE 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
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 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
705 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
706 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 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
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 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
710 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 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
712 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
713 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
714 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
715 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 * Return 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
722 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 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
725 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 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
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 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
729 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 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
731 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 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
733 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
734 ++p;
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 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
737 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
738 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 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
741 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 # 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
744
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 * 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
747 * 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
748 * 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
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 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
751 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
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 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
754 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
755
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 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
757 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
758 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 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
761 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 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
763 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
764 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 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
766 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
767 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
768 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 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
772 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 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
776 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 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
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 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
780 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
781 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
782 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 # 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
785
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 * 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
788 * 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
789 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 * :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
791 * 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
792 * 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
793 * the current group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 * :autocmd <event> <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
795 * <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
796 * :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
797 * <event>.
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 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
799 * :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
800 * <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
801 * <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
802 * :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
803 * <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
804 * :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
805 * <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
806 * :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
807 * group.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 * 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
810 * 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
811 * :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
812 * :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
813 *
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 * *.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
815 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 * 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
817 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 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
820 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 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
822 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
823 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
824 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
825 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
826 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
827 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
828 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
829 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
830 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
831
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 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
833 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 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
835 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
836 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 * 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
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 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
843 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
844 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846
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 * 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
849 * 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
850 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 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
852 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
853 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 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
856 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
857 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 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
859 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
860 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 else
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 * 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
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 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
867 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
868 cmd++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 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
870 *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
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 // 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
873 // 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
874 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
875 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 #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
877 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
878
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 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
880 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 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
882 #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
883 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
884 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 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
887 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890 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
891 {
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
892 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
893 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
894 // 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
895 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
896 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
897 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
898 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
899 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
900 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
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
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
903 // Check for "++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
904 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
905 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
906 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
907 semsg(_(e_duparg2), "++nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
908 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
909 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
910 }
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
911
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
912 // Check for 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
913 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
914 {
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
915 if (nested)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
916 semsg(_(e_duparg2), "nested");
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
917 nested = TRUE;
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
918 cmd = skipwhite(cmd + 6);
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 }
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 * 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
925 * 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
926 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 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
928 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 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
930 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
931 return;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 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
933 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
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 * 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
938 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 if (!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
940 // 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
941 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
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 * 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
945 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 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
947 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
948 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
949 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 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
951 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
952 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
953 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
954 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 else
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 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
959 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
960 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
961 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 }
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 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
965 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
966 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
967 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 * 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
971 * 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
972 *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 * 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
974 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 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
976 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
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 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
979 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
980 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
981 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
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 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
984 ;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 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
986 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 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
988 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
989 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
990 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
991 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
992 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
993 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 *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
995 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
996 }
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 group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 * 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
1002 * 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
1003 * 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
1004 * 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
1005 * 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
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 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
1008 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
1009 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
1010 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
1011 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
1012 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
1013 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
1014 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
1015 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
1016 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 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
1018 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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025 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
1026 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
1027 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
1028 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
1029
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 if (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
1031 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
1032 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 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
1035
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 * 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
1038 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 if (*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
1040 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 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
1042 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 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
1044 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 if (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
1046 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
1047 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 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
1049 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
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 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 * 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
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 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
1057 {
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 * 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
1060 * 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
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 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
1063 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
1064 || (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
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 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
1067 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
1068 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
1069 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
1070 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 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
1072 continue;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 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
1074
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 * 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
1077 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 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
1079 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
1080
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 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
1082 && 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
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 // "<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
1085 // 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
1086 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
1087 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
1088 // "<buffer>"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 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
1090 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
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 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
1093 // "<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
1094 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
1095 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
1096 // "<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
1097 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
1098 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 if (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
1102 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 // 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
1104 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
1105 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
1106 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
1107 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 * 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
1111 * 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
1112 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 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
1114 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
1115 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 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
1117 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
1118 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 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
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 /* 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
1122 * - 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
1123 * 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
1124 * 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
1125 * - 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
1126 * - 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
1127 * 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
1128 * 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
1129 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 && 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
1132 && 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
1133 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 * 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
1136 * 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
1137 * 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
1138 * 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
1139 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 if (forceit)
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 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
1143 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 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
1145 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 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
1148 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 * 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
1152 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 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
1154 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
1155
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 * 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
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 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
1160 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 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
1164 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 * 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
1168 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 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
1170 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 * 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
1173 * 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
1174 * 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
1175 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 /* 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
1179 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
1180 || 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
1181 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 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
1183 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
1184 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
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
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
1187 ap = ALLOC_ONE(AutoPat);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 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
1189 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
1190 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
1191 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
1192 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
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 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
1195 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
1196 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 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
1199 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 ap->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
1201 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
1202 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 else
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 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
1206
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 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
1208 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
1209 &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
1210 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
1211 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
1212 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
1213 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
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 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
1216 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
1217 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
1218 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 ap->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
1221 *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
1222 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
1223 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
1224 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
1225 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
1226 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 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
1228 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 * 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
1232 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 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
1234 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
1235 prev_ac = &ac->next;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16778
diff changeset
1236 ac = ALLOC_ONE(AutoCmd);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 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
1238 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
1239 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
1240 #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
1241 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
1242 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
1243 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 if (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
1245 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 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
1247 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 }
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->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
1250 *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
1251 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
1252 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
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 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 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
1258 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 * 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
1262 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 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
1266 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
1267 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
1268 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
1269 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 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
1271 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
1272 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
1273
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 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
1275 *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
1276
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 * 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
1279 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 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
1281 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
1282 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
1283
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 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
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 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
1287 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
1288 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 * 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
1292 * 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
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 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
1295 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
1296 return FAIL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 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
1299
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 * 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
1302 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 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
1304 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
1305 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
1306 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
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 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
1309 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
1310 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
1311 *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
1312
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 #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
1314 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
1315 #else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 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
1317 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319
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 * ":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
1322 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 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
1325 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 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
1327 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
1328 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
1329 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
1330 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
1331 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
1332 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
1333
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 * 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
1336 * 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
1337 * 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
1338 * 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
1339 * 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
1340 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 {
16847
f8e28c6ae8ab patch 8.1.1425: win_execute() does not set window pointers properly
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1343 if (buf->b_ml.ml_mfp != NULL)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 // 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
1346 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
1347 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
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 // 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
1350 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
1351
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 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
1353 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 // 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
1355 // 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
1356 // buffer.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 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
1358 }
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 // 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
1361 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
1362
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 // 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
1364 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
1365 break;
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 * 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
1374 * 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
1375 * 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
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 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 check_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
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 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
1381 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 *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
1383 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
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 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
1386 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 * 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
1390 * 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
1391 * 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
1392 * 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
1393 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 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
1396 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
1397 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
1398 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 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
1400 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
1401 #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
1402 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
1403 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 // 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
1406 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
1407 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
1408 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 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
1410 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
1411 break;
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 // 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
1414 // 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
1415 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
1416 {
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1417 aucmd_win = win_alloc_popup_win();
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 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
1419 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
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 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
1422 // 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
1423 // 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
1424 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
1425
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 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
1427 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
1428 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
1429 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
1430 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 // 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
1432 // 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
1433 // "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
1434 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
1435 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
1436 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 else
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 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
1440 // 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
1441 // 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
1442 // 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
1443 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
1444 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
1445
16778
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1446 win_init_popup_win(aucmd_win, buf);
eda4d65f232c patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents: 16764
diff changeset
1447
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 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
1449 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
1450
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 // 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
1452 // 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
1453 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
1454 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
1455 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
1456 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
1457
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 #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
1459 // 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
1460 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
1461 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
1462 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 (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
1465 (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
1466 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
1467 #ifdef FEAT_AUTOCHDIR
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 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
1469 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 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
1471 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
1472 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 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
1474 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
1475 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
1476 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 * 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
1480 * 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
1481 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 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
1484 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
1485 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 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
1487
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 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
1489 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 --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
1491 // 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
1492 // 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
1493 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
1494 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
1495 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 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
1497 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
1498
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 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
1500 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 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
1502 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 if (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
1504 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
1505 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
1506 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
1507 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 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
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 // 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
1513 (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
1514 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
1515 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
1516 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
1517
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 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
1519 // 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
1520 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
1521
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 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
1523 (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
1524 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
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 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
1527 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
1528 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 // 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
1530 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
1531 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
1532 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
1533 #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
1534 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
1535 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
1536 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 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
1538
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 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
1540 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
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 // 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
1543 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
1544 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
1545 {
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->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
1547 #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
1548 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
1549 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 #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
1552 // 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
1553 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
1554 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
1555 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
1556 #endif
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 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 // 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
1561 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
1562 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 // 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
1564 // 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
1565 // valid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 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
1567 && 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
1568 && 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
1569 && 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
1570 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 # 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
1572 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
1573 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
1574 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 --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
1576 curbuf = aco->new_curbuf.br_buf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 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
1578 ++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
1579 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 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
1582 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
1583 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
1584 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
1585 // 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
1586 // 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
1587 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
1588 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 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
1593
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 * 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
1596 * 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
1597 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 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
1600 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
1601 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
1602 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
1603 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
1604 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
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 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
1607 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
1608 }
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 * 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
1612 * 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
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_exarg(
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,
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,
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,
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,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 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
1622 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 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
1624 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 * 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
1629 * 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
1630 * 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
1631 * 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
1632 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 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
1635 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
1636 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
1637 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
1638 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
1639 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
1640 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
1641 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 int 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
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 #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
1645 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
1646 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
1647 #endif
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 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
1650 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
1651 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
1652 #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
1653 && aborting()
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 )
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 *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
1657 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
1658 }
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 * 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
1662 */
17789
0f7ae8010787 patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents: 17781
diff changeset
1663 static int
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 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
1665 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 return (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
1667 ? 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
1668 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 * Return 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
1672 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 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
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 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
1677
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 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
1679 && 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
1680 && 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
1681 && typebuf.tb_len == 0
17809
59f8948b7590 patch 8.1.1901: the +insert_expand feature is not always available
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
1682 && !ins_compl_active())
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 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
1685 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
1686 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
1687 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 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
1689 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 * 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
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 int
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_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
1696 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 return (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
1698 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 * Return TRUE when there is a 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
1702 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 has_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
1705 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 return (first_autopat[(int)EVENT_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
1707 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 * Return TRUE when there is a 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
1711 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 has_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
1714 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 return (first_autopat[(int)EVENT_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
1716 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 * Return TRUE when there is a 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
1720 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 has_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
1723 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 return (first_autopat[(int)EVENT_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
1725 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 * Return TRUE when there is a 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
1729 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 has_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
1732 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 return (first_autopat[(int)EVENT_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
1734 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 * Return TRUE when there is 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
1738 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 has_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
1741 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 return (first_autopat[(int)EVENT_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
1743 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 * Return TRUE when there is an 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
1747 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 has_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
1750 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 return (first_autopat[(int)EVENT_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
1752 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 * Return TRUE when there is an 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
1756 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 has_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
1759 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 return (first_autopat[(int)EVENT_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
1761 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 #if defined(FEAT_EVAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 * Return TRUE when there is a TextYankPost autocommand defined.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 has_textyankpost(void)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 return (first_autopat[(int)EVENT_TEXTYANKPOST] != NULL);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773
16268
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1774 #if defined(FEAT_EVAL) || defined(PROTO)
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1775 /*
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1776 * Return TRUE when there is a CompleteChanged autocommand defined.
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1777 */
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1778 int
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1779 has_completechanged(void)
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1780 {
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1781 return (first_autopat[(int)EVENT_COMPLETECHANGED] != NULL);
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1782 }
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1783 #endif
0f65f2808470 patch 8.1.1138: plugins don't get notified when the popup menu changes
Bram Moolenaar <Bram@vim.org>
parents: 16221
diff changeset
1784
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 * Execute autocommands for "event" and file name "fname".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 * Return TRUE if some commands were executed.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 static int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 apply_autocmds_group(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 event_T event,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 char_u *fname, // NULL or empty means use actual file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 char_u *fname_io, // fname to use for <afile> on cmdline, NULL means
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 // use fname
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 int force, // when TRUE, ignore autocmd_busy
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 int group, // group ID, or AUGROUP_ALL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 buf_T *buf, // buffer for <abuf>
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 exarg_T *eap UNUSED) // command arguments
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 char_u *sfname = NULL; // short file name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 char_u *tail;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 int save_changed;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 buf_T *old_curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 char_u *save_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
1806 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
1807 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
1808 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
1809 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
1810 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
1811 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
1812 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
1813 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
1814 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
1815 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
1816 #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
1817 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
1818 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
1819 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
1820 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
1821 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 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
1823 #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
1824 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
1825 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 int 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
1827 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
1828 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
1829
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 * 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
1832 * 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
1833 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 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
1835 || 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
1836 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
1837
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 * 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
1840 * 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
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 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
1843 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
1844
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 #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
1846 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 * 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
1848 * 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
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 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
1851 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
1852 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 * 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
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 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
1858 || 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
1859 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
1860
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 * 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
1863 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 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
1865 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
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 * 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
1869 * 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
1870 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 if (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
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 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
1874 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
1875 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 * 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
1879 * ":ball".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 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
1882 && (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
1883 || (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
1884 && (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
1885 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
1886
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 * 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
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 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
1891 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
1892 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
1893 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
1894 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
1895 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
1896 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
1897 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
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 * 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
1901 * 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
1902 * invalid.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 if (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
1905 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 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
1907 || 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
1908 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
1909 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
1910 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
1911 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
1912 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
1913 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 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
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 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 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
1918 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
1919 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
1920 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
1921
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 * 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
1924 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 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
1926 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
1927 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 autocmd_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
1929
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 * 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
1932 * 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
1933 * "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
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 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
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 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
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 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 #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
1942 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
1943 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
1944 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 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
1947 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
1948 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 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
1951 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
1952 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
1953 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 if (fname == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 fname = (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
1957 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
1958 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 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
1962 // 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
1963 // 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
1964 if (event == EVENT_FILETYPE
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 || 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
1966 || 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
1967 || 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
1968 || 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
1969 || 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
1970 || 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
1971 || 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
1972 || 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
1973 || 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
1974 || 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
1975 || 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
1976 || 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
1977 || 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
1978 || 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
1979 || 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
1980 || 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
1981 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 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
1983 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
1984 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 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
1987 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 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
1989 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 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
1991 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
1992 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 #ifdef 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
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 * 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
1998 * 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
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 (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
2001 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
2002 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
2003 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 #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
2006 // 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
2007 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
2008 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
2009 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
2010 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 * 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
2014 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 // 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
2019 ++RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 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
2021 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
2022 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
2023 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
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 #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
2026 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
2027
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 # 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
2029 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
2030 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
2031 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2032
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 // 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
2034 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
2035 #endif
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 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 * 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
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 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
2041 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 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
2043 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
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 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
2046 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
2047 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 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
2049 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 * 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
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 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
2055 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
2056 ++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
2057
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 // 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
2059 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
2060 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
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 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
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 // 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
2065 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
2066 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
2067 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
2068 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
2069 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
2070 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
2071 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
2072 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
2073 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
2074 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
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 // 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
2077 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
2078 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 // 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
2080 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
2081 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
2082
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 #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
2084 // 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
2085 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
2086 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
2087 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 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
2089 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
2090 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 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
2093 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 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
2095 // 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
2096 // 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
2097 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
2098 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
2099 ap->last = TRUE;
16401
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2100
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2101 // make sure cursor and topline are valid
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2102 check_lnums(TRUE);
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2103
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 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
2105 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
16401
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2106
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2107 // restore cursor and topline, unless they were changed
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2108 reset_lnums();
3b2db762a509 patch 8.1.1205: a BufReadPre autocommand may cause the cursor to move
Bram Moolenaar <Bram@vim.org>
parents: 16268
diff changeset
2109
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 #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
2111 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
2112 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 (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
2114 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
2115 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 // 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
2118 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
2119 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
2120 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 --RedrawingDisabled;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 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
2124 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
2125 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
2126 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
2127 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
2128 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
2129 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
2130 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
2131 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
2132 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
2133 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
2134 #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
2135 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
2136 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
2137 # 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
2138 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
2139 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
2140 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 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
2143 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
2144 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
2145 --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
2146
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 * 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
2149 * 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
2150 * 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
2151 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 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
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 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
2155 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
2156 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
2157 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
2158 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
2159 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 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
2161 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
2162 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
2163 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 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
2165 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 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
2167 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
2168 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
2169 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 * 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
2174 * 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
2175 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 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
2177 && (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
2178 || 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
2179 || 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
2180 || 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
2181 || 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
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 #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
2184 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
2185 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
2186 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 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
2188 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 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
2191
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 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
2193 // 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
2194 // 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
2195 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
2196 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
2197
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 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
2199 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
2200
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 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
2202 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 # 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
2205 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
2206 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 * 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
2210 * 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
2211 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 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
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 # 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
2216 // 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
2217 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
2218 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
2219 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 ++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
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
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 void
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 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
2225 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226 --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
2227
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228 # 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
2229 // 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
2230 // 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
2231 // 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
2232 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
2233 && 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
2234 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
2235 # endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 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
2240 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2241 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
2242 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2243
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2244 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245 * 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
2246 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 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
2248 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
2249 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
2250 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
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 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
2253 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
2254 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
2255 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
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 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
2258
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 for (ap = apc->curpat; ap != NULL && !got_int; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2261 apc->curpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 // Only use a pattern when it has not been removed, has commands and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 // the group matches. For buffer-local autocommands only check the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 // buffer number.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2266 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2267 && (apc->group == AUGROUP_ALL || apc->group == ap->group))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 // execution-condition
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 if (ap->buflocal_nr == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271 ? (match_file_pat(NULL, &ap->reg_prog, apc->fname,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 apc->sfname, apc->tail, ap->allow_dirs))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 : ap->buflocal_nr == apc->arg_bufnr)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2274 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2275 name = event_nr2name(apc->event);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2276 s = _("%s Autocommands for \"%s\"");
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16401
diff changeset
2277 sourcing_name = alloc(STRLEN(s)
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16401
diff changeset
2278 + STRLEN(name) + ap->patlen + 1);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 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
2280 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 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
2282 (char *)name, (char *)ap->pat);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2283 if (p_verbose >= 8)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 verbose_enter();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 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
2287 verbose_leave();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2290
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2291 apc->curpat = ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2292 apc->nextcmd = ap->cmds;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 // mark last command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 for (cp = ap->cmds; cp->next != NULL; cp = cp->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 cp->last = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 cp->last = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2297 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 line_breakcheck();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 if (apc->curpat != NULL) // found a match
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 if (stop_at_last && ap->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2307 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 * Get next autocommand command.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2309 * Called by do_cmdline() to get the next line for ":if".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 * Returns allocated string, or NULL for end of autocommands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 char_u *
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 16906
diff changeset
2313 getnextac(int c UNUSED, void *cookie, int indent UNUSED, int do_concat UNUSED)
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 AutoPatCmd *acp = (AutoPatCmd *)cookie;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316 char_u *retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 AutoCmd *ac;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2318
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 // Can be called again after returning the last line.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 if (acp->curpat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2323 // repeat until we find an autocommand to execute
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 for (;;)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 // skip removed commands
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 while (acp->nextcmd != NULL && acp->nextcmd->cmd == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 if (acp->nextcmd->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 acp->nextcmd = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2330 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2331 acp->nextcmd = acp->nextcmd->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2332
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2333 if (acp->nextcmd != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 // at end of commands, find next pattern that matches
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 if (acp->curpat->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 acp->curpat = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 acp->curpat = acp->curpat->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 if (acp->curpat != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2342 auto_next_pat(acp, TRUE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 if (acp->curpat == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 ac = acp->nextcmd;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 if (p_verbose >= 9)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 verbose_enter_scroll();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 smsg(_("autocommand %s"), ac->cmd);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 msg_puts("\n"); // don't overwrite this either
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 verbose_leave_scroll();
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 retval = vim_strsave(ac->cmd);
16217
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2357 // Remove one-shot ("once") autocmd in anticipation of its execution.
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2358 if (ac->once)
81e6940504e8 patch 8.1.1113: making an autocommand trigger once is not so easy
Bram Moolenaar <Bram@vim.org>
parents: 16162
diff changeset
2359 au_del_cmd(ac);
15634
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2360 autocmd_nested = ac->nested;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2361 #ifdef FEAT_EVAL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 current_sctx = ac->script_ctx;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 if (ac->last)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2365 acp->nextcmd = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 acp->nextcmd = ac->next;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 * Return TRUE if there is a matching autocommand for "fname".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373 * To account for buffer-local autocommands, function needs to know
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 * in which buffer the file will be opened.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 has_autocmd(event_T event, char_u *sfname, buf_T *buf)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 char_u *fname;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 char_u *tail = gettail(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2382 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2383
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 fname = FullName_save(sfname, FALSE);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 if (fname == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 * Replace all backslashes with forward slashes. This makes the
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 * autocommand patterns portable between Unix and MS-DOS.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 sfname = vim_strsave(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 if (sfname != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 forward_slash(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 forward_slash(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 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
2400 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 && (ap->buflocal_nr == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 ? match_file_pat(NULL, &ap->reg_prog,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 fname, sfname, tail, ap->allow_dirs)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 : buf != NULL && ap->buflocal_nr == buf->b_fnum
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 ))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 vim_free(fname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 #ifdef BACKSLASH_IN_FILENAME
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 vim_free(sfname);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 #endif
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 * Function given to ExpandGeneric() to obtain the list of autocommand group
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 * names.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 get_augroup_name(expand_T *xp UNUSED, int idx)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 if (idx == augroups.ga_len) // add "END" add the end
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 return (char_u *)"END";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 if (idx >= augroups.ga_len) // end of list
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 if (AUGROUP_NAME(idx) == NULL || AUGROUP_NAME(idx) == get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 // skip deleted entries
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 return (char_u *)"";
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 return AUGROUP_NAME(idx); // return a name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 static int include_groups = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 set_context_in_autocmd(
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 expand_T *xp,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 char_u *arg,
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 int doautocmd) // TRUE for :doauto*, FALSE for :autocmd
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 // check for a group name, skip it if present
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 include_groups = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 p = arg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 group = au_get_grouparg(&arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 // If there only is a group name that's what we expand.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454 if (*arg == NUL && group != AUGROUP_ALL && !VIM_ISWHITE(arg[-1]))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 arg = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 // skip over event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 for (p = arg; *p != NUL && !VIM_ISWHITE(*p); ++p)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 if (*p == ',')
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 arg = p + 1;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 if (*p == NUL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 if (group == AUGROUP_ALL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 include_groups = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 xp->xp_context = EXPAND_EVENTS; // expand event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 xp->xp_pattern = arg;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2473 // skip over pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 arg = skipwhite(p);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 while (*arg && (!VIM_ISWHITE(*arg) || arg[-1] == '\\'))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 arg++;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 if (*arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 return arg; // expand (next) command
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 if (doautocmd)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 xp->xp_context = EXPAND_FILES; // expand file names
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 xp->xp_context = EXPAND_NOTHING; // pattern is not expanded
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 return NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 * Function given to ExpandGeneric() to obtain the list of event names.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 char_u *
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 get_event_name(expand_T *xp UNUSED, int idx)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 if (idx < augroups.ga_len) // First list group names, if wanted
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 if (!include_groups || AUGROUP_NAME(idx) == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 || AUGROUP_NAME(idx) == get_deleted_augroup())
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 return (char_u *)""; // skip deleted entries
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 return AUGROUP_NAME(idx); // return a name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 return (char_u *)event_names[idx - augroups.ga_len].name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 #if defined(FEAT_EVAL) || defined(PROTO)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2505 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 * Return TRUE if autocmd is supported.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2507 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 autocmd_supported(char_u *name)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2512
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 return (event_name2nr(name, &p) != NUM_EVENTS);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 /*
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2517 * Return TRUE if an autocommand is defined for a group, event and
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 * pattern: The group can be omitted to accept any group. "event" and "pattern"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 * can be NULL to accept any event and pattern. "pattern" can be NULL to accept
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 * any pattern. Buffer-local patterns <buffer> or <buffer=N> are accepted.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2521 * Used for:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 * exists("#Group") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 * exists("#Group#Event") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2524 * exists("#Group#Event#pat") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 * exists("#Event") or
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 * exists("#Event#pat")
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 */
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 int
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 au_exists(char_u *arg)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2531 char_u *arg_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2532 char_u *pattern = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 char_u *event_name;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 char_u *p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 event_T event;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 AutoPat *ap;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 buf_T *buflocal_buf = NULL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 int group;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 int retval = FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 // Make a copy so that we can change the '#' chars to a NUL.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 arg_save = vim_strsave(arg);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 if (arg_save == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 p = vim_strchr(arg_save, '#');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 if (p != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 *p++ = NUL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 // First, look for an autocmd group name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 group = au_find_group(arg_save);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 if (group == AUGROUP_ERROR)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 // Didn't match a group name, assume the first argument is an event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 group = AUGROUP_ALL;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 event_name = arg_save;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 else
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 if (p == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 // "Group": group name is present and it's recognized
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566 // Must be "Group#Event" or "Group#Event#pat".
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 event_name = p;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 p = vim_strchr(event_name, '#');
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 if (p != NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 *p++ = NUL; // "Group#Event#pat"
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 pattern = p; // "pattern" is NULL when there is no pattern
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 // find the index (enum) for the event name
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 event = event_name2nr(event_name, &p);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 // return FALSE if the event name is not recognized
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 if (event == NUM_EVENTS)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 // Find the first autocommand for this event.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 // If there isn't any, return FALSE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 // If there is one and no pattern given, return TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 ap = first_autopat[(int)event];
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 if (ap == NULL)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 goto theend;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 // if pattern is "<buffer>", special handling is needed which uses curbuf
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 // for pattern "<buffer=N>, fnamecmp() will work fine
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 if (pattern != NULL && STRICMP(pattern, "<buffer>") == 0)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 buflocal_buf = curbuf;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 // Check if there is an autocommand with the given pattern.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 for ( ; ap != NULL; ap = ap->next)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2596 // only use a pattern when it has not been removed and has commands.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 // For buffer-local autocommands, fnamecmp() works fine.
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 if (ap->pat != NULL && ap->cmds != NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599 && (group == AUGROUP_ALL || ap->group == group)
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 && (pattern == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 || (buflocal_buf == NULL
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 ? fnamecmp(ap->pat, pattern) == 0
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603 : ap->buflocal_nr == buflocal_buf->b_fnum)))
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 {
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605 retval = TRUE;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 break;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2607 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 theend:
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 vim_free(arg_save);
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 return retval;
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 }
746b95fd25ad patch 8.1.0825: code for autocommands is mixed with file I/O code
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 #endif