Mercurial > vim
annotate src/usercmd.c @ 33815:08f9e1eac4cf v9.0.2123
patch 9.0.2123: Problem with initializing the length of range() lists
Commit: https://github.com/vim/vim/commit/df63da98d8dc284b1c76cfe1b17fa0acbd6094d8
Author: Christian Brabandt <cb@256bit.org>
Date: Thu Nov 23 20:14:28 2023 +0100
patch 9.0.2123: Problem with initializing the length of range() lists
Problem: Problem with initializing the length of range() lists
Solution: Set length explicitly when it shouldn't contain any items
range() may cause a wrong calculation of list length, which may later
then cause a segfault in list_find(). This is usually not a problem,
because range_list_materialize() calculates the length, when it
materializes the list.
In addition, in list_find() when the length of the range was wrongly
initialized, it may seem to be valid, so the check for list index
out-of-bounds will not be true, because it is called before the list is
actually materialized. And so we may eventually try to access a null
pointer, causing a segfault.
So this patch does 3 things:
- In f_range(), when we know that the list should be empty, explicitly
set the list->lv_len value to zero. This should happen, when
start is larger than end (in case the stride is positive) or
end is larger than start when the stride is negative.
This should fix the underlying issue properly. However,
- as a safety measure, let's check that the requested index is not
out of range one more time, after the list has been materialized
and return NULL in case it suddenly is.
- add a few more tests to verify the behaviour.
fixes: #13557
closes: #13563
Co-authored-by: Tim Pope <tpope@github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 23 Nov 2023 20:30:07 +0100 |
parents | 306f51627f50 |
children | 7c30841c60a0 |
rev | line source |
---|---|
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 * usercmd.c: User defined command support |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 #include "vim.h" |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 typedef struct ucmd |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 char_u *uc_name; // The command name |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 long_u uc_argt; // The argument type |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 char_u *uc_rep; // The command's replacement string |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 long uc_def; // The default value for a range/count |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 int uc_compl; // completion type |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
23 cmd_addr_T uc_addr_type; // The command's address type |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22715
diff
changeset
|
24 sctx_T uc_script_ctx; // SCTX where the command was defined |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
25 int uc_flags; // some UC_ flags |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 # ifdef FEAT_EVAL |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 char_u *uc_compl_arg; // completion argument if any |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 } ucmd_T; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 // List of all user commands. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 static garray_T ucmds = {0, 0, sizeof(ucmd_T), 4, NULL}; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
34 // When non-zero it is not allowed to add or remove user commands |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
35 static int ucmd_locked = 0; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
36 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 #define USER_CMD(i) (&((ucmd_T *)(ucmds.ga_data))[i]) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 #define USER_CMD_GA(gap, i) (&((ucmd_T *)((gap)->ga_data))[i]) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 * List of names for completion for ":command" with the EXPAND_ flag. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 * Must be alphabetical for completion. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 static struct |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 int expand; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 char *name; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 } command_complete[] = |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 {EXPAND_ARGLIST, "arglist"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 {EXPAND_AUGROUP, "augroup"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 {EXPAND_BEHAVE, "behave"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 {EXPAND_BUFFERS, "buffer"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 {EXPAND_COLORS, "color"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 {EXPAND_COMMANDS, "command"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 {EXPAND_COMPILER, "compiler"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 #if defined(FEAT_CSCOPE) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 {EXPAND_CSCOPE, "cscope"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 #endif |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
60 #if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 {EXPAND_USER_DEFINED, "custom"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 {EXPAND_USER_LIST, "customlist"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 #endif |
18987
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
64 {EXPAND_DIFF_BUFFERS, "diff_buffer"}, |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 {EXPAND_DIRECTORIES, "dir"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 {EXPAND_ENV_VARS, "environment"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 {EXPAND_EVENTS, "event"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 {EXPAND_EXPRESSION, "expression"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 {EXPAND_FILES, "file"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 {EXPAND_FILES_IN_PATH, "file_in_path"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 {EXPAND_FILETYPE, "filetype"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 {EXPAND_FUNCTIONS, "function"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 {EXPAND_HELP, "help"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 {EXPAND_HIGHLIGHT, "highlight"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 {EXPAND_HISTORY, "history"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 #if defined(HAVE_LOCALE_H) || defined(X_LOCALE) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 {EXPAND_LOCALES, "locale"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 {EXPAND_MAPCLEAR, "mapclear"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 {EXPAND_MAPPINGS, "mapping"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 {EXPAND_MENUS, "menu"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 {EXPAND_MESSAGES, "messages"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 {EXPAND_OWNSYNTAX, "syntax"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 #if defined(FEAT_PROFILE) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 {EXPAND_SYNTIME, "syntime"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 {EXPAND_SETTINGS, "option"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 {EXPAND_PACKADD, "packadd"}, |
31790
18da1d44878a
patch 9.0.1227: no cmdline completion for :runtime
Bram Moolenaar <Bram@vim.org>
parents:
31493
diff
changeset
|
89 {EXPAND_RUNTIME, "runtime"}, |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 {EXPAND_SHELLCMD, "shellcmd"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 #if defined(FEAT_SIGNS) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 {EXPAND_SIGN, "sign"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 {EXPAND_TAGS, "tag"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 {EXPAND_TAGS_LISTFILES, "tag_listfiles"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 {EXPAND_USER, "user"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 {EXPAND_USER_VARS, "var"}, |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
98 #if defined(FEAT_EVAL) |
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
99 {EXPAND_BREAKPOINT, "breakpoint"}, |
28183
2b595cee4c85
patch 8.2.4617: no completion for :scriptnames
Bram Moolenaar <Bram@vim.org>
parents:
28181
diff
changeset
|
100 {EXPAND_SCRIPTNAMES, "scriptnames"}, |
28081
b737bfa876c5
patch 8.2.4565: no command line completion for :breakadd and :breakdel
Bram Moolenaar <Bram@vim.org>
parents:
27805
diff
changeset
|
101 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 {0, NULL} |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 }; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 * List of names of address types. Must be alphabetical for completion. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 static struct |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 { |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
110 cmd_addr_T expand; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
111 char *name; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
112 char *shortname; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
113 } addr_type_complete[] = |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
114 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 {ADDR_ARGUMENTS, "arguments", "arg"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 {ADDR_LINES, "lines", "line"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 {ADDR_LOADED_BUFFERS, "loaded_buffers", "load"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
118 {ADDR_TABS, "tabs", "tab"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
119 {ADDR_BUFFERS, "buffers", "buf"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
120 {ADDR_WINDOWS, "windows", "win"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
121 {ADDR_QUICKFIX, "quickfix", "qf"}, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
122 {ADDR_OTHER, "other", "?"}, |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
123 {ADDR_NONE, NULL, NULL} |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
124 }; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
125 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
126 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
127 * Search for a user command that matches "eap->cmd". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
128 * Return cmdidx in "eap->cmdidx", flags in "eap->argt", idx in "eap->useridx". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
129 * Return a pointer to just after the command. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
130 * Return NULL if there is no matching command. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
131 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
132 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
133 find_ucmd( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
134 exarg_T *eap, |
27179
c4b94533559e
patch 8.2.4118: using UNUSED for argument that is used
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
135 char_u *p, // end of the command (possibly including count) |
c4b94533559e
patch 8.2.4118: using UNUSED for argument that is used
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
136 int *full, // set to TRUE for a full match |
c4b94533559e
patch 8.2.4118: using UNUSED for argument that is used
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
137 expand_T *xp, // used for completion, NULL otherwise |
c4b94533559e
patch 8.2.4118: using UNUSED for argument that is used
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
138 int *complp) // completion flags or NULL |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
139 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
140 int len = (int)(p - eap->cmd); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
141 int j, k, matchlen = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
142 ucmd_T *uc; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
143 int found = FALSE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
144 int possible = FALSE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
145 char_u *cp, *np; // Point into typed cmd and test name |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
146 garray_T *gap; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
147 int amb_local = FALSE; // Found ambiguous buffer-local command, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
148 // only full match global is accepted. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
149 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
150 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
151 * Look for buffer-local user commands first, then global ones. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
152 */ |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27778
diff
changeset
|
153 gap = &prevwin_curwin()->w_buffer->b_ucmds; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
154 for (;;) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
155 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
156 for (j = 0; j < gap->ga_len; ++j) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
157 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
158 uc = USER_CMD_GA(gap, j); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
159 cp = eap->cmd; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
160 np = uc->uc_name; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
161 k = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
162 while (k < len && *np != NUL && *cp++ == *np++) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
163 k++; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
164 if (k == len || (*np == NUL && vim_isdigit(eap->cmd[k]))) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
165 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
166 // If finding a second match, the command is ambiguous. But |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
167 // not if a buffer-local command wasn't a full match and a |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
168 // global command is a full match. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
169 if (k == len && found && *np != NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
170 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
171 if (gap == &ucmds) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
172 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
173 amb_local = TRUE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
174 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
175 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
176 if (!found || (k == len && *np == NUL)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
177 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
178 // If we matched up to a digit, then there could |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
179 // be another command including the digit that we |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
180 // should use instead. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
181 if (k == len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
182 found = TRUE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
183 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
184 possible = TRUE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
185 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
186 if (gap == &ucmds) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
187 eap->cmdidx = CMD_USER; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
188 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
189 eap->cmdidx = CMD_USER_BUF; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
190 eap->argt = (long)uc->uc_argt; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
191 eap->useridx = j; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
192 eap->addr_type = uc->uc_addr_type; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
193 |
16466
a2befc9b3729
patch 8.1.1237: error for using "compl", reserved word in C++
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
194 if (complp != NULL) |
a2befc9b3729
patch 8.1.1237: error for using "compl", reserved word in C++
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
195 *complp = uc->uc_compl; |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
196 # ifdef FEAT_EVAL |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
197 if (xp != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
198 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
199 xp->xp_arg = uc->uc_compl_arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
200 xp->xp_script_ctx = uc->uc_script_ctx; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
201 xp->xp_script_ctx.sc_lnum += SOURCING_LNUM; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
202 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
203 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
204 // Do not search for further abbreviations |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
205 // if this is an exact match. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
206 matchlen = k; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
207 if (k == len && *np == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
208 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
209 if (full != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
210 *full = TRUE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
211 amb_local = FALSE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
212 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
213 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
214 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
215 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
216 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
217 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
218 // Stop if we found a full match or searched all. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
219 if (j < gap->ga_len || gap == &ucmds) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
220 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
221 gap = &ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
222 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
223 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
224 // Only found ambiguous matches. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
225 if (amb_local) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
226 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
227 if (xp != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
228 xp->xp_context = EXPAND_UNSUCCESSFUL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
229 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
230 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
231 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
232 // The match we found may be followed immediately by a number. Move "p" |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
233 // back to point to it. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
234 if (found || possible) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
235 return p + (matchlen - len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
236 return p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
237 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
238 |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
239 /* |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
240 * Set completion context for :command |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
241 */ |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
242 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
243 set_context_in_user_cmd(expand_T *xp, char_u *arg_in) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
244 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
245 char_u *arg = arg_in; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
246 char_u *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
247 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
248 // Check for attributes |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
249 while (*arg == '-') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
250 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
251 arg++; // Skip "-" |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
252 p = skiptowhite(arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
253 if (*p == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
254 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
255 // Cursor is still in the attribute |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
256 p = vim_strchr(arg, '='); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
257 if (p == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
258 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
259 // No "=", so complete attribute names |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
260 xp->xp_context = EXPAND_USER_CMD_FLAGS; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
261 xp->xp_pattern = arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
262 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
263 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
264 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
265 // For the -complete, -nargs and -addr attributes, we complete |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
266 // their arguments as well. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
267 if (STRNICMP(arg, "complete", p - arg) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
268 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
269 xp->xp_context = EXPAND_USER_COMPLETE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
270 xp->xp_pattern = p + 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
271 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
272 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
273 else if (STRNICMP(arg, "nargs", p - arg) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
274 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
275 xp->xp_context = EXPAND_USER_NARGS; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
276 xp->xp_pattern = p + 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
277 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
278 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
279 else if (STRNICMP(arg, "addr", p - arg) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
280 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
281 xp->xp_context = EXPAND_USER_ADDR_TYPE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
282 xp->xp_pattern = p + 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
283 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
284 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
285 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
286 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
287 arg = skipwhite(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
288 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
289 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
290 // After the attributes comes the new command name |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
291 p = skiptowhite(arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
292 if (*p == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
293 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
294 xp->xp_context = EXPAND_USER_COMMANDS; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
295 xp->xp_pattern = arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
296 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
297 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
298 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
299 // And finally comes a normal command |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
300 return skipwhite(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
301 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
302 |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
303 /* |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
304 * Set the completion context for the argument of a user defined command. |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
305 */ |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
306 char_u * |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
307 set_context_in_user_cmdarg( |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
308 char_u *cmd UNUSED, |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
309 char_u *arg, |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
310 long argt, |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
311 int context, |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
312 expand_T *xp, |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
313 int forceit) |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
314 { |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
315 char_u *p; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
316 |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
317 if (context == EXPAND_NOTHING) |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
318 return NULL; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
319 |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
320 if (argt & EX_XFILE) |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
321 { |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
322 // EX_XFILE: file names are handled before this call |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
323 xp->xp_context = context; |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
324 return NULL; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
325 } |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
326 |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
327 #ifdef FEAT_MENU |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
328 if (context == EXPAND_MENUS) |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
329 return set_context_in_menu_cmd(xp, cmd, arg, forceit); |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
330 #endif |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
331 if (context == EXPAND_COMMANDS) |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
332 return arg; |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
333 if (context == EXPAND_MAPPINGS) |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
334 return set_context_in_map_cmd(xp, (char_u *)"map", arg, forceit, FALSE, |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
335 FALSE, CMD_map); |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
336 // Find start of last argument. |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
337 p = arg; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
338 while (*p) |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
339 { |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
340 if (*p == ' ') |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
341 // argument starts after a space |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
342 arg = p + 1; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
343 else if (*p == '\\' && *(p + 1) != NUL) |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
344 ++p; // skip over escaped character |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
345 MB_PTR_ADV(p); |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
346 } |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
347 xp->xp_pattern = arg; |
27778
858002fef4b7
patch 8.2.4415: function argument name conflicts with C++ keyword
Bram Moolenaar <Bram@vim.org>
parents:
27744
diff
changeset
|
348 xp->xp_context = context; |
27744
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
349 |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
350 return NULL; |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
351 } |
515ce8e07bf2
patch 8.2.4398: some command completion functions are too long
Bram Moolenaar <Bram@vim.org>
parents:
27197
diff
changeset
|
352 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
353 char_u * |
25757
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
354 expand_user_command_name(int idx) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
355 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
356 return get_user_commands(NULL, idx - (int)CMD_SIZE); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
357 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
358 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
359 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
360 * Function given to ExpandGeneric() to obtain the list of user command names. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
361 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
362 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
363 get_user_commands(expand_T *xp UNUSED, int idx) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
364 { |
17468
fa6c9047ec70
patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
365 // In cmdwin, the alternative buffer should be used. |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27778
diff
changeset
|
366 buf_T *buf = prevwin_curwin()->w_buffer; |
17468
fa6c9047ec70
patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
367 |
fa6c9047ec70
patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
368 if (idx < buf->b_ucmds.ga_len) |
fa6c9047ec70
patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
369 return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; |
29479
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
370 |
17468
fa6c9047ec70
patch 8.1.1732: completion in cmdwin does not work for buffer-local commands
Bram Moolenaar <Bram@vim.org>
parents:
17336
diff
changeset
|
371 idx -= buf->b_ucmds.ga_len; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
372 if (idx < ucmds.ga_len) |
29479
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
373 { |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
374 int i; |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
375 char_u *name = USER_CMD(idx)->uc_name; |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
376 |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
377 for (i = 0; i < buf->b_ucmds.ga_len; ++i) |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
378 if (STRCMP(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0) |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
379 // global command is overruled by buffer-local one |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
380 return (char_u *)""; |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
381 return name; |
5c390aa28f44
patch 9.0.0081: command line completion of user command may have duplicates
Bram Moolenaar <Bram@vim.org>
parents:
29377
diff
changeset
|
382 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
383 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
384 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
385 |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26986
diff
changeset
|
386 #ifdef FEAT_EVAL |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
387 /* |
25757
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
388 * Get the name of user command "idx". "cmdidx" can be CMD_USER or |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
389 * CMD_USER_BUF. |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
390 * Returns NULL if the command is not found. |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
391 */ |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
392 char_u * |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
393 get_user_command_name(int idx, int cmdidx) |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
394 { |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
395 if (cmdidx == CMD_USER && idx < ucmds.ga_len) |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
396 return USER_CMD(idx)->uc_name; |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
397 if (cmdidx == CMD_USER_BUF) |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
398 { |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
399 // In cmdwin, the alternative buffer should be used. |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27778
diff
changeset
|
400 buf_T *buf = prevwin_curwin()->w_buffer; |
25757
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
401 |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
402 if (idx < buf->b_ucmds.ga_len) |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
403 return USER_CMD_GA(&buf->b_ucmds, idx)->uc_name; |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
404 } |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
405 return NULL; |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
406 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26986
diff
changeset
|
407 #endif |
25757
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
408 |
589226a5f317
patch 8.2.3414: fullcommand() gives wrong name with buffer-local user command
Bram Moolenaar <Bram@vim.org>
parents:
25491
diff
changeset
|
409 /* |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
410 * Function given to ExpandGeneric() to obtain the list of user address type |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
411 * names. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
412 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
413 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
414 get_user_cmd_addr_type(expand_T *xp UNUSED, int idx) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
415 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
416 return (char_u *)addr_type_complete[idx].name; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
417 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
418 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
419 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
420 * Function given to ExpandGeneric() to obtain the list of user command |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
421 * attributes. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
422 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
423 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
424 get_user_cmd_flags(expand_T *xp UNUSED, int idx) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
425 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
426 static char *user_cmd_flags[] = { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
427 "addr", "bang", "bar", "buffer", "complete", |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
428 "count", "nargs", "range", "register", "keepscript" |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
429 }; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
430 |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
431 if (idx >= (int)ARRAY_LENGTH(user_cmd_flags)) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
432 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
433 return (char_u *)user_cmd_flags[idx]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
434 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
435 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
436 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
437 * Function given to ExpandGeneric() to obtain the list of values for -nargs. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
438 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
439 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
440 get_user_cmd_nargs(expand_T *xp UNUSED, int idx) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
441 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
442 static char *user_cmd_nargs[] = {"0", "1", "*", "?", "+"}; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
443 |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
23390
diff
changeset
|
444 if (idx >= (int)ARRAY_LENGTH(user_cmd_nargs)) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
445 return NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
446 return (char_u *)user_cmd_nargs[idx]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
447 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
448 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
449 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
450 * Function given to ExpandGeneric() to obtain the list of values for |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
451 * -complete. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
452 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
453 char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
454 get_user_cmd_complete(expand_T *xp UNUSED, int idx) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
455 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
456 return (char_u *)command_complete[idx].name; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
457 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
458 |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26986
diff
changeset
|
459 #ifdef FEAT_EVAL |
28757
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
460 /* |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
461 * Get the name of completion type "expand" as a string. |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
462 */ |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
463 char_u * |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
464 cmdcomplete_type_to_str(int expand) |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
465 { |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
466 int i; |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
467 |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
468 for (i = 0; command_complete[i].expand != 0; i++) |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
469 if (command_complete[i].expand == expand) |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
470 return (char_u *)command_complete[i].name; |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
471 |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
472 return NULL; |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
473 } |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
474 |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
475 /* |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
476 * Get the index of completion type "complete_str". |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
477 * Returns EXPAND_NOTHING if no match found. |
add09d468c0d
patch 8.2.4903: cannot get the current cmdline completion type and position
Bram Moolenaar <Bram@vim.org>
parents:
28183
diff
changeset
|
478 */ |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
479 int |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
480 cmdcomplete_str_to_type(char_u *complete_str) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
481 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
482 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
483 |
32947
306f51627f50
commit 92997dda789ad8061841128cbc99b15ec0374411
Christian Brabandt <cb@256bit.org>
parents:
32796
diff
changeset
|
484 if (STRNCMP(complete_str, "custom,", 7) == 0) |
306f51627f50
commit 92997dda789ad8061841128cbc99b15ec0374411
Christian Brabandt <cb@256bit.org>
parents:
32796
diff
changeset
|
485 return EXPAND_USER_DEFINED; |
306f51627f50
commit 92997dda789ad8061841128cbc99b15ec0374411
Christian Brabandt <cb@256bit.org>
parents:
32796
diff
changeset
|
486 if (STRNCMP(complete_str, "customlist,", 11) == 0) |
306f51627f50
commit 92997dda789ad8061841128cbc99b15ec0374411
Christian Brabandt <cb@256bit.org>
parents:
32796
diff
changeset
|
487 return EXPAND_USER_LIST; |
306f51627f50
commit 92997dda789ad8061841128cbc99b15ec0374411
Christian Brabandt <cb@256bit.org>
parents:
32796
diff
changeset
|
488 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
489 for (i = 0; command_complete[i].expand != 0; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
490 if (STRCMP(complete_str, command_complete[i].name) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
491 return command_complete[i].expand; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
492 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
493 return EXPAND_NOTHING; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
494 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26986
diff
changeset
|
495 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
496 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
497 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
498 * List user commands starting with "name[name_len]". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
499 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
500 static void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
501 uc_list(char_u *name, size_t name_len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
502 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
503 int i, j; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
504 int found = FALSE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
505 ucmd_T *cmd; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
506 int len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
507 int over; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
508 long a; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
509 garray_T *gap; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
510 |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
511 // don't allow for adding or removing user commands here |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
512 ++ucmd_locked; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
513 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18301
diff
changeset
|
514 // In cmdwin, the alternative buffer should be used. |
27805
afbe86e8b24a
patch 8.2.4428: crash when switching tabpage while in the cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
27778
diff
changeset
|
515 gap = &prevwin_curwin()->w_buffer->b_ucmds; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
516 for (;;) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
517 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
518 for (i = 0; i < gap->ga_len; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
519 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
520 cmd = USER_CMD_GA(gap, i); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
521 a = (long)cmd->uc_argt; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
522 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
523 // Skip commands which don't match the requested prefix and |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
524 // commands filtered out. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
525 if (STRNCMP(name, cmd->uc_name, name_len) != 0 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
526 || message_filtered(cmd->uc_name)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
527 continue; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
528 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
529 // Put out the title first time |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
530 if (!found) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
531 msg_puts_title(_("\n Name Args Address Complete Definition")); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
532 found = TRUE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
533 msg_putchar('\n'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
534 if (got_int) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
535 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
536 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
537 // Special cases |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
538 len = 4; |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
539 if (a & EX_BANG) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
540 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
541 msg_putchar('!'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
542 --len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
543 } |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
544 if (a & EX_REGSTR) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
545 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
546 msg_putchar('"'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
547 --len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
548 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
549 if (gap != &ucmds) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
550 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
551 msg_putchar('b'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
552 --len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
553 } |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
554 if (a & EX_TRLBAR) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
555 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
556 msg_putchar('|'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
557 --len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
558 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
559 while (len-- > 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
560 msg_putchar(' '); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
561 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
562 msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D)); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
563 len = (int)STRLEN(cmd->uc_name) + 4; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
564 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
565 do { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
566 msg_putchar(' '); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
567 ++len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
568 } while (len < 22); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
569 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
570 // "over" is how much longer the name is than the column width for |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
571 // the name, we'll try to align what comes after. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
572 over = len - 22; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
573 len = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
574 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
575 // Arguments |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
576 switch ((int)(a & (EX_EXTRA|EX_NOSPC|EX_NEEDARG))) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
577 { |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
578 case 0: IObuff[len++] = '0'; break; |
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
579 case (EX_EXTRA): IObuff[len++] = '*'; break; |
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
580 case (EX_EXTRA|EX_NOSPC): IObuff[len++] = '?'; break; |
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
581 case (EX_EXTRA|EX_NEEDARG): IObuff[len++] = '+'; break; |
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
582 case (EX_EXTRA|EX_NOSPC|EX_NEEDARG): IObuff[len++] = '1'; break; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
583 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
584 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
585 do { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
586 IObuff[len++] = ' '; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
587 } while (len < 5 - over); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
588 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
589 // Address / Range |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
590 if (a & (EX_RANGE|EX_COUNT)) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
591 { |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
592 if (a & EX_COUNT) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
593 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
594 // -count=N |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
595 sprintf((char *)IObuff + len, "%ldc", cmd->uc_def); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
596 len += (int)STRLEN(IObuff + len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
597 } |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
598 else if (a & EX_DFLALL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
599 IObuff[len++] = '%'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
600 else if (cmd->uc_def >= 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
601 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
602 // -range=N |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
603 sprintf((char *)IObuff + len, "%ld", cmd->uc_def); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
604 len += (int)STRLEN(IObuff + len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
605 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
606 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
607 IObuff[len++] = '.'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
608 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
609 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
610 do { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
611 IObuff[len++] = ' '; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
612 } while (len < 8 - over); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
613 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
614 // Address Type |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
615 for (j = 0; addr_type_complete[j].expand != ADDR_NONE; ++j) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
616 if (addr_type_complete[j].expand != ADDR_LINES |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
617 && addr_type_complete[j].expand == cmd->uc_addr_type) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
618 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
619 STRCPY(IObuff + len, addr_type_complete[j].shortname); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
620 len += (int)STRLEN(IObuff + len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
621 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
622 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
623 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
624 do { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
625 IObuff[len++] = ' '; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
626 } while (len < 13 - over); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
627 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
628 // Completion |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
629 for (j = 0; command_complete[j].expand != 0; ++j) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
630 if (command_complete[j].expand == cmd->uc_compl) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
631 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
632 STRCPY(IObuff + len, command_complete[j].name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
633 len += (int)STRLEN(IObuff + len); |
27197
80f2c282ef9c
patch 8.2.4127: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
27187
diff
changeset
|
634 #ifdef FEAT_EVAL |
27187
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
635 if (p_verbose > 0 && cmd->uc_compl_arg != NULL |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
636 && STRLEN(cmd->uc_compl_arg) < 200) |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
637 { |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
638 IObuff[len] = ','; |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
639 STRCPY(IObuff + len + 1, cmd->uc_compl_arg); |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
640 len += (int)STRLEN(IObuff + len); |
8950a7b6cc89
patch 8.2.4122: ":command Cmd" does not show custom completion argument
Bram Moolenaar <Bram@vim.org>
parents:
27179
diff
changeset
|
641 } |
27197
80f2c282ef9c
patch 8.2.4127: build failure without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
27187
diff
changeset
|
642 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
643 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
644 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
645 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
646 do { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
647 IObuff[len++] = ' '; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
648 } while (len < 25 - over); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
649 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
650 IObuff[len] = '\0'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
651 msg_outtrans(IObuff); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
652 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
653 msg_outtrans_special(cmd->uc_rep, FALSE, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
654 name_len == 0 ? Columns - 47 : 0); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
655 #ifdef FEAT_EVAL |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
656 if (p_verbose > 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
657 last_set_msg(cmd->uc_script_ctx); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
658 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
659 out_flush(); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
660 ui_breakcheck(); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
661 if (got_int) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
662 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
663 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
664 if (gap == &ucmds || i < gap->ga_len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
665 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
666 gap = &ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
667 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
668 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
669 if (!found) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
670 msg(_("No user-defined commands found")); |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
671 |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
672 --ucmd_locked; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
673 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
674 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
675 char * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
676 uc_fun_cmd(void) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
677 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
678 static char_u fcmd[] = {0x84, 0xaf, 0x60, 0xb9, 0xaf, 0xb5, 0x60, 0xa4, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
679 0xa5, 0xad, 0xa1, 0xae, 0xa4, 0x60, 0xa1, 0x60, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
680 0xb3, 0xa8, 0xb2, 0xb5, 0xa2, 0xa2, 0xa5, 0xb2, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
681 0xb9, 0x7f, 0}; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
682 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
683 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
684 for (i = 0; fcmd[i]; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
685 IObuff[i] = fcmd[i] - 0x40; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
686 IObuff[i] = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
687 return (char *)IObuff; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
688 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
689 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
690 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
691 * Parse address type argument |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
692 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
693 static int |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
694 parse_addr_type_arg( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
695 char_u *value, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
696 int vallen, |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
697 cmd_addr_T *addr_type_arg) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
698 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
699 int i, a, b; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
700 |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
701 for (i = 0; addr_type_complete[i].expand != ADDR_NONE; ++i) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
702 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
703 a = (int)STRLEN(addr_type_complete[i].name) == vallen; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
704 b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
705 if (a && b) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
706 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
707 *addr_type_arg = addr_type_complete[i].expand; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
708 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
709 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
710 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
711 |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
712 if (addr_type_complete[i].expand == ADDR_NONE) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
713 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
714 char_u *err = value; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
715 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
716 for (i = 0; err[i] != NUL && !VIM_ISWHITE(err[i]); i++) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
717 ; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
718 err[i] = NUL; |
26986
79ea140936e9
patch 8.2.4022: two error messages in the wrong file
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
719 semsg(_(e_invalid_address_type_value_str), err); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
720 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
721 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
722 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
723 return OK; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
724 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
725 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
726 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
727 * Parse a completion argument "value[vallen]". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
728 * The detected completion goes in "*complp", argument type in "*argt". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
729 * When there is an argument, for function and user defined completion, it's |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
730 * copied to allocated memory and stored in "*compl_arg". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
731 * Returns FAIL if something is wrong. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
732 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
733 int |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
734 parse_compl_arg( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
735 char_u *value, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
736 int vallen, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
737 int *complp, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
738 long *argt, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
739 char_u **compl_arg UNUSED) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
740 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
741 char_u *arg = NULL; |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
742 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
743 size_t arglen = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
744 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
745 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
746 int valend = vallen; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
747 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
748 // Look for any argument part - which is the part after any ',' |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
749 for (i = 0; i < vallen; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
750 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
751 if (value[i] == ',') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
752 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
753 arg = &value[i + 1]; |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
754 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
755 arglen = vallen - i - 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
756 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
757 valend = i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
758 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
759 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
760 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
761 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
762 for (i = 0; command_complete[i].expand != 0; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
763 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
764 if ((int)STRLEN(command_complete[i].name) == valend |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
765 && STRNCMP(value, command_complete[i].name, valend) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
766 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
767 *complp = command_complete[i].expand; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
768 if (command_complete[i].expand == EXPAND_BUFFERS) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
769 *argt |= EX_BUFNAME; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
770 else if (command_complete[i].expand == EXPAND_DIRECTORIES |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
771 || command_complete[i].expand == EXPAND_FILES) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
772 *argt |= EX_XFILE; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
773 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
774 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
775 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
776 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
777 if (command_complete[i].expand == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
778 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
779 semsg(_(e_invalid_complete_value_str), value); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
780 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
781 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
782 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
783 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
784 if (*complp != EXPAND_USER_DEFINED && *complp != EXPAND_USER_LIST |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
785 && arg != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
786 # else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
787 if (arg != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
788 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
789 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
790 emsg(_(e_completion_argument_only_allowed_for_custom_completion)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
791 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
792 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
793 |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
794 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
795 if ((*complp == EXPAND_USER_DEFINED || *complp == EXPAND_USER_LIST) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
796 && arg == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
797 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
798 emsg(_(e_custom_completion_requires_function_argument)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
799 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
800 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
801 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
802 if (arg != NULL) |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
803 *compl_arg = vim_strnsave(arg, arglen); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
804 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
805 return OK; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
806 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
807 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
808 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
809 * Scan attributes in the ":command" command. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
810 * Return FAIL when something is wrong. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
811 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
812 static int |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
813 uc_scan_attr( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
814 char_u *attr, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
815 size_t len, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
816 long *argt, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
817 long *def, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
818 int *flags, |
16466
a2befc9b3729
patch 8.1.1237: error for using "compl", reserved word in C++
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
819 int *complp, |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
820 char_u **compl_arg, |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
821 cmd_addr_T *addr_type_arg) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
822 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
823 char_u *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
824 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
825 if (len == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
826 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
827 emsg(_(e_no_attribute_specified)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
828 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
829 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
830 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
831 // First, try the simple attributes (no arguments) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
832 if (STRNICMP(attr, "bang", len) == 0) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
833 *argt |= EX_BANG; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
834 else if (STRNICMP(attr, "buffer", len) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
835 *flags |= UC_BUFFER; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
836 else if (STRNICMP(attr, "register", len) == 0) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
837 *argt |= EX_REGSTR; |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
838 else if (STRNICMP(attr, "keepscript", len) == 0) |
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
839 *argt |= EX_KEEPSCRIPT; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
840 else if (STRNICMP(attr, "bar", len) == 0) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
841 *argt |= EX_TRLBAR; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
842 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
843 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
844 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
845 char_u *val = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
846 size_t vallen = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
847 size_t attrlen = len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
848 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
849 // Look for the attribute name - which is the part before any '=' |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
850 for (i = 0; i < (int)len; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
851 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
852 if (attr[i] == '=') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
853 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
854 val = &attr[i + 1]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
855 vallen = len - i - 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
856 attrlen = i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
857 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
858 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
859 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
860 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
861 if (STRNICMP(attr, "nargs", attrlen) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
862 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
863 if (vallen == 1) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
864 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
865 if (*val == '0') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
866 // Do nothing - this is the default |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
867 ; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
868 else if (*val == '1') |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
869 *argt |= (EX_EXTRA | EX_NOSPC | EX_NEEDARG); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
870 else if (*val == '*') |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
871 *argt |= EX_EXTRA; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
872 else if (*val == '?') |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
873 *argt |= (EX_EXTRA | EX_NOSPC); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
874 else if (*val == '+') |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
875 *argt |= (EX_EXTRA | EX_NEEDARG); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
876 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
877 goto wrong_nargs; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
878 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
879 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
880 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
881 wrong_nargs: |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
882 emsg(_(e_invalid_number_of_arguments)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
883 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
884 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
885 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
886 else if (STRNICMP(attr, "range", attrlen) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
887 { |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
888 *argt |= EX_RANGE; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
889 if (vallen == 1 && *val == '%') |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
890 *argt |= EX_DFLALL; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
891 else if (val != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
892 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
893 p = val; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
894 if (*def >= 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
895 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
896 two_count: |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
897 emsg(_(e_count_cannot_be_specified_twice)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
898 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
899 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
900 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
901 *def = getdigits(&p); |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
902 *argt |= EX_ZEROR; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
903 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
904 if (p != val + vallen || vallen == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
905 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
906 invalid_count: |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
907 emsg(_(e_invalid_default_value_for_count)); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
908 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
909 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
910 } |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
911 // default for -range is using buffer lines |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
912 if (*addr_type_arg == ADDR_NONE) |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
913 *addr_type_arg = ADDR_LINES; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
914 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
915 else if (STRNICMP(attr, "count", attrlen) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
916 { |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
917 *argt |= (EX_COUNT | EX_ZEROR | EX_RANGE); |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
918 // default for -count is using any number |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
919 if (*addr_type_arg == ADDR_NONE) |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
920 *addr_type_arg = ADDR_OTHER; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
921 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
922 if (val != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
923 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
924 p = val; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
925 if (*def >= 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
926 goto two_count; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
927 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
928 *def = getdigits(&p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
929 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
930 if (p != val + vallen) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
931 goto invalid_count; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
932 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
933 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
934 if (*def < 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
935 *def = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
936 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
937 else if (STRNICMP(attr, "complete", attrlen) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
938 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
939 if (val == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
940 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
941 semsg(_(e_argument_required_for_str), "-complete"); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
942 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
943 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
944 |
16466
a2befc9b3729
patch 8.1.1237: error for using "compl", reserved word in C++
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
945 if (parse_compl_arg(val, (int)vallen, complp, argt, compl_arg) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
946 == FAIL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
947 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
948 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
949 else if (STRNICMP(attr, "addr", attrlen) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
950 { |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
951 *argt |= EX_RANGE; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
952 if (val == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
953 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
954 semsg(_(e_argument_required_for_str), "-addr"); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
955 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
956 } |
16513
81a9d0fad357
patch 8.1.1260: comparing with pointer instead of value
Bram Moolenaar <Bram@vim.org>
parents:
16511
diff
changeset
|
957 if (parse_addr_type_arg(val, (int)vallen, addr_type_arg) == FAIL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
958 return FAIL; |
16513
81a9d0fad357
patch 8.1.1260: comparing with pointer instead of value
Bram Moolenaar <Bram@vim.org>
parents:
16511
diff
changeset
|
959 if (*addr_type_arg != ADDR_LINES) |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
960 *argt |= EX_ZEROR; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
961 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
962 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
963 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
964 char_u ch = attr[len]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
965 attr[len] = '\0'; |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
966 semsg(_(e_invalid_attribute_str), attr); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
967 attr[len] = ch; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
968 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
969 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
970 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
971 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
972 return OK; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
973 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
974 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
975 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
976 * Add a user command to the list or replace an existing one. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
977 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
978 static int |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
979 uc_add_command( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
980 char_u *name, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
981 size_t name_len, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
982 char_u *rep, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
983 long argt, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
984 long def, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
985 int flags, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
986 int compl, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
987 char_u *compl_arg UNUSED, |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
988 cmd_addr_T addr_type, |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
989 int force) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
990 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
991 ucmd_T *cmd = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
992 char_u *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
993 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
994 int cmp = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
995 char_u *rep_buf = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
996 garray_T *gap; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
997 |
32736
161ae1985d81
patch 9.0.1687: mapset() not properly handling script ID
Christian Brabandt <cb@256bit.org>
parents:
32000
diff
changeset
|
998 replace_termcodes(rep, &rep_buf, 0, 0, NULL); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
999 if (rep_buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1000 { |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1001 // can't replace termcodes - try using the string as is |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1002 rep_buf = vim_strsave(rep); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1003 |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1004 // give up if out of memory |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1005 if (rep_buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1006 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1007 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1008 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1009 // get address of growarray: global or in curbuf |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1010 if (flags & UC_BUFFER) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1011 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1012 gap = &curbuf->b_ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1013 if (gap->ga_itemsize == 0) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1014 ga_init2(gap, sizeof(ucmd_T), 4); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1015 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1016 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1017 gap = &ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1018 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1019 // Search for the command in the already defined commands. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1020 for (i = 0; i < gap->ga_len; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1021 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1022 size_t len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1023 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1024 cmd = USER_CMD_GA(gap, i); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1025 len = STRLEN(cmd->uc_name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1026 cmp = STRNCMP(name, cmd->uc_name, name_len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1027 if (cmp == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1028 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1029 if (name_len < len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1030 cmp = -1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1031 else if (name_len > len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1032 cmp = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1033 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1034 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1035 if (cmp == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1036 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1037 // Command can be replaced with "command!" and when sourcing the |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1038 // same script again, but only once. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1039 if (!force |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1040 #ifdef FEAT_EVAL |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1041 && (cmd->uc_script_ctx.sc_sid != current_sctx.sc_sid |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1042 || cmd->uc_script_ctx.sc_seq == current_sctx.sc_seq) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1043 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1044 ) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1045 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
1046 semsg(_(e_command_already_exists_add_bang_to_replace_it_str), |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1047 name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1048 goto fail; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1049 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1050 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1051 VIM_CLEAR(cmd->uc_rep); |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1052 #if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1053 VIM_CLEAR(cmd->uc_compl_arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1054 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1055 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1056 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1057 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1058 // Stop as soon as we pass the name to add |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1059 if (cmp < 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1060 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1061 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1062 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1063 // Extend the array unless we're replacing an existing command |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1064 if (cmp != 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1065 { |
31837
e16361210675
patch 9.0.1251: checking returned value of ga_grow() is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
31790
diff
changeset
|
1066 if (ga_grow(gap, 1) == FAIL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1067 goto fail; |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
1068 if ((p = vim_strnsave(name, name_len)) == NULL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1069 goto fail; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1070 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1071 cmd = USER_CMD_GA(gap, i); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1072 mch_memmove(cmd + 1, cmd, (gap->ga_len - i) * sizeof(ucmd_T)); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1073 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1074 ++gap->ga_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1075 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1076 cmd->uc_name = p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1077 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1078 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1079 cmd->uc_rep = rep_buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1080 cmd->uc_argt = argt; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1081 cmd->uc_def = def; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1082 cmd->uc_compl = compl; |
23390
9a5f12b36273
patch 8.2.2238: Vim9: cannot load a Vim9 script without the +eval feature
Bram Moolenaar <Bram@vim.org>
parents:
22715
diff
changeset
|
1083 cmd->uc_script_ctx = current_sctx; |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1084 if (flags & UC_VIM9) |
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1085 cmd->uc_script_ctx.sc_version = SCRIPT_VERSION_VIM9; |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1086 cmd->uc_flags = flags & UC_VIM9; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1087 #ifdef FEAT_EVAL |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
1088 cmd->uc_script_ctx.sc_lnum += SOURCING_LNUM; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1089 cmd->uc_compl_arg = compl_arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1090 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1091 cmd->uc_addr_type = addr_type; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1092 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1093 return OK; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1094 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1095 fail: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1096 vim_free(rep_buf); |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1097 #if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1098 vim_free(compl_arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1099 #endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1100 return FAIL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1101 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1102 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1103 /* |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1104 * If "p" starts with "{" then read a block of commands until "}". |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1105 * Used for ":command" and ":autocmd". |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1106 */ |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1107 char_u * |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1108 may_get_cmd_block(exarg_T *eap, char_u *p, char_u **tofree, int *flags) |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1109 { |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1110 char_u *retp = p; |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1111 |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1112 if (*p == '{' && ends_excmd2(eap->arg, skipwhite(p + 1)) |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1113 && eap->getline != NULL) |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1114 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1115 garray_T ga; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1116 char_u *line = NULL; |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1117 |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1118 ga_init2(&ga, sizeof(char_u *), 10); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1119 if (ga_copy_string(&ga, p) == FAIL) |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1120 return retp; |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1121 |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1122 // If the argument ends in "}" it must have been concatenated already |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1123 // for ISN_EXEC. |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1124 if (p[STRLEN(p) - 1] != '}') |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1125 // Read lines between '{' and '}'. Does not support nesting or |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1126 // here-doc constructs. |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1127 for (;;) |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1128 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1129 vim_free(line); |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1130 if ((line = eap->getline(':', eap->cookie, |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1131 0, GETLINE_CONCAT_CONTBAR)) == NULL) |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1132 { |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1133 emsg(_(e_missing_rcurly)); |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1134 break; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1135 } |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1136 if (ga_copy_string(&ga, line) == FAIL) |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1137 break; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1138 if (*skipwhite(line) == '}') |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25463
diff
changeset
|
1139 break; |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1140 } |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1141 vim_free(line); |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1142 retp = *tofree = ga_concat_strings(&ga, "\n"); |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1143 ga_clear_strings(&ga); |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1144 *flags |= UC_VIM9; |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1145 } |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1146 return retp; |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1147 } |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1148 |
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1149 /* |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1150 * ":command ..." implementation |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1151 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1152 void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1153 ex_command(exarg_T *eap) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1154 { |
16475
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1155 char_u *name; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1156 char_u *end; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1157 char_u *p; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1158 long argt = 0; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1159 long def = -1; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1160 int flags = 0; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1161 int compl = EXPAND_NOTHING; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1162 char_u *compl_arg = NULL; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1163 cmd_addr_T addr_type_arg = ADDR_NONE; |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1164 int has_attr = (eap->arg[0] == '-'); |
854fb0ad4be6
patch 8.1.1241: Ex command info contains confusing information
Bram Moolenaar <Bram@vim.org>
parents:
16466
diff
changeset
|
1165 int name_len; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1166 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1167 p = eap->arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1168 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1169 // Check for attributes |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1170 while (*p == '-') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1171 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1172 ++p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1173 end = skiptowhite(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1174 if (uc_scan_attr(p, end - p, &argt, &def, &flags, &compl, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1175 &compl_arg, &addr_type_arg) == FAIL) |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1176 goto theend; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1177 p = skipwhite(end); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1178 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1179 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1180 // Get the name (if any) and skip to the following argument |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1181 name = p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1182 if (ASCII_ISALPHA(*p)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1183 while (ASCII_ISALNUM(*p)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1184 ++p; |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
1185 if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p)) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1186 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
1187 emsg(_(e_invalid_command_name)); |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1188 goto theend; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1189 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1190 end = p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1191 name_len = (int)(end - name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1192 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1193 // If there is nothing after the name, and no attributes were specified, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1194 // we are listing commands |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1195 p = skipwhite(end); |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
1196 if (!has_attr && ends_excmd2(eap->arg, p)) |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1197 { |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1198 uc_list(name, end - name); |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1199 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1200 else if (!ASCII_ISUPPER(*name)) |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1201 { |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26498
diff
changeset
|
1202 emsg(_(e_user_defined_commands_must_start_with_an_uppercase_letter)); |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1203 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1204 else if ((name_len == 1 && *name == 'X') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1205 || (name_len <= 4 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1206 && STRNCMP(name, "Next", name_len > 4 ? 4 : name_len) == 0)) |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1207 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1208 emsg(_(e_reserved_name_cannot_be_used_for_user_defined_command)); |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1209 } |
25210
8d816c266ceb
patch 8.2.3141: no error when using :complete for :command without -nargs
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
1210 else if (compl > 0 && (argt & EX_EXTRA) == 0) |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1211 { |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1212 // Some plugins rely on silently ignoring the mistake, only make this |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1213 // an error in Vim9 script. |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1214 if (in_vim9script()) |
25491
b9419c9d3da6
patch 8.2.3282: Vim9: error about using -complete without -nargs is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
1215 emsg(_(e_complete_used_without_allowing_arguments)); |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1216 else |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1217 give_warning_with_source( |
25491
b9419c9d3da6
patch 8.2.3282: Vim9: error about using -complete without -nargs is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
1218 (char_u *)_(e_complete_used_without_allowing_arguments), |
b9419c9d3da6
patch 8.2.3282: Vim9: error about using -complete without -nargs is confusing
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
1219 TRUE, TRUE); |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
25210
diff
changeset
|
1220 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1221 else |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1222 { |
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1223 char_u *tofree = NULL; |
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1224 |
25463
05f9e8f2016c
patch 8.2.3268: cannot use a block with :autocmd like with :command
Bram Moolenaar <Bram@vim.org>
parents:
25382
diff
changeset
|
1225 p = may_get_cmd_block(eap, p, &tofree, &flags); |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1226 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1227 uc_add_command(name, end - name, p, argt, def, flags, compl, compl_arg, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1228 addr_type_arg, eap->forceit); |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1229 vim_free(tofree); |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1230 |
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1231 return; // success |
25382
b80e4e9c4988
patch 8.2.3228: cannot use a simple block for the :command argument
Bram Moolenaar <Bram@vim.org>
parents:
25226
diff
changeset
|
1232 } |
31493
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1233 |
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1234 theend: |
6c32d1072f82
patch 9.0.1079: leaking memory when defining a user command fails
Bram Moolenaar <Bram@vim.org>
parents:
31085
diff
changeset
|
1235 vim_free(compl_arg); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1236 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1237 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1238 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1239 * ":comclear" implementation |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1240 * Clear all user commands, global and for current buffer. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1241 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1242 void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1243 ex_comclear(exarg_T *eap UNUSED) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1244 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1245 uc_clear(&ucmds); |
16511
4182f74e2965
patch 8.1.1259: crash when exiting early
Bram Moolenaar <Bram@vim.org>
parents:
16475
diff
changeset
|
1246 if (curbuf != NULL) |
4182f74e2965
patch 8.1.1259: crash when exiting early
Bram Moolenaar <Bram@vim.org>
parents:
16475
diff
changeset
|
1247 uc_clear(&curbuf->b_ucmds); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1248 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1249 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1250 /* |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1251 * If ucmd_locked is set give an error and return TRUE. |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1252 * Otherwise return FALSE. |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1253 */ |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1254 static int |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1255 is_ucmd_locked(void) |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1256 { |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1257 if (ucmd_locked > 0) |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1258 { |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1259 emsg(_(e_cannot_change_user_commands_while_listing)); |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1260 return TRUE; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1261 } |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1262 return FALSE; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1263 } |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1264 |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1265 /* |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1266 * Clear all user commands for "gap". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1267 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1268 void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1269 uc_clear(garray_T *gap) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1270 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1271 int i; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1272 ucmd_T *cmd; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1273 |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1274 if (is_ucmd_locked()) |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1275 return; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1276 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1277 for (i = 0; i < gap->ga_len; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1278 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1279 cmd = USER_CMD_GA(gap, i); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1280 vim_free(cmd->uc_name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1281 vim_free(cmd->uc_rep); |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1282 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1283 vim_free(cmd->uc_compl_arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1284 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1285 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1286 ga_clear(gap); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1287 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1288 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1289 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1290 * ":delcommand" implementation |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1291 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1292 void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1293 ex_delcommand(exarg_T *eap) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1294 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1295 int i = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1296 ucmd_T *cmd = NULL; |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1297 int res = -1; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1298 garray_T *gap; |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1299 char_u *arg = eap->arg; |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1300 int buffer_only = FALSE; |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1301 |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1302 if (STRNCMP(arg, "-buffer", 7) == 0 && VIM_ISWHITE(arg[7])) |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1303 { |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1304 buffer_only = TRUE; |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1305 arg = skipwhite(arg + 7); |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1306 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1307 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1308 gap = &curbuf->b_ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1309 for (;;) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1310 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1311 for (i = 0; i < gap->ga_len; ++i) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1312 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1313 cmd = USER_CMD_GA(gap, i); |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1314 res = STRCMP(arg, cmd->uc_name); |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1315 if (res <= 0) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1316 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1317 } |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1318 if (gap == &ucmds || res == 0 || buffer_only) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1319 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1320 gap = &ucmds; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1321 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1322 |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1323 if (res != 0) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1324 { |
25796
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1325 semsg(_(buffer_only |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1326 ? e_no_such_user_defined_command_in_current_buffer_str |
60e4892dfa45
patch 8.2.3433: :delcommand does not take a -buffer option
Bram Moolenaar <Bram@vim.org>
parents:
25757
diff
changeset
|
1327 : e_no_such_user_defined_command_str), arg); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1328 return; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1329 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1330 |
31085
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1331 if (is_ucmd_locked()) |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1332 return; |
8c10a0b22015
patch 9.0.0877: using freed memory with :comclear while listing commands
Bram Moolenaar <Bram@vim.org>
parents:
30986
diff
changeset
|
1333 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1334 vim_free(cmd->uc_name); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1335 vim_free(cmd->uc_rep); |
17781
04245f071792
patch 8.1.1887: the +cmdline_compl feature is not in the tiny version
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
1336 # if defined(FEAT_EVAL) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1337 vim_free(cmd->uc_compl_arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1338 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1339 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1340 --gap->ga_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1341 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1342 if (i < gap->ga_len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1343 mch_memmove(cmd, cmd + 1, (gap->ga_len - i) * sizeof(ucmd_T)); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1344 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1345 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1346 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1347 * Split and quote args for <f-args>. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1348 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1349 static char_u * |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1350 uc_split_args(char_u *arg, size_t *lenp) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1351 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1352 char_u *buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1353 char_u *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1354 char_u *q; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1355 int len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1356 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1357 // Precalculate length |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1358 p = arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1359 len = 2; // Initial and final quotes |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1360 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1361 while (*p) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1362 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1363 if (p[0] == '\\' && p[1] == '\\') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1364 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1365 len += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1366 p += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1367 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1368 else if (p[0] == '\\' && VIM_ISWHITE(p[1])) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1369 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1370 len += 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1371 p += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1372 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1373 else if (*p == '\\' || *p == '"') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1374 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1375 len += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1376 p += 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1377 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1378 else if (VIM_ISWHITE(*p)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1379 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1380 p = skipwhite(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1381 if (*p == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1382 break; |
22649
6e965b3587a4
patch 8.2.1873: Vim9: missing white space when using <f-args>
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1383 len += 4; // ", " |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1384 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1385 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1386 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1387 int charlen = (*mb_ptr2len)(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1388 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1389 len += charlen; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1390 p += charlen; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1391 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1392 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1393 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1394 buf = alloc(len + 1); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1395 if (buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1396 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1397 *lenp = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1398 return buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1399 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1400 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1401 p = arg; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1402 q = buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1403 *q++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1404 while (*p) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1405 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1406 if (p[0] == '\\' && p[1] == '\\') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1407 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1408 *q++ = '\\'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1409 *q++ = '\\'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1410 p += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1411 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1412 else if (p[0] == '\\' && VIM_ISWHITE(p[1])) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1413 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1414 *q++ = p[1]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1415 p += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1416 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1417 else if (*p == '\\' || *p == '"') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1418 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1419 *q++ = '\\'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1420 *q++ = *p++; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1421 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1422 else if (VIM_ISWHITE(*p)) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1423 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1424 p = skipwhite(p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1425 if (*p == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1426 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1427 *q++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1428 *q++ = ','; |
22649
6e965b3587a4
patch 8.2.1873: Vim9: missing white space when using <f-args>
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1429 *q++ = ' '; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1430 *q++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1431 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1432 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1433 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1434 MB_COPY_CHAR(p, q); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1435 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1436 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1437 *q++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1438 *q = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1439 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1440 *lenp = len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1441 return buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1442 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1443 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1444 static size_t |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1445 add_cmd_modifier(char_u *buf, char *mod_str, int *multi_mods) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1446 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1447 size_t result; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1448 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1449 result = STRLEN(mod_str); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1450 if (*multi_mods) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1451 result += 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1452 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1453 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1454 if (*multi_mods) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1455 STRCAT(buf, " "); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1456 STRCAT(buf, mod_str); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1457 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1458 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1459 *multi_mods = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1460 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1461 return result; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1462 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1463 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1464 /* |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1465 * Add modifiers from "cmod->cmod_split" to "buf". Set "multi_mods" when one |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22649
diff
changeset
|
1466 * was added. Return the number of bytes added. |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1467 */ |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1468 size_t |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30904
diff
changeset
|
1469 add_win_cmd_modifiers(char_u *buf, cmdmod_T *cmod, int *multi_mods) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1470 { |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1471 size_t result = 0; |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1472 |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1473 // :aboveleft and :leftabove |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1474 if (cmod->cmod_split & WSP_ABOVE) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1475 result += add_cmd_modifier(buf, "aboveleft", multi_mods); |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1476 // :belowright and :rightbelow |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1477 if (cmod->cmod_split & WSP_BELOW) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1478 result += add_cmd_modifier(buf, "belowright", multi_mods); |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1479 // :botright |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1480 if (cmod->cmod_split & WSP_BOT) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1481 result += add_cmd_modifier(buf, "botright", multi_mods); |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1482 |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1483 // :tab |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1484 if (cmod->cmod_tab > 0) |
30904
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1485 { |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1486 int tabnr = cmod->cmod_tab - 1; |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1487 |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1488 if (tabnr == tabpage_index(curtab)) |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1489 { |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1490 // For compatibility, don't add a tabpage number if it is the same |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1491 // as the default number for :tab. |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1492 result += add_cmd_modifier(buf, "tab", multi_mods); |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1493 } |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1494 else |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1495 { |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1496 char tab_buf[NUMBUFLEN + 3]; |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1497 |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1498 sprintf(tab_buf, "%dtab", tabnr); |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1499 result += add_cmd_modifier(buf, tab_buf, multi_mods); |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1500 } |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1501 } |
8c7495056f35
patch 9.0.0786: user command does not get number from :tab modifier
Bram Moolenaar <Bram@vim.org>
parents:
30017
diff
changeset
|
1502 |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1503 // :topleft |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1504 if (cmod->cmod_split & WSP_TOP) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1505 result += add_cmd_modifier(buf, "topleft", multi_mods); |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1506 // :vertical |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1507 if (cmod->cmod_split & WSP_VERT) |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1508 result += add_cmd_modifier(buf, "vertical", multi_mods); |
30017
578e71f924fe
patch 9.0.0346: :horizontal modifier not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
29479
diff
changeset
|
1509 // :horizontal |
578e71f924fe
patch 9.0.0346: :horizontal modifier not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
29479
diff
changeset
|
1510 if (cmod->cmod_split & WSP_HOR) |
578e71f924fe
patch 9.0.0346: :horizontal modifier not fully supported
Bram Moolenaar <Bram@vim.org>
parents:
29479
diff
changeset
|
1511 result += add_cmd_modifier(buf, "horizontal", multi_mods); |
20043
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1512 return result; |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1513 } |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1514 |
d13f8ae3b1de
patch 8.2.0577: not all modifiers supported for :options
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1515 /* |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1516 * Generate text for the "cmod" command modifiers. |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1517 * If "buf" is NULL just return the length. |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1518 */ |
22715
8968ed4ba4ba
patch 8.2.1906: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
22703
diff
changeset
|
1519 size_t |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1520 produce_cmdmods(char_u *buf, cmdmod_T *cmod, int quote) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1521 { |
22715
8968ed4ba4ba
patch 8.2.1906: warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
22703
diff
changeset
|
1522 size_t result = 0; |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1523 int multi_mods = 0; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1524 int i; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1525 typedef struct { |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1526 int flag; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1527 char *name; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1528 } mod_entry_T; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1529 static mod_entry_T mod_entries[] = { |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1530 #ifdef FEAT_BROWSE_CMD |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1531 {CMOD_BROWSE, "browse"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1532 #endif |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1533 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1534 {CMOD_CONFIRM, "confirm"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1535 #endif |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1536 {CMOD_HIDE, "hide"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1537 {CMOD_KEEPALT, "keepalt"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1538 {CMOD_KEEPJUMPS, "keepjumps"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1539 {CMOD_KEEPMARKS, "keepmarks"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1540 {CMOD_KEEPPATTERNS, "keeppatterns"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1541 {CMOD_LOCKMARKS, "lockmarks"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1542 {CMOD_NOSWAPFILE, "noswapfile"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1543 {CMOD_UNSILENT, "unsilent"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1544 {CMOD_NOAUTOCMD, "noautocmd"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1545 #ifdef HAVE_SANDBOX |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1546 {CMOD_SANDBOX, "sandbox"}, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1547 #endif |
26404
1bbb884c8561
patch 8.2.3733: Vim9: using "legacy" before range does not work
Bram Moolenaar <Bram@vim.org>
parents:
26195
diff
changeset
|
1548 {CMOD_LEGACY, "legacy"}, |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1549 {0, NULL} |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1550 }; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1551 |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1552 result = quote ? 2 : 0; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1553 if (buf != NULL) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1554 { |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1555 if (quote) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1556 *buf++ = '"'; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1557 *buf = '\0'; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1558 } |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1559 |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1560 // the modifiers that are simple flags |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1561 for (i = 0; mod_entries[i].name != NULL; ++i) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1562 if (cmod->cmod_flags & mod_entries[i].flag) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1563 result += add_cmd_modifier(buf, mod_entries[i].name, &multi_mods); |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1564 |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1565 // :silent |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1566 if (cmod->cmod_flags & CMOD_SILENT) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1567 result += add_cmd_modifier(buf, |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1568 (cmod->cmod_flags & CMOD_ERRSILENT) ? "silent!" |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1569 : "silent", &multi_mods); |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1570 // :verbose |
29377
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1571 if (cmod->cmod_verbose > 0) |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1572 { |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1573 int verbose_value = cmod->cmod_verbose - 1; |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1574 |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1575 if (verbose_value == 1) |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1576 result += add_cmd_modifier(buf, "verbose", &multi_mods); |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1577 else |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1578 { |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1579 char verbose_buf[NUMBUFLEN]; |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1580 |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1581 sprintf(verbose_buf, "%dverbose", verbose_value); |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1582 result += add_cmd_modifier(buf, verbose_buf, &multi_mods); |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1583 } |
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1584 } |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1585 // flags from cmod->cmod_split |
30986
360f286b5869
patch 9.0.0828: various typos
Bram Moolenaar <Bram@vim.org>
parents:
30904
diff
changeset
|
1586 result += add_win_cmd_modifiers(buf, cmod, &multi_mods); |
29377
48b086982c01
patch 9.0.0031: <cmod> of user command does not have correct verbose value
Bram Moolenaar <Bram@vim.org>
parents:
28757
diff
changeset
|
1587 |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1588 if (quote && buf != NULL) |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1589 { |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1590 buf += result - 2; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1591 *buf = '"'; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1592 } |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1593 return result; |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1594 } |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1595 |
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1596 /* |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1597 * Check for a <> code in a user command. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1598 * "code" points to the '<'. "len" the length of the <> (inclusive). |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1599 * "buf" is where the result is to be added. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1600 * "split_buf" points to a buffer used for splitting, caller should free it. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1601 * "split_len" is the length of what "split_buf" contains. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1602 * Returns the length of the replacement, which has been added to "buf". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1603 * Returns -1 if there was no match, and only the "<" has been copied. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1604 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1605 static size_t |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1606 uc_check_code( |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1607 char_u *code, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1608 size_t len, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1609 char_u *buf, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1610 ucmd_T *cmd, // the user command we're expanding |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1611 exarg_T *eap, // ex arguments |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1612 char_u **split_buf, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1613 size_t *split_len) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1614 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1615 size_t result = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1616 char_u *p = code + 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1617 size_t l = len - 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1618 int quote = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1619 enum { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1620 ct_ARGS, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1621 ct_BANG, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1622 ct_COUNT, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1623 ct_LINE1, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1624 ct_LINE2, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1625 ct_RANGE, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1626 ct_MODS, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1627 ct_REGISTER, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1628 ct_LT, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1629 ct_NONE |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1630 } type = ct_NONE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1631 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1632 if ((vim_strchr((char_u *)"qQfF", *p) != NULL) && p[1] == '-') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1633 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1634 quote = (*p == 'q' || *p == 'Q') ? 1 : 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1635 p += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1636 l -= 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1637 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1638 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1639 ++l; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1640 if (l <= 1) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1641 type = ct_NONE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1642 else if (STRNICMP(p, "args>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1643 type = ct_ARGS; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1644 else if (STRNICMP(p, "bang>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1645 type = ct_BANG; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1646 else if (STRNICMP(p, "count>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1647 type = ct_COUNT; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1648 else if (STRNICMP(p, "line1>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1649 type = ct_LINE1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1650 else if (STRNICMP(p, "line2>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1651 type = ct_LINE2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1652 else if (STRNICMP(p, "range>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1653 type = ct_RANGE; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1654 else if (STRNICMP(p, "lt>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1655 type = ct_LT; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1656 else if (STRNICMP(p, "reg>", l) == 0 || STRNICMP(p, "register>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1657 type = ct_REGISTER; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1658 else if (STRNICMP(p, "mods>", l) == 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1659 type = ct_MODS; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1660 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1661 switch (type) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1662 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1663 case ct_ARGS: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1664 // Simple case first |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1665 if (*eap->arg == NUL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1666 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1667 if (quote == 1) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1668 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1669 result = 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1670 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1671 STRCPY(buf, "''"); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1672 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1673 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1674 result = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1675 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1676 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1677 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1678 // When specified there is a single argument don't split it. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1679 // Works for ":Cmd %" when % is "a b c". |
17336
81705f4d9e03
patch 8.1.1667: flags for Ex commands may clash with other symbols
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1680 if ((eap->argt & EX_NOSPC) && quote == 2) |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1681 quote = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1682 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1683 switch (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1684 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1685 case 0: // No quoting, no splitting |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1686 result = STRLEN(eap->arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1687 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1688 STRCPY(buf, eap->arg); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1689 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1690 case 1: // Quote, but don't split |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1691 result = STRLEN(eap->arg) + 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1692 for (p = eap->arg; *p; ++p) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1693 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1694 if (enc_dbcs != 0 && (*mb_ptr2len)(p) == 2) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1695 // DBCS can contain \ in a trail byte, skip the |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1696 // double-byte character. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1697 ++p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1698 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1699 if (*p == '\\' || *p == '"') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1700 ++result; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1701 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1702 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1703 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1704 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1705 *buf++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1706 for (p = eap->arg; *p; ++p) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1707 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1708 if (enc_dbcs != 0 && (*mb_ptr2len)(p) == 2) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1709 // DBCS can contain \ in a trail byte, copy the |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1710 // double-byte character to avoid escaping. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1711 *buf++ = *p++; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1712 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1713 if (*p == '\\' || *p == '"') |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1714 *buf++ = '\\'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1715 *buf++ = *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1716 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1717 *buf = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1718 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1719 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1720 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1721 case 2: // Quote and split (<f-args>) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1722 // This is hard, so only do it once, and cache the result |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1723 if (*split_buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1724 *split_buf = uc_split_args(eap->arg, split_len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1725 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1726 result = *split_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1727 if (buf != NULL && result != 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1728 STRCPY(buf, *split_buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1729 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1730 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1731 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1732 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1733 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1734 case ct_BANG: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1735 result = eap->forceit ? 1 : 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1736 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1737 result += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1738 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1739 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1740 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1741 *buf++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1742 if (eap->forceit) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1743 *buf++ = '!'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1744 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1745 *buf = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1746 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1747 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1748 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1749 case ct_LINE1: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1750 case ct_LINE2: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1751 case ct_RANGE: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1752 case ct_COUNT: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1753 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1754 char num_buf[20]; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1755 long num = (type == ct_LINE1) ? eap->line1 : |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1756 (type == ct_LINE2) ? eap->line2 : |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1757 (type == ct_RANGE) ? eap->addr_count : |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1758 (eap->addr_count > 0) ? eap->line2 : cmd->uc_def; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1759 size_t num_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1760 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1761 sprintf(num_buf, "%ld", num); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1762 num_len = STRLEN(num_buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1763 result = num_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1764 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1765 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1766 result += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1767 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1768 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1769 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1770 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1771 *buf++ = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1772 STRCPY(buf, num_buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1773 buf += num_len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1774 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1775 *buf = '"'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1776 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1777 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1778 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1779 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1780 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1781 case ct_MODS: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1782 { |
22703
f2bfee4ac356
patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
1783 result = produce_cmdmods(buf, &cmdmod, quote); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1784 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1785 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1786 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1787 case ct_REGISTER: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1788 result = eap->regname ? 1 : 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1789 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1790 result += 2; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1791 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1792 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1793 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1794 *buf++ = '\''; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1795 if (eap->regname) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1796 *buf++ = eap->regname; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1797 if (quote) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1798 *buf = '\''; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1799 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1800 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1801 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1802 case ct_LT: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1803 result = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1804 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1805 *buf = '<'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1806 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1807 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1808 default: |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1809 // Not recognized: just copy the '<' and return -1. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1810 result = (size_t)-1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1811 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1812 *buf = '<'; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1813 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1814 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1815 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1816 return result; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1817 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1818 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1819 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1820 * Execute a user defined command. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1821 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1822 void |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1823 do_ucmd(exarg_T *eap) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1824 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1825 char_u *buf; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1826 char_u *p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1827 char_u *q; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1828 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1829 char_u *start; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1830 char_u *end = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1831 char_u *ksp; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1832 size_t len, totlen; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1833 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1834 size_t split_len = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1835 char_u *split_buf = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1836 ucmd_T *cmd; |
26498
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1837 sctx_T save_current_sctx; |
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1838 int restore_current_sctx = FALSE; |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1839 #ifdef FEAT_EVAL |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1840 int restore_script_version = 0; |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1841 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1842 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1843 if (eap->cmdidx == CMD_USER) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1844 cmd = USER_CMD(eap->useridx); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1845 else |
32000
bd01cb097120
patch 9.0.1332: crash when using buffer-local user command in cmdline window
Bram Moolenaar <Bram@vim.org>
parents:
31837
diff
changeset
|
1846 cmd = USER_CMD_GA(&prevwin_curwin()->w_buffer->b_ucmds, eap->useridx); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1847 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1848 /* |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1849 * Replace <> in the command by the arguments. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1850 * First round: "buf" is NULL, compute length, allocate "buf". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1851 * Second round: copy result into "buf". |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1852 */ |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1853 buf = NULL; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1854 for (;;) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1855 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1856 p = cmd->uc_rep; // source |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1857 q = buf; // destination |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1858 totlen = 0; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1859 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1860 for (;;) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1861 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1862 start = vim_strchr(p, '<'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1863 if (start != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1864 end = vim_strchr(start + 1, '>'); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1865 if (buf != NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1866 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1867 for (ksp = p; *ksp != NUL && *ksp != K_SPECIAL; ++ksp) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1868 ; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1869 if (*ksp == K_SPECIAL |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1870 && (start == NULL || ksp < start || end == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1871 && ((ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1872 # ifdef FEAT_GUI |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1873 || (ksp[1] == KS_EXTRA && ksp[2] == (int)KE_CSI) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1874 # endif |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1875 )) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1876 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1877 // K_SPECIAL has been put in the buffer as K_SPECIAL |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1878 // KS_SPECIAL KE_FILLER, like for mappings, but |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1879 // do_cmdline() doesn't handle that, so convert it back. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1880 // Also change K_SPECIAL KS_EXTRA KE_CSI into CSI. |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1881 len = ksp - p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1882 if (len > 0) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1883 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1884 mch_memmove(q, p, len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1885 q += len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1886 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1887 *q++ = ksp[1] == KS_SPECIAL ? K_SPECIAL : CSI; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1888 p = ksp + 3; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1889 continue; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1890 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1891 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1892 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1893 // break if no <item> is found |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1894 if (start == NULL || end == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1895 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1896 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1897 // Include the '>' |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1898 ++end; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1899 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1900 // Take everything up to the '<' |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1901 len = start - p; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1902 if (buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1903 totlen += len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1904 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1905 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1906 mch_memmove(q, p, len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1907 q += len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1908 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1909 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1910 len = uc_check_code(start, end - start, q, cmd, eap, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1911 &split_buf, &split_len); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1912 if (len == (size_t)-1) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1913 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1914 // no match, continue after '<' |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1915 p = start + 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1916 len = 1; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1917 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1918 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1919 p = end; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1920 if (buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1921 totlen += len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1922 else |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1923 q += len; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1924 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1925 if (buf != NULL) // second time here, finished |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1926 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1927 STRCPY(q, p); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1928 break; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1929 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1930 |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1931 totlen += STRLEN(p); // Add on the trailing characters |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16513
diff
changeset
|
1932 buf = alloc(totlen + 1); |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1933 if (buf == NULL) |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1934 { |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1935 vim_free(split_buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1936 return; |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1937 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1938 } |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1939 |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1940 if ((cmd->uc_argt & EX_KEEPSCRIPT) == 0) |
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1941 { |
26498
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1942 restore_current_sctx = TRUE; |
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1943 save_current_sctx = current_sctx; |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1944 current_sctx.sc_version = cmd->uc_script_ctx.sc_version; |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1945 #ifdef FEAT_EVAL |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1946 current_sctx.sc_sid = cmd->uc_script_ctx.sc_sid; |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1947 if (cmd->uc_flags & UC_VIM9) |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1948 { |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1949 // In a {} block variables use Vim9 script rules, even in a legacy |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1950 // script. |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1951 restore_script_version = |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1952 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version; |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1953 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = SCRIPT_VERSION_VIM9; |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1954 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1955 #endif |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1956 } |
26498
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1957 |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1958 (void)do_cmdline(buf, eap->getline, eap->cookie, |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1959 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED); |
26498
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1960 |
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1961 // Careful: Do not use "cmd" here, it may have become invalid if a user |
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1962 // command was added. |
e36aefc588c2
patch 8.2.3779: using freed memory when defining a user command recursively
Bram Moolenaar <Bram@vim.org>
parents:
26404
diff
changeset
|
1963 if (restore_current_sctx) |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1964 { |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1965 #ifdef FEAT_EVAL |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1966 if (restore_script_version != 0) |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1967 SCRIPT_ITEM(current_sctx.sc_sid)->sn_version = |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1968 restore_script_version; |
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1969 #endif |
26103
d079ab2ba260
patch 8.2.3584: "verbose set efm" reports location of the :compiler command
Bram Moolenaar <Bram@vim.org>
parents:
25796
diff
changeset
|
1970 current_sctx = save_current_sctx; |
28181
2961a18f9cbf
patch 8.2.4616: Vim9: Declarations in a {} block of a user command remain
Bram Moolenaar <Bram@vim.org>
parents:
28081
diff
changeset
|
1971 } |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1972 vim_free(buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1973 vim_free(split_buf); |
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1974 } |