Mercurial > vim
annotate src/message.c @ 25429:2aefea114696 v8.2.3251
patch 8.2.3251: listing builtin_gui as an available terminal is confusing
Commit: https://github.com/vim/vim/commit/0f5575d0a7316a9c9a4b02df3372a07514cd8f26
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jul 30 21:18:03 2021 +0200
patch 8.2.3251: listing builtin_gui as an available terminal is confusing
Problem: Listing builtin_gui as an available terminal is confusing.
Solution: Do not list builtin_gui. (Christian Brabandt, closes https://github.com/vim/vim/issues/8669,
closes #8661)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 30 Jul 2021 21:30:04 +0200 |
parents | a9ea83a3659a |
children | 0082503ff2ff |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10040
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * message.c: functions for displaying messages on the command line | |
12 */ | |
13 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
14 #define MESSAGE_FILE // don't include prototype for smsg() |
9988
cafe247c949a
commit https://github.com/vim/vim/commit/44ca54aeb9a0eca41aea203786e33d82e69d0615
Christian Brabandt <cb@256bit.org>
parents:
9986
diff
changeset
|
15 #define USING_FLOAT_STUFF |
7 | 16 |
17 #include "vim.h" | |
18 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
19 static void add_msg_hist(char_u *s, int len, int attr); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
20 static void hit_return_msg(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
21 static void msg_home_replace_attr(char_u *fname, int attr); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
22 static void msg_puts_attr_len(char *str, int maxlen, int attr); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
23 static void msg_puts_display(char_u *str, int maxlen, int attr, int recurse); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
24 static void msg_scroll_up(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
25 static void inc_msg_scrolled(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
26 static void store_sb_text(char_u **sb_str, char_u *s, int attr, int *sb_col, int finish); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
27 static void t_puts(int *t_col, char_u *t_s, char_u *s, int attr); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
28 static void msg_puts_printf(char_u *str, int maxlen); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
29 static int do_more_prompt(int typed_char); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
30 static void msg_screen_putchar(int c, int attr); |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
31 static void msg_moremsg(int full); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
32 static int msg_check_screen(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
33 static void redir_write(char_u *s, int maxlen); |
7 | 34 #ifdef FEAT_CON_DIALOG |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
35 static char_u *msg_show_console_dialog(char_u *message, char_u *buttons, int dfltbutton); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
36 static int confirm_msg_used = FALSE; // displaying confirm_msg |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
37 static char_u *confirm_msg = NULL; // ":confirm" message |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
38 static char_u *confirm_msg_tail; // tail of confirm_msg |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
39 static void display_confirm_msg(void); |
7 | 40 #endif |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
41 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
42 static int emsg_to_channel_log = FALSE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
43 #endif |
7 | 44 |
45 struct msg_hist | |
46 { | |
47 struct msg_hist *next; | |
48 char_u *msg; | |
49 int attr; | |
50 }; | |
51 | |
52 static struct msg_hist *first_msg_hist = NULL; | |
53 static struct msg_hist *last_msg_hist = NULL; | |
54 static int msg_hist_len = 0; | |
55 | |
3072 | 56 static FILE *verbose_fd = NULL; |
57 static int verbose_did_open = FALSE; | |
58 | |
7 | 59 /* |
60 * When writing messages to the screen, there are many different situations. | |
61 * A number of variables is used to remember the current state: | |
62 * msg_didany TRUE when messages were written since the last time the | |
63 * user reacted to a prompt. | |
64 * Reset: After hitting a key for the hit-return prompt, | |
65 * hitting <CR> for the command line or input(). | |
66 * Set: When any message is written to the screen. | |
67 * msg_didout TRUE when something was written to the current line. | |
68 * Reset: When advancing to the next line, when the current | |
69 * text can be overwritten. | |
70 * Set: When any message is written to the screen. | |
71 * msg_nowait No extra delay for the last drawn message. | |
72 * Used in normal_cmd() before the mode message is drawn. | |
73 * emsg_on_display There was an error message recently. Indicates that there | |
74 * should be a delay before redrawing. | |
75 * msg_scroll The next message should not overwrite the current one. | |
76 * msg_scrolled How many lines the screen has been scrolled (because of | |
77 * messages). Used in update_screen() to scroll the screen | |
78 * back. Incremented each time the screen scrolls a line. | |
79 * msg_scrolled_ign TRUE when msg_scrolled is non-zero and msg_puts_attr() | |
80 * writes something without scrolling should not make | |
81 * need_wait_return to be set. This is a hack to make ":ts" | |
82 * work without an extra prompt. | |
83 * lines_left Number of lines available for messages before the | |
3240 | 84 * more-prompt is to be given. -1 when not set. |
7 | 85 * need_wait_return TRUE when the hit-return prompt is needed. |
86 * Reset: After giving the hit-return prompt, when the user | |
87 * has answered some other prompt. | |
88 * Set: When the ruler or typeahead display is overwritten, | |
89 * scrolling the screen for some message. | |
90 * keep_msg Message to be displayed after redrawing the screen, in | |
91 * main_loop(). | |
92 * This is an allocated string or NULL when not used. | |
93 */ | |
94 | |
95 /* | |
96 * msg(s) - displays the string 's' on the status line | |
97 * When terminal not initialized (yet) mch_errmsg(..) is used. | |
98 * return TRUE if wait_return not called | |
99 */ | |
100 int | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
101 msg(char *s) |
7 | 102 { |
103 return msg_attr_keep(s, 0, FALSE); | |
104 } | |
105 | |
291 | 106 /* |
107 * Like msg() but keep it silent when 'verbosefile' is set. | |
108 */ | |
109 int | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
110 verb_msg(char *s) |
291 | 111 { |
112 int n; | |
113 | |
114 verbose_enter(); | |
115 n = msg_attr_keep(s, 0, FALSE); | |
116 verbose_leave(); | |
117 | |
118 return n; | |
119 } | |
120 | |
7 | 121 int |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
122 msg_attr(char *s, int attr) |
7 | 123 { |
124 return msg_attr_keep(s, attr, FALSE); | |
125 } | |
126 | |
127 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
128 msg_attr_keep( |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
129 char *s, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
130 int attr, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
131 int keep) // TRUE: set keep_msg if it doesn't scroll |
7 | 132 { |
133 static int entered = 0; | |
134 int retval; | |
135 char_u *buf = NULL; | |
136 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
137 // Skip messages not matching ":filter pattern". |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
138 // Don't filter when there is an error. |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
139 if (!emsg_on_display && message_filtered((char_u *)s)) |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
140 return TRUE; |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
141 |
7 | 142 #ifdef FEAT_EVAL |
143 if (attr == 0) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
144 set_vim_var_string(VV_STATUSMSG, (char_u *)s, -1); |
7 | 145 #endif |
146 | |
147 /* | |
148 * It is possible that displaying a messages causes a problem (e.g., | |
149 * when redrawing the window), which causes another message, etc.. To | |
150 * break this loop, limit the recursiveness to 3 levels. | |
151 */ | |
152 if (entered >= 3) | |
153 return TRUE; | |
154 ++entered; | |
155 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
156 // Add message to history (unless it's a repeated kept message or a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
157 // truncated message) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
158 if ((char_u *)s != keep_msg |
7 | 159 || (*s != '<' |
160 && last_msg_hist != NULL | |
161 && last_msg_hist->msg != NULL | |
162 && STRCMP(s, last_msg_hist->msg))) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
163 add_msg_hist((char_u *)s, -1, attr); |
7 | 164 |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
165 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
166 if (emsg_to_channel_log) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
167 // Write message in the channel log. |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11653
diff
changeset
|
168 ch_log(NULL, "ERROR: %s", (char *)s); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
169 #endif |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
170 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
171 // Truncate the message if needed. |
513 | 172 msg_start(); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
173 buf = msg_strtrunc((char_u *)s, FALSE); |
7 | 174 if (buf != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
175 s = (char *)buf; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
176 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
177 msg_outtrans_attr((char_u *)s, attr); |
7 | 178 msg_clr_eos(); |
179 retval = msg_end(); | |
180 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
181 if (keep && retval && vim_strsize((char_u *)s) |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
182 < (int)(Rows - cmdline_row - 1) * Columns + sc_col) |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
183 set_keep_msg((char_u *)s, 0); |
7 | 184 |
185 vim_free(buf); | |
186 --entered; | |
187 return retval; | |
188 } | |
189 | |
190 /* | |
191 * Truncate a string such that it can be printed without causing a scroll. | |
192 * Returns an allocated string or NULL when no truncating is done. | |
193 */ | |
194 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
195 msg_strtrunc( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
196 char_u *s, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
197 int force) // always truncate |
7 | 198 { |
199 char_u *buf = NULL; | |
200 int len; | |
201 int room; | |
202 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
203 // May truncate message to avoid a hit-return prompt |
513 | 204 if ((!msg_scroll && !need_wait_return && shortmess(SHM_TRUNCALL) |
205 && !exmode_active && msg_silent == 0) || force) | |
7 | 206 { |
207 len = vim_strsize(s); | |
539 | 208 if (msg_scrolled != 0) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
209 // Use all the columns. |
513 | 210 room = (int)(Rows - msg_row) * Columns - 1; |
211 else | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
212 // Use up to 'showcmd' column. |
513 | 213 room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; |
7 | 214 if (len > room && room > 0) |
215 { | |
216 if (enc_utf8) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
217 // may have up to 18 bytes per cell (6 per char, up to two |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
218 // composing chars) |
3277 | 219 len = (room + 2) * 18; |
7 | 220 else if (enc_dbcs == DBCS_JPNU) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
221 // may have up to 2 bytes per cell for euc-jp |
3277 | 222 len = (room + 2) * 2; |
7 | 223 else |
3277 | 224 len = room + 2; |
225 buf = alloc(len); | |
7 | 226 if (buf != NULL) |
3277 | 227 trunc_string(s, buf, room, len); |
7 | 228 } |
229 } | |
230 return buf; | |
231 } | |
232 | |
233 /* | |
234 * Truncate a string "s" to "buf" with cell width "room". | |
235 * "s" and "buf" may be equal. | |
236 */ | |
237 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
238 trunc_string( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
239 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
240 char_u *buf, |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
241 int room_in, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
242 int buflen) |
7 | 243 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
244 size_t room = room_in - 3; // "..." takes 3 chars |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
245 size_t half; |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
246 size_t len = 0; |
7 | 247 int e; |
248 int i; | |
249 int n; | |
250 | |
23946
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
251 if (*s == NUL) |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
252 { |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
253 if (buflen > 0) |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
254 *buf = NUL; |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
255 return; |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
256 } |
0b1f5717dc4d
patch 8.2.2515: memory access error when truncating an empty message
Bram Moolenaar <Bram@vim.org>
parents:
23825
diff
changeset
|
257 |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
258 if (room_in < 3) |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
259 room = 0; |
7 | 260 half = room / 2; |
261 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
262 // First part: Start of the string. |
3277 | 263 for (e = 0; len < half && e < buflen; ++e) |
7 | 264 { |
265 if (s[e] == NUL) | |
266 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
267 // text fits without truncating! |
7 | 268 buf[e] = NUL; |
269 return; | |
270 } | |
271 n = ptr2cells(s + e); | |
9542
00ee8d8c2e0c
commit https://github.com/vim/vim/commit/502ae4ba63561c98ac69af26cd9883bfd18d225f
Christian Brabandt <cb@256bit.org>
parents:
9538
diff
changeset
|
272 if (len + n > half) |
7 | 273 break; |
274 len += n; | |
275 buf[e] = s[e]; | |
276 if (has_mbyte) | |
474 | 277 for (n = (*mb_ptr2len)(s + e); --n > 0; ) |
7 | 278 { |
3277 | 279 if (++e == buflen) |
280 break; | |
7 | 281 buf[e] = s[e]; |
282 } | |
283 } | |
284 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
285 // Last part: End of the string. |
7 | 286 i = e; |
287 if (enc_dbcs != 0) | |
288 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
289 // For DBCS going backwards in a string is slow, but |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
290 // computing the cell width isn't too slow: go forward |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
291 // until the rest fits. |
7 | 292 n = vim_strsize(s + i); |
293 while (len + n > room) | |
294 { | |
295 n -= ptr2cells(s + i); | |
474 | 296 i += (*mb_ptr2len)(s + i); |
7 | 297 } |
298 } | |
299 else if (enc_utf8) | |
300 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
301 // For UTF-8 we can go backwards easily. |
714 | 302 half = i = (int)STRLEN(s); |
7 | 303 for (;;) |
304 { | |
714 | 305 do |
11269
121d29004998
patch 8.0.0520: using a function pointer while the function is known
Christian Brabandt <cb@256bit.org>
parents:
11163
diff
changeset
|
306 half = half - utf_head_off(s, s + half - 1) - 1; |
9581
716382aaa0c0
commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents:
9542
diff
changeset
|
307 while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); |
7 | 308 n = ptr2cells(s + half); |
9581
716382aaa0c0
commit https://github.com/vim/vim/commit/b9644433d2728e99fab874e5e33147ad95d23a31
Christian Brabandt <cb@256bit.org>
parents:
9542
diff
changeset
|
309 if (len + n > room || half == 0) |
7 | 310 break; |
311 len += n; | |
9698
a1b1405a33ca
commit https://github.com/vim/vim/commit/a5c0cc11330157c721748e317e8ff54b649610ca
Christian Brabandt <cb@256bit.org>
parents:
9640
diff
changeset
|
312 i = (int)half; |
7 | 313 } |
314 } | |
315 else | |
316 { | |
18999
6fb11e7fb9cd
patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
317 for (i = (int)STRLEN(s); |
6fb11e7fb9cd
patch 8.2.0060: message test only runs with one encoding
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
318 i - 1 >= 0 && len + (n = ptr2cells(s + i - 1)) <= room; --i) |
7 | 319 len += n; |
320 } | |
321 | |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
322 |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
323 if (i <= e + 3) |
3277 | 324 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
325 // text fits without truncating |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
326 if (s != buf) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
327 { |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
328 len = STRLEN(s); |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
329 if (len >= (size_t)buflen) |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
330 len = buflen - 1; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
331 len = len - e + 1; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
332 if (len < 1) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
333 buf[e - 1] = NUL; |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
334 else |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
335 mch_memmove(buf + e, s + e, len); |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
336 } |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
337 } |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
338 else if (e + 3 < buflen) |
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
339 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
340 // set the middle and copy the last part |
3277 | 341 mch_memmove(buf + e, "...", (size_t)3); |
9640
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
342 len = STRLEN(s + i) + 1; |
bc0a6d9a9a07
commit https://github.com/vim/vim/commit/d4f31dc45482e8db527ca044b9c3436b1e750006
Christian Brabandt <cb@256bit.org>
parents:
9605
diff
changeset
|
343 if (len >= (size_t)buflen - e - 3) |
3277 | 344 len = buflen - e - 3 - 1; |
345 mch_memmove(buf + e + 3, s + i, len); | |
346 buf[e + 3 + len - 1] = NUL; | |
347 } | |
348 else | |
349 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
350 // can't fit in the "...", just truncate it |
9538
26da1efa9e46
commit https://github.com/vim/vim/commit/f6acffbe83e622542d9fdf3066f51933e46e4954
Christian Brabandt <cb@256bit.org>
parents:
9497
diff
changeset
|
351 buf[e - 1] = NUL; |
3277 | 352 } |
7 | 353 } |
354 | |
355 /* | |
356 * Automatic prototype generation does not understand this function. | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
357 * Note: Caller of smsg() and smsg_attr() must check the resulting string is |
7 | 358 * shorter than IOSIZE!!! |
359 */ | |
360 #ifndef PROTO | |
361 | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
362 int vim_snprintf(char *str, size_t str_m, const char *fmt, ...); |
272 | 363 |
7 | 364 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
365 smsg(const char *s, ...) |
7 | 366 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
367 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
368 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
369 // Very early in initialisation and already something wrong, just |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
370 // give the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
371 return msg((char *)s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
372 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
373 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
374 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
375 va_list arglist; |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
376 |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
377 va_start(arglist, s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
378 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
379 va_end(arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
380 return msg((char *)IObuff); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
381 } |
7 | 382 } |
383 | |
384 int | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
385 smsg_attr(int attr, const char *s, ...) |
7 | 386 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
387 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
388 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
389 // Very early in initialisation and already something wrong, just |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
390 // give the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
391 return msg_attr((char *)s, attr); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
392 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
393 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
394 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
395 va_list arglist; |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
396 |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
397 va_start(arglist, s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
398 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
399 va_end(arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
400 return msg_attr((char *)IObuff, attr); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
401 } |
7 | 402 } |
403 | |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
404 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
405 smsg_attr_keep(int attr, const char *s, ...) |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
406 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
407 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
408 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
409 // Very early in initialisation and already something wrong, just |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
410 // give the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
411 return msg_attr_keep((char *)s, attr, TRUE); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
412 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
413 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
414 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
415 va_list arglist; |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
416 |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
417 va_start(arglist, s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
418 vim_vsnprintf((char *)IObuff, IOSIZE, s, arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
419 va_end(arglist); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
420 return msg_attr_keep((char *)IObuff, attr, TRUE); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
421 } |
14237
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
422 } |
487d7bda80ea
patch 8.1.0135: undo message delays screen update for CTRL-O u
Christian Brabandt <cb@256bit.org>
parents:
14210
diff
changeset
|
423 |
7 | 424 #endif |
425 | |
426 /* | |
427 * Remember the last sourcing name/lnum used in an error message, so that it | |
428 * isn't printed each time when it didn't change. | |
429 */ | |
430 static int last_sourcing_lnum = 0; | |
431 static char_u *last_sourcing_name = NULL; | |
432 | |
433 /* | |
434 * Reset the last used sourcing name/lnum. Makes sure it is displayed again | |
435 * for the next error message; | |
436 */ | |
360 | 437 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
438 reset_last_sourcing(void) |
7 | 439 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
440 VIM_CLEAR(last_sourcing_name); |
7 | 441 last_sourcing_lnum = 0; |
442 } | |
443 | |
444 /* | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
445 * Return TRUE if "SOURCING_NAME" differs from "last_sourcing_name". |
16 | 446 */ |
447 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
448 other_sourcing_name(void) |
16 | 449 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
450 if (SOURCING_NAME != NULL) |
16 | 451 { |
452 if (last_sourcing_name != NULL) | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
453 return STRCMP(SOURCING_NAME, last_sourcing_name) != 0; |
16 | 454 return TRUE; |
455 } | |
456 return FALSE; | |
457 } | |
458 | |
459 /* | |
7 | 460 * Get the message about the source, as used for an error message. |
461 * Returns an allocated string with room for one more character. | |
462 * Returns NULL when no message is to be given. | |
463 */ | |
464 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
465 get_emsg_source(void) |
7 | 466 { |
467 char_u *Buf, *p; | |
468 | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
469 if (SOURCING_NAME != NULL && other_sourcing_name()) |
7 | 470 { |
22208
a607f02fd17a
patch 8.2.1653: expand('<stack>') does not include the final line number
Bram Moolenaar <Bram@vim.org>
parents:
22163
diff
changeset
|
471 char_u *sname = estack_sfile(ESTACK_NONE); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
472 char_u *tofree = sname; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
473 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
474 if (sname == NULL) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
475 sname = SOURCING_NAME; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
476 |
22584
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
477 #ifdef FEAT_EVAL |
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
478 if (estack_compiling) |
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
479 p = (char_u *)_("Error detected while compiling %s:"); |
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
480 else |
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
481 #endif |
c271498e03b2
patch 8.2.1840: Vim9: error message is not clear about compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22208
diff
changeset
|
482 p = (char_u *)_("Error detected while processing %s:"); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
483 Buf = alloc(STRLEN(sname) + STRLEN(p)); |
7 | 484 if (Buf != NULL) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
485 sprintf((char *)Buf, (char *)p, sname); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
486 vim_free(tofree); |
7 | 487 return Buf; |
488 } | |
489 return NULL; | |
490 } | |
491 | |
492 /* | |
493 * Get the message about the source lnum, as used for an error message. | |
494 * Returns an allocated string with room for one more character. | |
495 * Returns NULL when no message is to be given. | |
496 */ | |
497 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
498 get_emsg_lnum(void) |
7 | 499 { |
500 char_u *Buf, *p; | |
501 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
502 // lnum is 0 when executing a command from the command line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
503 // argument, we don't want a line number then |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
504 if (SOURCING_NAME != NULL |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
505 && (other_sourcing_name() || SOURCING_LNUM != last_sourcing_lnum) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
506 && SOURCING_LNUM != 0) |
7 | 507 { |
508 p = (char_u *)_("line %4ld:"); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
509 Buf = alloc(STRLEN(p) + 20); |
7 | 510 if (Buf != NULL) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
511 sprintf((char *)Buf, (char *)p, (long)SOURCING_LNUM); |
7 | 512 return Buf; |
513 } | |
514 return NULL; | |
515 } | |
516 | |
517 /* | |
16 | 518 * Display name and line number for the source of an error. |
519 * Remember the file name and line number, so that for the next error the info | |
520 * is only displayed if it changed. | |
521 */ | |
522 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
523 msg_source(int attr) |
16 | 524 { |
525 char_u *p; | |
526 | |
527 ++no_wait_return; | |
528 p = get_emsg_source(); | |
529 if (p != NULL) | |
530 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
531 msg_attr((char *)p, attr); |
16 | 532 vim_free(p); |
533 } | |
534 p = get_emsg_lnum(); | |
535 if (p != NULL) | |
536 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
537 msg_attr((char *)p, HL_ATTR(HLF_N)); |
16 | 538 vim_free(p); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
539 last_sourcing_lnum = SOURCING_LNUM; // only once for each line |
16 | 540 } |
541 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
542 // remember the last sourcing name printed, also when it's empty |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
543 if (SOURCING_NAME == NULL || other_sourcing_name()) |
16 | 544 { |
545 vim_free(last_sourcing_name); | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
546 if (SOURCING_NAME == NULL) |
16 | 547 last_sourcing_name = NULL; |
548 else | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
549 last_sourcing_name = vim_strsave(SOURCING_NAME); |
16 | 550 } |
551 --no_wait_return; | |
552 } | |
553 | |
554 /* | |
840 | 555 * Return TRUE if not giving error messages right now: |
556 * If "emsg_off" is set: no error messages at the moment. | |
557 * If "msg" is in 'debug': do error message but without side effects. | |
558 * If "emsg_skip" is set: never do error messages. | |
559 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
560 static int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
561 emsg_not_now(void) |
840 | 562 { |
563 if ((emsg_off > 0 && vim_strchr(p_debug, 'm') == NULL | |
564 && vim_strchr(p_debug, 't') == NULL) | |
565 #ifdef FEAT_EVAL | |
566 || emsg_skip > 0 | |
567 #endif | |
568 ) | |
569 return TRUE; | |
570 return FALSE; | |
571 } | |
572 | |
11016
4e7308525fe7
patch 8.0.0397: can't build with +viminfo but without +eval
Christian Brabandt <cb@256bit.org>
parents:
11012
diff
changeset
|
573 #if defined(FEAT_EVAL) || defined(PROTO) |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
574 static garray_T ignore_error_list = GA_EMPTY; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
575 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
576 void |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
577 ignore_error_for_testing(char_u *error) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
578 { |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
579 if (ignore_error_list.ga_itemsize == 0) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
580 ga_init2(&ignore_error_list, sizeof(char_u *), 1); |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
581 |
15219
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
582 if (STRCMP("RESET", error) == 0) |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
583 ga_clear_strings(&ignore_error_list); |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
584 else |
dada0b389d4f
patch 8.1.0619: :echomsg and :echoerr do not handle List and Dict
Bram Moolenaar <Bram@vim.org>
parents:
15211
diff
changeset
|
585 ga_add_string(&ignore_error_list, error); |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
586 } |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
587 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
588 static int |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
589 ignore_error(char_u *msg) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
590 { |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
591 int i; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
592 |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
593 for (i = 0; i < ignore_error_list.ga_len; ++i) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
594 if (strstr((char *)msg, |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
595 (char *)((char_u **)(ignore_error_list.ga_data))[i]) != NULL) |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
596 return TRUE; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
597 return FALSE; |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
598 } |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
599 #endif |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
600 |
9605
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
601 #if !defined(HAVE_STRERROR) || defined(PROTO) |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
602 /* |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
603 * Replacement for perror() that behaves more or less like emsg() was called. |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
604 * v:errmsg will be set and called_emsg will be incremented. |
9605
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
605 */ |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
606 void |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
607 do_perror(char *msg) |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
608 { |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
609 perror(msg); |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
610 ++emsg_silent; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
611 emsg(msg); |
9605
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
612 --emsg_silent; |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
613 } |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
614 #endif |
846d4bad2df7
commit https://github.com/vim/vim/commit/b869c0da31716ff14bbfd63346d140d0a1d68af7
Christian Brabandt <cb@256bit.org>
parents:
9581
diff
changeset
|
615 |
840 | 616 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
617 * emsg_core() - display an error message |
7 | 618 * |
619 * Rings the bell, if appropriate, and calls message() to do the real work | |
620 * When terminal not initialized (yet) mch_errmsg(..) is used. | |
621 * | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
622 * Return TRUE if wait_return not called. |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
623 * Note: caller must check 'emsg_not_now()' before calling this. |
7 | 624 */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
625 static int |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
626 emsg_core(char_u *s) |
7 | 627 { |
628 int attr; | |
629 char_u *p; | |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
630 int r; |
7 | 631 #ifdef FEAT_EVAL |
632 int ignore = FALSE; | |
633 int severe; | |
634 #endif | |
635 | |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
636 #ifdef FEAT_EVAL |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
637 // When testing some errors are turned into a normal message. |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
638 if (ignore_error(s)) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
639 // don't call msg() if it results in a dialog |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
640 return msg_use_printf() ? FALSE : msg((char *)s); |
11006
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
641 #endif |
b3601a8eb679
patch 8.0.0392: GUI test fails with Athena and Motif
Christian Brabandt <cb@256bit.org>
parents:
10589
diff
changeset
|
642 |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18931
diff
changeset
|
643 ++called_emsg; |
7 | 644 |
645 #ifdef FEAT_EVAL | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
646 // If "emsg_severe" is TRUE: When an error exception is to be thrown, |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
647 // prefer this message over previous messages for the same command. |
7 | 648 severe = emsg_severe; |
649 emsg_severe = FALSE; | |
650 #endif | |
651 | |
839 | 652 if (!emsg_off || vim_strchr(p_debug, 't') != NULL) |
7 | 653 { |
654 #ifdef FEAT_EVAL | |
655 /* | |
656 * Cause a throw of an error exception if appropriate. Don't display | |
657 * the error message in this case. (If no matching catch clause will | |
658 * be found, the message will be displayed later on.) "ignore" is set | |
659 * when the message should be ignored completely (used for the | |
660 * interrupt message). | |
661 */ | |
662 if (cause_errthrow(s, severe, &ignore) == TRUE) | |
663 { | |
664 if (!ignore) | |
15079
a527110d5f56
patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
665 ++did_emsg; |
7 | 666 return TRUE; |
667 } | |
668 | |
22742
f7f2d73ff85e
patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
669 if (in_assert_fails && emsg_assert_fails_msg == NULL) |
21859
3e5d0832a2e7
patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
21493
diff
changeset
|
670 { |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21192
diff
changeset
|
671 emsg_assert_fails_msg = vim_strsave(s); |
21859
3e5d0832a2e7
patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
21493
diff
changeset
|
672 emsg_assert_fails_lnum = SOURCING_LNUM; |
22163
b6d36f0b4f03
patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents:
21859
diff
changeset
|
673 vim_free(emsg_assert_fails_context); |
b6d36f0b4f03
patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents:
21859
diff
changeset
|
674 emsg_assert_fails_context = vim_strsave( |
b6d36f0b4f03
patch 8.2.1631: test_fails() does not check the context of the line number
Bram Moolenaar <Bram@vim.org>
parents:
21859
diff
changeset
|
675 SOURCING_NAME == NULL ? (char_u *)"" : SOURCING_NAME); |
21859
3e5d0832a2e7
patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
21493
diff
changeset
|
676 } |
21265
6a4806e326dd
patch 8.2.1183: assert_fails() checks the last error message
Bram Moolenaar <Bram@vim.org>
parents:
21192
diff
changeset
|
677 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
678 // set "v:errmsg", also when using ":silent! cmd" |
7 | 679 set_vim_var_string(VV_ERRMSG, s, -1); |
680 #endif | |
681 | |
682 /* | |
1619 | 683 * When using ":silent! cmd" ignore error messages. |
7 | 684 * But do write it to the redirection file. |
685 */ | |
686 if (emsg_silent != 0) | |
687 { | |
24406
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
688 #ifdef FEAT_EVAL |
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
689 ++did_emsg_silent; |
a26f0fa12845
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!"
Bram Moolenaar <Bram@vim.org>
parents:
23952
diff
changeset
|
690 #endif |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
691 if (emsg_noredir == 0) |
7 | 692 { |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
693 msg_start(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
694 p = get_emsg_source(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
695 if (p != NULL) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
696 { |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
697 STRCAT(p, "\n"); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
698 redir_write(p, -1); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
699 vim_free(p); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
700 } |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
701 p = get_emsg_lnum(); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
702 if (p != NULL) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
703 { |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
704 STRCAT(p, "\n"); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
705 redir_write(p, -1); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
706 vim_free(p); |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
707 } |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
708 redir_write(s, -1); |
7 | 709 } |
23102
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
710 #ifdef FEAT_EVAL |
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
711 // Only increment did_emsg_def when :silent! wasn't used inside the |
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
712 // :def function. |
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
713 if (emsg_silent == emsg_silent_def) |
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
714 ++did_emsg_def; |
3239b0f3c592
patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents:
23090
diff
changeset
|
715 #endif |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
716 #ifdef FEAT_JOB_CHANNEL |
17262
041156ce1d22
patch 8.1.1630: various small problems
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
717 ch_log(NULL, "ERROR silent: %s", (char *)s); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
718 #endif |
7 | 719 return TRUE; |
720 } | |
721 | |
10589
b0c9c1a05054
patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents:
10426
diff
changeset
|
722 ex_exitval = 1; |
b0c9c1a05054
patch 8.0.0184: when an error is caught Vim still exits with non-zero result
Christian Brabandt <cb@256bit.org>
parents:
10426
diff
changeset
|
723 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
724 // Reset msg_silent, an error causes messages to be switched back on. |
7 | 725 msg_silent = 0; |
726 cmd_silent = FALSE; | |
727 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
728 if (global_busy) // break :global command |
7 | 729 ++global_busy; |
730 | |
731 if (p_eb) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
732 beep_flush(); // also includes flush_buffers() |
7 | 733 else |
14909
c97b4b537572
patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
734 flush_buffers(FLUSH_MINIMAL); // flush internal buffers |
15079
a527110d5f56
patch 8.1.0550: expression evaluation may repeat an error message
Bram Moolenaar <Bram@vim.org>
parents:
14909
diff
changeset
|
735 ++did_emsg; // flag for DoOneCmd() |
12375
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
736 #ifdef FEAT_EVAL |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
737 did_uncaught_emsg = TRUE; |
ab0d827151a1
patch 8.0.1067: try/catch in timer does not prevent it from being stopped
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
738 #endif |
7 | 739 } |
740 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
741 emsg_on_display = TRUE; // remember there is an error message |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
742 ++msg_scroll; // don't overwrite a previous message |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
743 attr = HL_ATTR(HLF_E); // set highlight mode for error messages |
539 | 744 if (msg_scrolled != 0) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
745 need_wait_return = TRUE; // needed in case emsg() is called after |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
746 // wait_return has reset need_wait_return |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
747 // and a redraw is expected because |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
748 // msg_scrolled is non-zero |
7 | 749 |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
750 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
751 emsg_to_channel_log = TRUE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
752 #endif |
7 | 753 /* |
754 * Display name and line number for the source of the error. | |
755 */ | |
16 | 756 msg_source(attr); |
7 | 757 |
758 /* | |
759 * Display the error message itself. | |
760 */ | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
761 msg_nowait = FALSE; // wait for this msg |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
762 r = msg_attr((char *)s, attr); |
10426
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
763 |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
764 #ifdef FEAT_JOB_CHANNEL |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
765 emsg_to_channel_log = FALSE; |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
766 #endif |
acfc83aca8ee
commit https://github.com/vim/vim/commit/958dc6923d341390531888058495569d73c356c3
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
767 return r; |
7 | 768 } |
769 | |
770 /* | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
771 * Print an error message. |
7 | 772 */ |
773 int | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
774 emsg(char *s) |
7 | 775 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
776 // Skip this if not giving error messages at the moment. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
777 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
778 return emsg_core((char_u *)s); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
779 return TRUE; // no error messages at the moment |
7 | 780 } |
781 | |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
782 #ifndef PROTO // manual proto with __attribute__ |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
783 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
784 * Print an error message with format string and variable arguments. |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
785 * Note: caller must not pass 'IObuff' as 1st argument. |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
786 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
787 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
788 semsg(const char *s, ...) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
789 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
790 // Skip this if not giving error messages at the moment. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
791 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
792 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
793 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
794 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
795 // Very early in initialisation and already something wrong, just |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
796 // give the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
797 return emsg_core((char_u *)s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
798 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
799 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
800 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
801 va_list ap; |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
802 |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
803 va_start(ap, s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
804 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
805 va_end(ap); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
806 return emsg_core(IObuff); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
807 } |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
808 } |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
809 return TRUE; // no error messages at the moment |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
810 } |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
811 #endif |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
812 |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
813 /* |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
814 * Same as emsg(...), but abort on error when ABORT_ON_INTERNAL_ERROR is |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
815 * defined. It is used for internal errors only, so that they can be |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
816 * detected when fuzzing vim. |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
817 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
818 void |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
819 iemsg(char *s) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
820 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
821 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
822 emsg_core((char_u *)s); |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
823 #ifdef ABORT_ON_INTERNAL_ERROR |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
824 abort(); |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
825 #endif |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
826 } |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
827 |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
828 #ifndef PROTO // manual proto with __attribute__ |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
829 /* |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
830 * Same as semsg(...) but abort on error when ABORT_ON_INTERNAL_ERROR is |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
831 * defined. It is used for internal errors only, so that they can be |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
832 * detected when fuzzing vim. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
833 * Note: caller must not pass 'IObuff' as 1st argument. |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
834 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
835 void |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
836 siemsg(const char *s, ...) |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
837 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
838 if (!emsg_not_now()) |
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
839 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
840 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
841 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
842 // Very early in initialisation and already something wrong, just |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
843 // give the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
844 emsg_core((char_u *)s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
845 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
846 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
847 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
848 va_list ap; |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
849 |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
850 va_start(ap, s); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
851 vim_vsnprintf((char *)IObuff, IOSIZE, s, ap); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
852 va_end(ap); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
853 emsg_core(IObuff); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
854 } |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
855 } |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
856 # ifdef ABORT_ON_INTERNAL_ERROR |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
857 abort(); |
15896
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
858 # endif |
ac080f6a4db8
patch 8.1.0954: arguments of semsg() and siemsg() are not checked
Bram Moolenaar <Bram@vim.org>
parents:
15868
diff
changeset
|
859 } |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
860 #endif |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
861 |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
862 /* |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
863 * Give an "Internal error" message. |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
864 */ |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
865 void |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
866 internal_error(char *where) |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
867 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
868 siemsg(_(e_intern2), where); |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
869 } |
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10158
diff
changeset
|
870 |
19554
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
871 /* |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
872 * Like internal_error() but do not call abort(), to avoid tests using |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
873 * test_unknown() and test_void() causing Vim to exit. |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
874 */ |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
875 void |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
876 internal_error_no_abort(char *where) |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
877 { |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
878 semsg(_(e_intern2), where); |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
879 } |
b38d73f36467
patch 8.2.0334: abort called when using test_void()
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
880 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
881 // emsg3() and emsgn() are in misc2.c to avoid warnings for the prototypes. |
7 | 882 |
167 | 883 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
884 emsg_invreg(int name) |
167 | 885 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
886 semsg(_("E354: Invalid register name: '%s'"), transchar(name)); |
167 | 887 } |
888 | |
7 | 889 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
890 * Give an error message which contains %s for "name[len]". |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
891 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
892 void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
893 emsg_namelen(char *msg, char_u *name, int len) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
894 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
895 char_u *copy = vim_strnsave((char_u *)name, len); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
896 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
897 semsg(msg, copy == NULL ? "NULL" : (char *)copy); |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19615
diff
changeset
|
898 vim_free(copy); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
899 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
900 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
18999
diff
changeset
|
901 /* |
7 | 902 * Like msg(), but truncate to a single line if p_shm contains 't', or when |
903 * "force" is TRUE. This truncates in another way as for normal messages. | |
904 * Careful: The string may be changed by msg_may_trunc()! | |
905 * Returns a pointer to the printed message, if wait_return() not called. | |
906 */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
907 char * |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
908 msg_trunc_attr(char *s, int force, int attr) |
7 | 909 { |
910 int n; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
911 char *ts; |
7 | 912 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
913 // Add message to history before truncating |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
914 add_msg_hist((char_u *)s, -1, attr); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
915 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
916 ts = (char *)msg_may_trunc(force, (char_u *)s); |
7 | 917 |
918 msg_hist_off = TRUE; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
919 n = msg_attr(ts, attr); |
7 | 920 msg_hist_off = FALSE; |
921 | |
922 if (n) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
923 return ts; |
7 | 924 return NULL; |
925 } | |
926 | |
927 /* | |
928 * Check if message "s" should be truncated at the start (for filenames). | |
929 * Return a pointer to where the truncated message starts. | |
930 * Note: May change the message by replacing a character with '<'. | |
931 */ | |
932 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
933 msg_may_trunc(int force, char_u *s) |
7 | 934 { |
935 int n; | |
936 int room; | |
937 | |
938 room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1; | |
939 if ((force || (shortmess(SHM_TRUNC) && !exmode_active)) | |
940 && (n = (int)STRLEN(s) - room) > 0) | |
941 { | |
942 if (has_mbyte) | |
943 { | |
944 int size = vim_strsize(s); | |
945 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
946 // There may be room anyway when there are multibyte chars. |
615 | 947 if (size <= room) |
948 return s; | |
949 | |
7 | 950 for (n = 0; size >= room; ) |
951 { | |
952 size -= (*mb_ptr2cells)(s + n); | |
474 | 953 n += (*mb_ptr2len)(s + n); |
7 | 954 } |
955 --n; | |
956 } | |
957 s += n; | |
958 *s = '<'; | |
959 } | |
960 return s; | |
961 } | |
962 | |
963 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
964 add_msg_hist( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
965 char_u *s, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
966 int len, // -1 for undetermined length |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
967 int attr) |
7 | 968 { |
969 struct msg_hist *p; | |
970 | |
971 if (msg_hist_off || msg_silent != 0) | |
972 return; | |
973 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
974 // Don't let the message history get too big |
625 | 975 while (msg_hist_len > MAX_MSG_HIST_LEN) |
355 | 976 (void)delete_first_msg(); |
977 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
978 // allocate an entry and add the message at the end of the history |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
979 p = ALLOC_ONE(struct msg_hist); |
7 | 980 if (p != NULL) |
981 { | |
982 if (len < 0) | |
983 len = (int)STRLEN(s); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
984 // remove leading and trailing newlines |
7 | 985 while (len > 0 && *s == '\n') |
986 { | |
987 ++s; | |
988 --len; | |
989 } | |
990 while (len > 0 && s[len - 1] == '\n') | |
991 --len; | |
992 p->msg = vim_strnsave(s, len); | |
993 p->next = NULL; | |
994 p->attr = attr; | |
995 if (last_msg_hist != NULL) | |
996 last_msg_hist->next = p; | |
997 last_msg_hist = p; | |
998 if (first_msg_hist == NULL) | |
999 first_msg_hist = last_msg_hist; | |
1000 ++msg_hist_len; | |
1001 } | |
1002 } | |
1003 | |
1004 /* | |
355 | 1005 * Delete the first (oldest) message from the history. |
1006 * Returns FAIL if there are no messages. | |
1007 */ | |
1008 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1009 delete_first_msg(void) |
355 | 1010 { |
1011 struct msg_hist *p; | |
1012 | |
1013 if (msg_hist_len <= 0) | |
1014 return FAIL; | |
1015 p = first_msg_hist; | |
1016 first_msg_hist = p->next; | |
1619 | 1017 if (first_msg_hist == NULL) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1018 last_msg_hist = NULL; // history is empty |
355 | 1019 vim_free(p->msg); |
1020 vim_free(p); | |
1021 --msg_hist_len; | |
1022 return OK; | |
1023 } | |
1024 | |
1025 /* | |
7 | 1026 * ":messages" command. |
1027 */ | |
1028 void | |
8901
b4dad96ade29
commit https://github.com/vim/vim/commit/52196b2dbe3b64b5054e1df3d3aa8fc65e30addc
Christian Brabandt <cb@256bit.org>
parents:
8897
diff
changeset
|
1029 ex_messages(exarg_T *eap) |
7 | 1030 { |
1031 struct msg_hist *p; | |
1032 char_u *s; | |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1033 int c = 0; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1034 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1035 if (STRCMP(eap->arg, "clear") == 0) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1036 { |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1037 int keep = eap->addr_count == 0 ? 0 : eap->line2; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1038 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1039 while (msg_hist_len > keep) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1040 (void)delete_first_msg(); |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1041 return; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1042 } |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1043 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1044 if (*eap->arg != NUL) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1045 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
1046 emsg(_(e_invarg)); |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1047 return; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1048 } |
7 | 1049 |
1050 msg_hist_off = TRUE; | |
1051 | |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1052 p = first_msg_hist; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1053 if (eap->addr_count != 0) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1054 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1055 // Count total messages |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1056 for (; p != NULL && !got_int; p = p->next) |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1057 c++; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1058 |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1059 c -= eap->line2; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1060 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1061 // Skip without number of messages specified |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1062 for (p = first_msg_hist; p != NULL && !got_int && c > 0; |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1063 p = p->next, c--); |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1064 } |
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1065 |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1066 if (p == first_msg_hist) |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1067 { |
20162
7196cd9d8397
patch 8.2.0636: :messages does not show the maintainer when $LANG is unset
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1068 #ifdef FEAT_MULTI_LANG |
7196cd9d8397
patch 8.2.0636: :messages does not show the maintainer when $LANG is unset
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1069 s = get_mess_lang(); |
7196cd9d8397
patch 8.2.0636: :messages does not show the maintainer when $LANG is unset
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1070 #else |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1071 s = mch_getenv((char_u *)"LANG"); |
20162
7196cd9d8397
patch 8.2.0636: :messages does not show the maintainer when $LANG is unset
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1072 #endif |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1073 if (s != NULL && *s != NUL) |
14210
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1074 // The next comment is extracted by xgettext and put in po file for |
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1075 // translators to read. |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1076 msg_attr( |
14210
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1077 // Translator: Please replace the name and email address |
1681178c4434
patch 8.1.0122: translators don't always understand the maintainer message
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
1078 // with the appropriate text for your translation. |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1079 _("Messages maintainer: Bram Moolenaar <Bram@vim.org>"), |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1080 HL_ATTR(HLF_T)); |
8905
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1081 } |
9200836eee15
commit https://github.com/vim/vim/commit/bea1ede1c59a11ca5bf9d91cd30b7b2937b9fb41
Christian Brabandt <cb@256bit.org>
parents:
8901
diff
changeset
|
1082 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1083 // Display what was not skipped. |
8897
a410390e340b
commit https://github.com/vim/vim/commit/451f849fd6282a4facd4f0f58af62837443fb5a6
Christian Brabandt <cb@256bit.org>
parents:
8627
diff
changeset
|
1084 for (; p != NULL && !got_int; p = p->next) |
7 | 1085 if (p->msg != NULL) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1086 msg_attr((char *)p->msg, p->attr); |
7 | 1087 |
1088 msg_hist_off = FALSE; | |
1089 } | |
1090 | |
28 | 1091 #if defined(FEAT_CON_DIALOG) || defined(FIND_REPLACE_DIALOG) || defined(PROTO) |
7 | 1092 /* |
1093 * Call this after prompting the user. This will avoid a hit-return message | |
1094 * and a delay. | |
1095 */ | |
28 | 1096 void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1097 msg_end_prompt(void) |
7 | 1098 { |
1099 need_wait_return = FALSE; | |
1100 emsg_on_display = FALSE; | |
1101 cmdline_row = msg_row; | |
1102 msg_col = 0; | |
1103 msg_clr_eos(); | |
3240 | 1104 lines_left = -1; |
7 | 1105 } |
1106 #endif | |
1107 | |
1108 /* | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1109 * Wait for the user to hit a key (normally Enter). |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1110 * If "redraw" is TRUE, clear and redraw the screen. |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1111 * If "redraw" is FALSE, just redraw the screen. |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1112 * If "redraw" is -1, don't redraw at all. |
7 | 1113 */ |
1114 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1115 wait_return(int redraw) |
7 | 1116 { |
1117 int c; | |
1118 int oldState; | |
1119 int tmpState; | |
1120 int had_got_int; | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1121 int save_reg_recording; |
5430 | 1122 FILE *save_scriptout; |
7 | 1123 |
1124 if (redraw == TRUE) | |
1125 must_redraw = CLEAR; | |
1126 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1127 // If using ":silent cmd", don't wait for a return. Also don't set |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1128 // need_wait_return to do it later. |
7 | 1129 if (msg_silent != 0) |
1130 return; | |
1131 | |
2723 | 1132 /* |
1133 * When inside vgetc(), we can't wait for a typed character at all. | |
1134 * With the global command (and some others) we only need one return at | |
1135 * the end. Adjust cmdline_row to avoid the next message overwriting the | |
1136 * last one. | |
1137 */ | |
822 | 1138 if (vgetc_busy > 0) |
7 | 1139 return; |
2723 | 1140 need_wait_return = TRUE; |
7 | 1141 if (no_wait_return) |
1142 { | |
1143 if (!exmode_active) | |
1144 cmdline_row = msg_row; | |
1145 return; | |
1146 } | |
1147 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1148 redir_off = TRUE; // don't redirect this message |
7 | 1149 oldState = State; |
1150 if (quit_more) | |
1151 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1152 c = CAR; // just pretend CR was hit |
7 | 1153 quit_more = FALSE; |
1154 got_int = FALSE; | |
1155 } | |
1156 else if (exmode_active) | |
1157 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1158 msg_puts(" "); // make sure the cursor is on the right line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1159 c = CAR; // no need for a return in ex mode |
7 | 1160 got_int = FALSE; |
1161 } | |
1162 else | |
1163 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1164 // Make sure the hit-return prompt is on screen when 'guioptions' was |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1165 // just changed. |
7 | 1166 screenalloc(FALSE); |
1167 | |
1168 State = HITRETURN; | |
1169 setmouse(); | |
1170 #ifdef USE_ON_FLY_SCROLL | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1171 dont_scroll = TRUE; // disallow scrolling here |
7 | 1172 #endif |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
1173 cmdline_row = msg_row; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
1174 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1175 // Avoid the sequence that the user types ":" at the hit-return prompt |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1176 // to start an Ex command, but the file-changed dialog gets in the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1177 // way. |
4325 | 1178 if (need_check_timestamps) |
1179 check_timestamps(FALSE); | |
1180 | |
7 | 1181 hit_return_msg(); |
1182 | |
1183 do | |
1184 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1185 // Remember "got_int", if it is set vgetc() probably returns a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1186 // CTRL-C, but we need to loop then. |
7 | 1187 had_got_int = got_int; |
280 | 1188 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1189 // Don't do mappings here, we put the character back in the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1190 // typeahead buffer. |
280 | 1191 ++no_mapping; |
1192 ++allow_keys; | |
5430 | 1193 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1194 // Temporarily disable Recording. If Recording is active, the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1195 // character will be recorded later, since it will be added to the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1196 // typebuf after the loop |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1197 save_reg_recording = reg_recording; |
5430 | 1198 save_scriptout = scriptout; |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1199 reg_recording = 0; |
5430 | 1200 scriptout = NULL; |
7 | 1201 c = safe_vgetc(); |
216 | 1202 if (had_got_int && !global_busy) |
7 | 1203 got_int = FALSE; |
280 | 1204 --no_mapping; |
1205 --allow_keys; | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13802
diff
changeset
|
1206 reg_recording = save_reg_recording; |
5430 | 1207 scriptout = save_scriptout; |
280 | 1208 |
7 | 1209 #ifdef FEAT_CLIPBOARD |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1210 // Strange way to allow copying (yanking) a modeless selection at |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1211 // the hit-enter prompt. Use CTRL-Y, because the same is used in |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1212 // Cmdline-mode and it's harmless when there is no selection. |
7 | 1213 if (c == Ctrl_Y && clip_star.state == SELECT_DONE) |
1214 { | |
1215 clip_copy_modeless_selection(TRUE); | |
1216 c = K_IGNORE; | |
1217 } | |
1218 #endif | |
1381 | 1219 |
698 | 1220 /* |
1221 * Allow scrolling back in the messages. | |
1222 * Also accept scroll-down commands when messages fill the screen, | |
1223 * to avoid that typing one 'j' too many makes the messages | |
1224 * disappear. | |
1225 */ | |
1226 if (p_more && !p_cp) | |
446 | 1227 { |
4234 | 1228 if (c == 'b' || c == 'k' || c == 'u' || c == 'g' |
1229 || c == K_UP || c == K_PAGEUP) | |
446 | 1230 { |
4234 | 1231 if (msg_scrolled > Rows) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1232 // scroll back to show older messages |
4234 | 1233 do_more_prompt(c); |
1234 else | |
1235 { | |
1236 msg_didout = FALSE; | |
1237 c = K_IGNORE; | |
1238 msg_col = | |
1239 #ifdef FEAT_RIGHTLEFT | |
1240 cmdmsg_rl ? Columns - 1 : | |
1241 #endif | |
1242 0; | |
1243 } | |
698 | 1244 if (quit_more) |
1245 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1246 c = CAR; // just pretend CR was hit |
698 | 1247 quit_more = FALSE; |
1248 got_int = FALSE; | |
1249 } | |
5290
059c8a4b103f
updated for version 7.4b.021
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1250 else if (c != K_IGNORE) |
698 | 1251 { |
1252 c = K_IGNORE; | |
1253 hit_return_msg(); | |
1254 } | |
446 | 1255 } |
698 | 1256 else if (msg_scrolled > Rows - 2 |
4234 | 1257 && (c == 'j' || c == 'd' || c == 'f' |
1258 || c == K_DOWN || c == K_PAGEDOWN)) | |
446 | 1259 c = K_IGNORE; |
1260 } | |
7 | 1261 } while ((had_got_int && c == Ctrl_C) |
1262 || c == K_IGNORE | |
1263 #ifdef FEAT_GUI | |
1264 || c == K_VER_SCROLLBAR || c == K_HOR_SCROLLBAR | |
1265 #endif | |
1266 || c == K_LEFTDRAG || c == K_LEFTRELEASE | |
1267 || c == K_MIDDLEDRAG || c == K_MIDDLERELEASE | |
1268 || c == K_RIGHTDRAG || c == K_RIGHTRELEASE | |
2409
0ca06a92adfb
Add support for horizontal scroll wheel. (Bjorn Winckler)
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1269 || c == K_MOUSELEFT || c == K_MOUSERIGHT |
7 | 1270 || c == K_MOUSEDOWN || c == K_MOUSEUP |
12865
ebb4f6c93598
patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents:
12716
diff
changeset
|
1271 || c == K_MOUSEMOVE |
7 | 1272 || (!mouse_has(MOUSE_RETURN) |
1273 && mouse_row < msg_row | |
1274 && (c == K_LEFTMOUSE | |
1275 || c == K_MIDDLEMOUSE | |
1276 || c == K_RIGHTMOUSE | |
1277 || c == K_X1MOUSE | |
1278 || c == K_X2MOUSE)) | |
1279 ); | |
1280 ui_breakcheck(); | |
1281 /* | |
1282 * Avoid that the mouse-up event causes visual mode to start. | |
1283 */ | |
1284 if (c == K_LEFTMOUSE || c == K_MIDDLEMOUSE || c == K_RIGHTMOUSE | |
1285 || c == K_X1MOUSE || c == K_X2MOUSE) | |
1286 (void)jump_to_mouse(MOUSE_SETPOS, NULL, 0); | |
18354
9f51d0cef8da
patch 8.1.2171: mouse support not always available
Bram Moolenaar <Bram@vim.org>
parents:
18309
diff
changeset
|
1287 else if (vim_strchr((char_u *)"\r\n ", c) == NULL && c != Ctrl_C) |
7 | 1288 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1289 // Put the character back in the typeahead buffer. Don't use the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1290 // stuff buffer, because lmaps wouldn't work. |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20162
diff
changeset
|
1291 ins_char_typebuf(vgetc_char, vgetc_mod_mask); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1292 do_redraw = TRUE; // need a redraw even though there is |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1293 // typeahead |
7 | 1294 } |
1295 } | |
1296 redir_off = FALSE; | |
1297 | |
1298 /* | |
1299 * If the user hits ':', '?' or '/' we get a command line from the next | |
1300 * line. | |
1301 */ | |
1302 if (c == ':' || c == '?' || c == '/') | |
1303 { | |
1304 if (!exmode_active) | |
1305 cmdline_row = msg_row; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1306 skip_redraw = TRUE; // skip redraw once |
7 | 1307 do_redraw = FALSE; |
14129
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1308 #ifdef FEAT_TERMINAL |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1309 skip_term_loop = TRUE; |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
1310 #endif |
7 | 1311 } |
1312 | |
1313 /* | |
1314 * If the window size changed set_shellsize() will redraw the screen. | |
1315 * Otherwise the screen is only redrawn if 'redraw' is set and no ':' | |
1316 * typed. | |
1317 */ | |
1318 tmpState = State; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1319 State = oldState; // restore State before set_shellsize |
7 | 1320 setmouse(); |
1321 msg_check(); | |
1322 | |
1323 #if defined(UNIX) || defined(VMS) | |
1324 /* | |
1325 * When switching screens, we need to output an extra newline on exit. | |
1326 */ | |
1327 if (swapping_screen() && !termcap_active) | |
1328 newline_on_exit = TRUE; | |
1329 #endif | |
1330 | |
1331 need_wait_return = FALSE; | |
1332 did_wait_return = TRUE; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1333 emsg_on_display = FALSE; // can delete error message now |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1334 lines_left = -1; // reset lines_left at next msg_start() |
7 | 1335 reset_last_sourcing(); |
1336 if (keep_msg != NULL && vim_strsize(keep_msg) >= | |
1337 (Rows - cmdline_row - 1) * Columns + sc_col) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1338 VIM_CLEAR(keep_msg); // don't redisplay message, it's too long |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1339 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1340 if (tmpState == SETWSIZE) // got resize event while in vgetc() |
7 | 1341 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1342 starttermcap(); // start termcap before redrawing |
7 | 1343 shell_resized(); |
1344 } | |
1345 else if (!skip_redraw | |
1346 && (redraw == TRUE || (msg_scrolled != 0 && redraw != -1))) | |
1347 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1348 starttermcap(); // start termcap before redrawing |
7 | 1349 redraw_later(VALID); |
1350 } | |
1351 } | |
1352 | |
1353 /* | |
1354 * Write the hit-return prompt. | |
1355 */ | |
1356 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1357 hit_return_msg(void) |
7 | 1358 { |
446 | 1359 int save_p_more = p_more; |
1360 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1361 p_more = FALSE; // don't want see this message when scrolling back |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1362 if (msg_didout) // start on a new line |
7 | 1363 msg_putchar('\n'); |
1364 if (got_int) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1365 msg_puts(_("Interrupt: ")); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1366 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1367 msg_puts_attr(_("Press ENTER or type command to continue"), HL_ATTR(HLF_R)); |
7 | 1368 if (!msg_use_printf()) |
1369 msg_clr_eos(); | |
446 | 1370 p_more = save_p_more; |
7 | 1371 } |
1372 | |
1373 /* | |
1374 * Set "keep_msg" to "s". Free the old value and check for NULL pointer. | |
1375 */ | |
1376 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1377 set_keep_msg(char_u *s, int attr) |
7 | 1378 { |
1379 vim_free(keep_msg); | |
1380 if (s != NULL && msg_silent == 0) | |
1381 keep_msg = vim_strsave(s); | |
1382 else | |
1383 keep_msg = NULL; | |
127 | 1384 keep_msg_more = FALSE; |
678 | 1385 keep_msg_attr = attr; |
7 | 1386 } |
1387 | |
678 | 1388 #if defined(FEAT_TERMRESPONSE) || defined(PROTO) |
1389 /* | |
1390 * If there currently is a message being displayed, set "keep_msg" to it, so | |
1391 * that it will be displayed again after redraw. | |
1392 */ | |
1393 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1394 set_keep_msg_from_hist(void) |
678 | 1395 { |
1396 if (keep_msg == NULL && last_msg_hist != NULL && msg_scrolled == 0 | |
1397 && (State & NORMAL)) | |
1398 set_keep_msg(last_msg_hist->msg, last_msg_hist->attr); | |
1399 } | |
1400 #endif | |
1401 | |
7 | 1402 /* |
1403 * Prepare for outputting characters in the command line. | |
1404 */ | |
1405 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1406 msg_start(void) |
7 | 1407 { |
1408 int did_return = FALSE; | |
1409 | |
2491
904cd1c26a1e
After entering a crypt key would need to hit return to continue.
Bram Moolenaar <bram@vim.org>
parents:
2409
diff
changeset
|
1410 if (!msg_silent) |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
1411 VIM_CLEAR(keep_msg); |
1619 | 1412 |
1413 #ifdef FEAT_EVAL | |
1414 if (need_clr_eos) | |
1415 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1416 // Halfway an ":echo" command and getting an (error) message: clear |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1417 // any text from the command. |
1619 | 1418 need_clr_eos = FALSE; |
1419 msg_clr_eos(); | |
1420 } | |
1421 #endif | |
1422 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1423 if (!msg_scroll && full_screen) // overwrite last message |
7 | 1424 { |
1425 msg_row = cmdline_row; | |
1426 msg_col = | |
1427 #ifdef FEAT_RIGHTLEFT | |
1428 cmdmsg_rl ? Columns - 1 : | |
1429 #endif | |
1430 0; | |
1431 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1432 else if (msg_didout) // start message on next line |
7 | 1433 { |
1434 msg_putchar('\n'); | |
1435 did_return = TRUE; | |
1436 if (exmode_active != EXMODE_NORMAL) | |
1437 cmdline_row = msg_row; | |
1438 } | |
1439 if (!msg_didany || lines_left < 0) | |
1440 msg_starthere(); | |
1441 if (msg_silent == 0) | |
1442 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1443 msg_didout = FALSE; // no output on current line yet |
7 | 1444 cursor_off(); |
1445 } | |
1446 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1447 // when redirecting, may need to start a new line. |
7 | 1448 if (!did_return) |
1449 redir_write((char_u *)"\n", -1); | |
1450 } | |
1451 | |
1452 /* | |
1453 * Note that the current msg position is where messages start. | |
1454 */ | |
1455 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1456 msg_starthere(void) |
7 | 1457 { |
1458 lines_left = cmdline_row; | |
1459 msg_didany = FALSE; | |
1460 } | |
1461 | |
1462 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1463 msg_putchar(int c) |
7 | 1464 { |
1465 msg_putchar_attr(c, 0); | |
1466 } | |
1467 | |
1468 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1469 msg_putchar_attr(int c, int attr) |
7 | 1470 { |
15551
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1471 char_u buf[MB_MAXBYTES + 1]; |
7 | 1472 |
1473 if (IS_SPECIAL(c)) | |
1474 { | |
1475 buf[0] = K_SPECIAL; | |
1476 buf[1] = K_SECOND(c); | |
1477 buf[2] = K_THIRD(c); | |
1478 buf[3] = NUL; | |
1479 } | |
1480 else | |
15551
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1481 buf[(*mb_char2bytes)(c, buf)] = NUL; |
b069a878bbeb
patch 8.1.0783: compiler warning for signed/unsigned
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1482 msg_puts_attr((char *)buf, attr); |
7 | 1483 } |
1484 | |
1485 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1486 msg_outnum(long n) |
7 | 1487 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1488 char buf[20]; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1489 |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1490 sprintf(buf, "%ld", n); |
7 | 1491 msg_puts(buf); |
1492 } | |
1493 | |
1494 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1495 msg_home_replace(char_u *fname) |
7 | 1496 { |
1497 msg_home_replace_attr(fname, 0); | |
1498 } | |
1499 | |
1500 #if defined(FEAT_FIND_ID) || defined(PROTO) | |
1501 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1502 msg_home_replace_hl(char_u *fname) |
7 | 1503 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1504 msg_home_replace_attr(fname, HL_ATTR(HLF_D)); |
7 | 1505 } |
1506 #endif | |
1507 | |
1508 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1509 msg_home_replace_attr(char_u *fname, int attr) |
7 | 1510 { |
1511 char_u *name; | |
1512 | |
1513 name = home_replace_save(NULL, fname); | |
1514 if (name != NULL) | |
1515 msg_outtrans_attr(name, attr); | |
1516 vim_free(name); | |
1517 } | |
1518 | |
1519 /* | |
1520 * Output 'len' characters in 'str' (including NULs) with translation | |
18829
eff8d8f72a82
patch 8.1.2402: typos and other small things
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1521 * if 'len' is -1, output up to a NUL character. |
7 | 1522 * Use attributes 'attr'. |
1523 * Return the number of characters it takes on the screen. | |
1524 */ | |
1525 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1526 msg_outtrans(char_u *str) |
7 | 1527 { |
1528 return msg_outtrans_attr(str, 0); | |
1529 } | |
1530 | |
1531 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1532 msg_outtrans_attr(char_u *str, int attr) |
7 | 1533 { |
1534 return msg_outtrans_len_attr(str, (int)STRLEN(str), attr); | |
1535 } | |
1536 | |
1537 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1538 msg_outtrans_len(char_u *str, int len) |
7 | 1539 { |
1540 return msg_outtrans_len_attr(str, len, 0); | |
1541 } | |
1542 | |
1543 /* | |
1544 * Output one character at "p". Return pointer to the next character. | |
1545 * Handles multi-byte characters. | |
1546 */ | |
1547 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1548 msg_outtrans_one(char_u *p, int attr) |
7 | 1549 { |
1550 int l; | |
1551 | |
474 | 1552 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 1553 { |
1554 msg_outtrans_len_attr(p, l, attr); | |
1555 return p + l; | |
1556 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1557 msg_puts_attr((char *)transchar_byte(*p), attr); |
7 | 1558 return p + 1; |
1559 } | |
1560 | |
1561 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1562 msg_outtrans_len_attr(char_u *msgstr, int len, int attr) |
7 | 1563 { |
1564 int retval = 0; | |
1565 char_u *str = msgstr; | |
1566 char_u *plain_start = msgstr; | |
1567 char_u *s; | |
1568 int mb_l; | |
1569 int c; | |
22592
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1570 int save_got_int = got_int; |
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1571 |
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1572 // Only quit when got_int was set in here. |
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1573 got_int = FALSE; |
7 | 1574 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1575 // if MSG_HIST flag set, add message to history |
7 | 1576 if (attr & MSG_HIST) |
1577 { | |
1578 add_msg_hist(str, len, attr); | |
1579 attr &= ~MSG_HIST; | |
1580 } | |
1581 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1582 // If the string starts with a composing character first draw a space on |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1583 // which the composing char can be drawn. |
7 | 1584 if (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr))) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1585 msg_puts_attr(" ", attr); |
7 | 1586 |
1587 /* | |
1588 * Go over the string. Special characters are translated and printed. | |
1589 * Normal characters are printed several at a time. | |
1590 */ | |
22592
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1591 while (--len >= 0 && !got_int) |
7 | 1592 { |
1593 if (enc_utf8) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1594 // Don't include composing chars after the end. |
474 | 1595 mb_l = utfc_ptr2len_len(str, len + 1); |
7 | 1596 else if (has_mbyte) |
474 | 1597 mb_l = (*mb_ptr2len)(str); |
7 | 1598 else |
1599 mb_l = 1; | |
1600 if (has_mbyte && mb_l > 1) | |
1601 { | |
1602 c = (*mb_ptr2char)(str); | |
1603 if (vim_isprintc(c)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1604 // printable multi-byte char: count the cells. |
7 | 1605 retval += (*mb_ptr2cells)(str); |
1606 else | |
1607 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1608 // unprintable multi-byte char: print the printable chars so |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1609 // far and the translation of the unprintable char. |
7 | 1610 if (str > plain_start) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1611 msg_puts_attr_len((char *)plain_start, |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1612 (int)(str - plain_start), attr); |
7 | 1613 plain_start = str + mb_l; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1614 msg_puts_attr((char *)transchar(c), |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1615 attr == 0 ? HL_ATTR(HLF_8) : attr); |
7 | 1616 retval += char2cells(c); |
1617 } | |
1618 len -= mb_l - 1; | |
1619 str += mb_l; | |
1620 } | |
1621 else | |
1622 { | |
1623 s = transchar_byte(*str); | |
1624 if (s[1] != NUL) | |
1625 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1626 // unprintable char: print the printable chars so far and the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1627 // translation of the unprintable char. |
7 | 1628 if (str > plain_start) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1629 msg_puts_attr_len((char *)plain_start, |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1630 (int)(str - plain_start), attr); |
7 | 1631 plain_start = str + 1; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1632 msg_puts_attr((char *)s, attr == 0 ? HL_ATTR(HLF_8) : attr); |
1668 | 1633 retval += (int)STRLEN(s); |
7 | 1634 } |
1663 | 1635 else |
1636 ++retval; | |
7 | 1637 ++str; |
1638 } | |
1639 } | |
1640 | |
22592
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1641 if (str > plain_start && !got_int) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1642 // print the printable chars at the end |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1643 msg_puts_attr_len((char *)plain_start, (int)(str - plain_start), attr); |
7 | 1644 |
22592
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1645 got_int |= save_got_int; |
fb5546aa6817
patch 8.2.1844: using "q" at the more prompt doesn't stop a long message
Bram Moolenaar <Bram@vim.org>
parents:
22584
diff
changeset
|
1646 |
7 | 1647 return retval; |
1648 } | |
1649 | |
1650 #if defined(FEAT_QUICKFIX) || defined(PROTO) | |
1651 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1652 msg_make(char_u *arg) |
7 | 1653 { |
1654 int i; | |
1655 static char_u *str = (char_u *)"eeffoc", *rs = (char_u *)"Plon#dqg#vxjduB"; | |
1656 | |
1657 arg = skipwhite(arg); | |
1658 for (i = 5; *arg && i >= 0; --i) | |
1659 if (*arg++ != str[i]) | |
1660 break; | |
1661 if (i < 0) | |
1662 { | |
1663 msg_putchar('\n'); | |
1664 for (i = 0; rs[i]; ++i) | |
1665 msg_putchar(rs[i] - 3); | |
1666 } | |
1667 } | |
1668 #endif | |
1669 | |
1670 /* | |
18829
eff8d8f72a82
patch 8.1.2402: typos and other small things
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
1671 * Output the string 'str' up to a NUL character. |
7 | 1672 * Return the number of characters it takes on the screen. |
1673 * | |
1674 * If K_SPECIAL is encountered, then it is taken in conjunction with the | |
1675 * following character and shown as <F1>, <S-Up> etc. Any other character | |
1676 * which is not printable shown in <> form. | |
1677 * If 'from' is TRUE (lhs of a mapping), a space is shown as <Space>. | |
1678 * If a character is displayed in one of these special ways, is also | |
1679 * highlighted (its highlight name is '8' in the p_hl variable). | |
1680 * Otherwise characters are not highlighted. | |
1681 * This function is used to show mappings, where we want to see how to type | |
1682 * the character/string -- webb | |
1683 */ | |
1684 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1685 msg_outtrans_special( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1686 char_u *strstart, |
16393
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1687 int from, // TRUE for lhs of a mapping |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
1688 int maxlen) // screen columns, 0 for unlimited |
7 | 1689 { |
1690 char_u *str = strstart; | |
1691 int retval = 0; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1692 char *text; |
7 | 1693 int attr; |
1694 int len; | |
1695 | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1696 attr = HL_ATTR(HLF_8); |
7 | 1697 while (*str != NUL) |
1698 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1699 // Leading and trailing spaces need to be displayed in <> form. |
7 | 1700 if ((str == strstart || str[1] == NUL) && *str == ' ') |
1701 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1702 text = "<Space>"; |
7 | 1703 ++str; |
1704 } | |
1705 else | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1706 text = (char *)str2special(&str, from); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1707 len = vim_strsize((char_u *)text); |
16393
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1708 if (maxlen > 0 && retval + len >= maxlen) |
c1c25e2523a6
patch 8.1.1201: output of :command is hard to read
Bram Moolenaar <Bram@vim.org>
parents:
16054
diff
changeset
|
1709 break; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1710 // Highlight special keys |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1711 msg_puts_attr(text, len > 1 |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1712 && (*mb_ptr2len)((char_u *)text) <= 1 ? attr : 0); |
7 | 1713 retval += len; |
1714 } | |
1715 return retval; | |
1716 } | |
1717 | |
2610 | 1718 #if defined(FEAT_EVAL) || defined(PROTO) |
1719 /* | |
1720 * Return the lhs or rhs of a mapping, with the key codes turned into printable | |
1721 * strings, in an allocated string. | |
1722 */ | |
1723 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1724 str2special_save( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1725 char_u *str, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1726 int is_lhs) // TRUE for lhs, FALSE for rhs |
2610 | 1727 { |
1728 garray_T ga; | |
1729 char_u *p = str; | |
1730 | |
1731 ga_init2(&ga, 1, 40); | |
1732 while (*p != NUL) | |
1733 ga_concat(&ga, str2special(&p, is_lhs)); | |
1734 ga_append(&ga, NUL); | |
1735 return (char_u *)ga.ga_data; | |
1736 } | |
1737 #endif | |
1738 | |
7 | 1739 /* |
1740 * Return the printable string for the key codes at "*sp". | |
1741 * Used for translating the lhs or rhs of a mapping to printable chars. | |
1742 * Advances "sp" to the next code. | |
1743 */ | |
1744 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1745 str2special( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1746 char_u **sp, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1747 int from) // TRUE for lhs of mapping |
7 | 1748 { |
1749 int c; | |
1750 static char_u buf[7]; | |
1751 char_u *str = *sp; | |
1752 int modifiers = 0; | |
1753 int special = FALSE; | |
1754 | |
1755 if (has_mbyte) | |
1756 { | |
1757 char_u *p; | |
1758 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1759 // Try to un-escape a multi-byte character. Return the un-escaped |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1760 // string if it is a multi-byte character. |
7 | 1761 p = mb_unescape(sp); |
1762 if (p != NULL) | |
1763 return p; | |
1764 } | |
1765 | |
1766 c = *str; | |
1767 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1768 { | |
1769 if (str[1] == KS_MODIFIER) | |
1770 { | |
1771 modifiers = str[2]; | |
1772 str += 3; | |
1773 c = *str; | |
1774 } | |
1775 if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL) | |
1776 { | |
1777 c = TO_SPECIAL(str[1], str[2]); | |
1778 str += 2; | |
1779 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1780 if (IS_SPECIAL(c) || modifiers) // special key |
7 | 1781 special = TRUE; |
1782 } | |
1783 | |
3024 | 1784 if (has_mbyte && !IS_SPECIAL(c)) |
7 | 1785 { |
3072 | 1786 int len = (*mb_ptr2len)(str); |
3024 | 1787 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1788 // For multi-byte characters check for an illegal byte. |
3024 | 1789 if (has_mbyte && MB_BYTE2LEN(*str) > len) |
1790 { | |
20782
c4bce986c31a
patch 8.2.0943: displaying ^M or ^J depends on current buffer
Bram Moolenaar <Bram@vim.org>
parents:
20571
diff
changeset
|
1791 transchar_nonprint(curbuf, buf, c); |
3024 | 1792 *sp = str + 1; |
1793 return buf; | |
1794 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1795 // Since 'special' is TRUE the multi-byte character 'c' will be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1796 // processed by get_special_key_name() |
3072 | 1797 c = (*mb_ptr2char)(str); |
1798 *sp = str + len; | |
7 | 1799 } |
3024 | 1800 else |
1801 *sp = str + 1; | |
7 | 1802 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1803 // Make unprintable characters in <> form, also <M-Space> and <Tab>. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1804 // Use <Space> only for lhs of a mapping. |
7 | 1805 if (special || char2cells(c) > 1 || (from && c == ' ')) |
1806 return get_special_key_name(c, modifiers); | |
1807 buf[0] = c; | |
1808 buf[1] = NUL; | |
1809 return buf; | |
1810 } | |
1811 | |
1812 /* | |
1813 * Translate a key sequence into special key names. | |
1814 */ | |
1815 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1816 str2specialbuf(char_u *sp, char_u *buf, int len) |
7 | 1817 { |
1818 char_u *s; | |
1819 | |
1820 *buf = NUL; | |
1821 while (*sp) | |
1822 { | |
1823 s = str2special(&sp, FALSE); | |
1824 if ((int)(STRLEN(s) + STRLEN(buf)) < len) | |
1825 STRCAT(buf, s); | |
1826 } | |
1827 } | |
1828 | |
1829 /* | |
1830 * print line for :print or :list command | |
1831 */ | |
1832 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1833 msg_prt_line(char_u *s, int list) |
7 | 1834 { |
1835 int c; | |
1836 int col = 0; | |
1837 int n_extra = 0; | |
1838 int c_extra = 0; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1839 int c_final = 0; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1840 char_u *p_extra = NULL; // init to make SASC shut up |
7 | 1841 int n; |
1059 | 1842 int attr = 0; |
7 | 1843 char_u *trail = NULL; |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1844 char_u *lead = NULL; |
7 | 1845 int l; |
1846 char_u buf[MB_MAXBYTES + 1]; | |
1847 | |
167 | 1848 if (curwin->w_p_list) |
1849 list = TRUE; | |
1850 | |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1851 if (list) |
7 | 1852 { |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1853 // find start of trailing whitespace |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1854 if (curwin->w_lcs_chars.trail) |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1855 { |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1856 trail = s + STRLEN(s); |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1857 while (trail > s && VIM_ISWHITE(trail[-1])) |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1858 --trail; |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1859 } |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1860 // find end of leading whitespace |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1861 if (curwin->w_lcs_chars.lead) |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1862 { |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1863 lead = s; |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1864 while (VIM_ISWHITE(lead[0])) |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1865 lead++; |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1866 // in a line full of spaces all of them are treated as trailing |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1867 if (*lead == NUL) |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1868 lead = NULL; |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1869 } |
7 | 1870 } |
1871 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1872 // output a space for an empty line, otherwise the line will be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1873 // overwritten |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1874 if (*s == NUL && !(list && curwin->w_lcs_chars.eol != NUL)) |
7 | 1875 msg_putchar(' '); |
1876 | |
446 | 1877 while (!got_int) |
7 | 1878 { |
1059 | 1879 if (n_extra > 0) |
7 | 1880 { |
1881 --n_extra; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1882 if (n_extra == 0 && c_final) |
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1883 c = c_final; |
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1884 else if (c_extra) |
7 | 1885 c = c_extra; |
1886 else | |
1887 c = *p_extra++; | |
1888 } | |
474 | 1889 else if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 1890 { |
1891 col += (*mb_ptr2cells)(s); | |
23064
89c324e327c0
patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
1892 if (l >= MB_MAXBYTES) |
89c324e327c0
patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
1893 { |
23090
fb27d3a7a24b
patch 8.2.2091: MS-Windows: build warnings
Bram Moolenaar <Bram@vim.org>
parents:
23064
diff
changeset
|
1894 STRCPY(buf, "?"); |
23064
89c324e327c0
patch 8.2.2078: illegal memory access when using :print on invalid text
Bram Moolenaar <Bram@vim.org>
parents:
22742
diff
changeset
|
1895 } |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1896 else if (curwin->w_lcs_chars.nbsp != NUL && list |
6801 | 1897 && (mb_ptr2char(s) == 160 |
1898 || mb_ptr2char(s) == 0x202f)) | |
2692 | 1899 { |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1900 mb_char2bytes(curwin->w_lcs_chars.nbsp, buf); |
2692 | 1901 buf[(*mb_ptr2len)(buf)] = NUL; |
1902 } | |
1903 else | |
1904 { | |
1905 mch_memmove(buf, s, (size_t)l); | |
1906 buf[l] = NUL; | |
1907 } | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
1908 msg_puts((char *)buf); |
7 | 1909 s += l; |
1910 continue; | |
1911 } | |
1912 else | |
1913 { | |
1914 attr = 0; | |
1915 c = *s++; | |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1916 if (c == TAB && (!list || curwin->w_lcs_chars.tab1)) |
7 | 1917 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1918 // tab amount depends on current column |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1919 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1920 n_extra = tabstop_padding(col, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1921 curbuf->b_p_vts_array) - 1; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1922 #else |
7 | 1923 n_extra = curbuf->b_p_ts - col % curbuf->b_p_ts - 1; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14129
diff
changeset
|
1924 #endif |
167 | 1925 if (!list) |
7 | 1926 { |
1927 c = ' '; | |
1928 c_extra = ' '; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1929 c_final = NUL; |
7 | 1930 } |
1931 else | |
1932 { | |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1933 c = (n_extra == 0 && curwin->w_lcs_chars.tab3) |
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1934 ? curwin->w_lcs_chars.tab3 |
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1935 : curwin->w_lcs_chars.tab1; |
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1936 c_extra = curwin->w_lcs_chars.tab2; |
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1937 c_final = curwin->w_lcs_chars.tab3; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1938 attr = HL_ATTR(HLF_8); |
7 | 1939 } |
1940 } | |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1941 else if (c == 160 && list && curwin->w_lcs_chars.nbsp != NUL) |
2692 | 1942 { |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1943 c = curwin->w_lcs_chars.nbsp; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1944 attr = HL_ATTR(HLF_8); |
2692 | 1945 } |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1946 else if (c == NUL && list && curwin->w_lcs_chars.eol != NUL) |
7 | 1947 { |
1948 p_extra = (char_u *)""; | |
1949 c_extra = NUL; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1950 c_final = NUL; |
7 | 1951 n_extra = 1; |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1952 c = curwin->w_lcs_chars.eol; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1953 attr = HL_ATTR(HLF_AT); |
7 | 1954 --s; |
1955 } | |
1956 else if (c != NUL && (n = byte2cells(c)) > 1) | |
1957 { | |
1958 n_extra = n - 1; | |
1959 p_extra = transchar_byte(c); | |
1960 c_extra = NUL; | |
15502
bc17a9d37810
patch 8.1.0759: showing two characters for tab is limited
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1961 c_final = NUL; |
7 | 1962 c = *p_extra++; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1963 // Use special coloring to be able to distinguish <hex> from |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
1964 // the same in plain text. |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1965 attr = HL_ATTR(HLF_8); |
7 | 1966 } |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1967 else if (c == ' ' && lead != NULL && s <= lead) |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1968 { |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1969 c = curwin->w_lcs_chars.lead; |
23825
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1970 attr = HL_ATTR(HLF_8); |
0bd44e94dd14
patch 8.2.2454: leading space can not be made visible
Bram Moolenaar <Bram@vim.org>
parents:
23102
diff
changeset
|
1971 } |
7 | 1972 else if (c == ' ' && trail != NULL && s > trail) |
1973 { | |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1974 c = curwin->w_lcs_chars.trail; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1975 attr = HL_ATTR(HLF_8); |
7 | 1976 } |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1977 else if (c == ' ' && list && curwin->w_lcs_chars.space != NUL) |
6781 | 1978 { |
23952
44be09b25619
patch 8.2.2518: 'listchars' should be window-local
Bram Moolenaar <Bram@vim.org>
parents:
23946
diff
changeset
|
1979 c = curwin->w_lcs_chars.space; |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1980 attr = HL_ATTR(HLF_8); |
6781 | 1981 } |
7 | 1982 } |
1983 | |
1984 if (c == NUL) | |
1985 break; | |
1986 | |
1987 msg_putchar_attr(c, attr); | |
1988 col++; | |
1989 } | |
1990 msg_clr_eos(); | |
1991 } | |
1992 | |
1993 /* | |
1994 * Use screen_puts() to output one multi-byte character. | |
1995 * Return the pointer "s" advanced to the next character. | |
1996 */ | |
1997 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1998 screen_puts_mbyte(char_u *s, int l, int attr) |
7 | 1999 { |
2000 int cw; | |
2001 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2002 msg_didout = TRUE; // remember that line is not empty |
7 | 2003 cw = (*mb_ptr2cells)(s); |
2004 if (cw > 1 && ( | |
2005 #ifdef FEAT_RIGHTLEFT | |
2006 cmdmsg_rl ? msg_col <= 1 : | |
2007 #endif | |
2008 msg_col == Columns - 1)) | |
2009 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2010 // Doesn't fit, print a highlighted '>' to fill it up. |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2011 msg_screen_putchar('>', HL_ATTR(HLF_AT)); |
7 | 2012 return s; |
2013 } | |
2014 | |
2015 screen_puts_len(s, l, msg_row, msg_col, attr); | |
2016 #ifdef FEAT_RIGHTLEFT | |
2017 if (cmdmsg_rl) | |
2018 { | |
2019 msg_col -= cw; | |
2020 if (msg_col == 0) | |
2021 { | |
2022 msg_col = Columns; | |
2023 ++msg_row; | |
2024 } | |
2025 } | |
2026 else | |
2027 #endif | |
2028 { | |
2029 msg_col += cw; | |
2030 if (msg_col >= Columns) | |
2031 { | |
2032 msg_col = 0; | |
2033 ++msg_row; | |
2034 } | |
2035 } | |
2036 return s + l; | |
2037 } | |
2038 | |
2039 /* | |
2040 * Output a string to the screen at position msg_row, msg_col. | |
2041 * Update msg_row and msg_col for the next message. | |
2042 */ | |
2043 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2044 msg_puts(char *s) |
7 | 2045 { |
10141
b67088aae933
commit https://github.com/vim/vim/commit/aeac9006d5d14910f214f09df52c026a5936e737
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2046 msg_puts_attr(s, 0); |
7 | 2047 } |
2048 | |
2049 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2050 msg_puts_title(char *s) |
7 | 2051 { |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
2052 msg_puts_attr(s, HL_ATTR(HLF_T)); |
7 | 2053 } |
2054 | |
2055 /* | |
2056 * Show a message in such a way that it always fits in the line. Cut out a | |
2057 * part in the middle and replace it with "..." when necessary. | |
2058 * Does not handle multi-byte characters! | |
2059 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2060 static void |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2061 msg_outtrans_long_len_attr(char_u *longstr, int len, int attr) |
7 | 2062 { |
2063 int slen = len; | |
2064 int room; | |
2065 | |
2066 room = Columns - msg_col; | |
2067 if (len > room && room >= 20) | |
2068 { | |
2069 slen = (room - 3) / 2; | |
2070 msg_outtrans_len_attr(longstr, slen, attr); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2071 msg_puts_attr("...", HL_ATTR(HLF_8)); |
7 | 2072 } |
2073 msg_outtrans_len_attr(longstr + len - slen, slen, attr); | |
2074 } | |
2075 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2076 void |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2077 msg_outtrans_long_attr(char_u *longstr, int attr) |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2078 { |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2079 msg_outtrans_long_len_attr(longstr, (int)STRLEN(longstr), attr); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2080 } |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
2081 |
7 | 2082 /* |
2083 * Basic function for writing a message with highlight attributes. | |
2084 */ | |
2085 void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2086 msg_puts_attr(char *s, int attr) |
7 | 2087 { |
2088 msg_puts_attr_len(s, -1, attr); | |
2089 } | |
2090 | |
2091 /* | |
2092 * Like msg_puts_attr(), but with a maximum length "maxlen" (in bytes). | |
2093 * When "maxlen" is -1 there is no maximum length. | |
2094 * When "maxlen" is >= 0 the message is not put in the history. | |
2095 */ | |
2096 static void | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2097 msg_puts_attr_len(char *str, int maxlen, int attr) |
7 | 2098 { |
2099 /* | |
2100 * If redirection is on, also write to the redirection file. | |
2101 */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2102 redir_write((char_u *)str, maxlen); |
7 | 2103 |
2104 /* | |
2105 * Don't print anything when using ":silent cmd". | |
2106 */ | |
2107 if (msg_silent != 0) | |
2108 return; | |
2109 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2110 // if MSG_HIST flag set, add message to history |
7 | 2111 if ((attr & MSG_HIST) && maxlen < 0) |
2112 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2113 add_msg_hist((char_u *)str, -1, attr); |
7 | 2114 attr &= ~MSG_HIST; |
2115 } | |
2116 | |
18293
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2117 // When writing something to the screen after it has scrolled, requires a |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2118 // wait-return prompt later. Needed when scrolling, resetting |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2119 // need_wait_return after some prompt, and then outputting something |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2120 // without scrolling |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2121 // Not needed when only using CR to move the cursor. |
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2122 if (msg_scrolled != 0 && !msg_scrolled_ign && STRCMP(str, "\r") != 0) |
7 | 2123 need_wait_return = TRUE; |
18293
1c5974759bcd
patch 8.1.2141: :tselect has an extra hit-enter prompt
Bram Moolenaar <Bram@vim.org>
parents:
18176
diff
changeset
|
2124 msg_didany = TRUE; // remember that something was outputted |
7 | 2125 |
2126 /* | |
2127 * If there is no valid screen, use fprintf so we can see error messages. | |
2128 * If termcap is not active, we may be writing in an alternate console | |
2129 * window, cursor positioning may not work correctly (window size may be | |
2130 * different, e.g. for Win32 console) or we just don't know where the | |
2131 * cursor is. | |
2132 */ | |
2133 if (msg_use_printf()) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2134 msg_puts_printf((char_u *)str, maxlen); |
446 | 2135 else |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
2136 msg_puts_display((char_u *)str, maxlen, attr, FALSE); |
446 | 2137 } |
2138 | |
2139 /* | |
2140 * The display part of msg_puts_attr_len(). | |
2141 * May be called recursively to display scroll-back text. | |
2142 */ | |
2143 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2144 msg_puts_display( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2145 char_u *str, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2146 int maxlen, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2147 int attr, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2148 int recurse) |
446 | 2149 { |
2150 char_u *s = str; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2151 char_u *t_s = str; // string from "t_s" to "s" is still todo |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2152 int t_col = 0; // screen cells todo, 0 when "t_s" not used |
446 | 2153 int l; |
2154 int cw; | |
2155 char_u *sb_str = str; | |
2156 int sb_col = msg_col; | |
2157 int wrap; | |
1381 | 2158 int did_last_char; |
7 | 2159 |
2160 did_wait_return = FALSE; | |
1339 | 2161 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) |
7 | 2162 { |
2163 /* | |
446 | 2164 * We are at the end of the screen line when: |
2165 * - When outputting a newline. | |
2166 * - When outputting a character in the last column. | |
7 | 2167 */ |
446 | 2168 if (!recurse && msg_row >= Rows - 1 && (*s == '\n' || ( |
7 | 2169 #ifdef FEAT_RIGHTLEFT |
2170 cmdmsg_rl | |
2171 ? ( | |
2172 msg_col <= 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2173 || (*s == TAB && msg_col <= 7) |
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2174 || (has_mbyte && (*mb_ptr2cells)(s) > 1 && msg_col <= 2)) |
7 | 2175 : |
2176 #endif | |
18866
a686560cf6c9
patch 8.1.2419: with a long file name the hit-enter prompt appears
Bram Moolenaar <Bram@vim.org>
parents:
18829
diff
changeset
|
2177 ((*s != '\r' && msg_col + t_col >= Columns - 1) |
7 | 2178 || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7)) |
2179 || (has_mbyte && (*mb_ptr2cells)(s) > 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2180 && msg_col + t_col >= Columns - 2))))) |
7 | 2181 { |
446 | 2182 /* |
2183 * The screen is scrolled up when at the last row (some terminals | |
2184 * scroll automatically, some don't. To avoid problems we scroll | |
2185 * ourselves). | |
2186 */ | |
7 | 2187 if (t_col > 0) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2188 // output postponed text |
446 | 2189 t_puts(&t_col, t_s, s, attr); |
7 | 2190 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2191 // When no more prompt and no more room, truncate here |
7 | 2192 if (msg_no_more && lines_left == 0) |
2193 break; | |
446 | 2194 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2195 // Scroll the screen up one line. |
446 | 2196 msg_scroll_up(); |
7 | 2197 |
2198 msg_row = Rows - 2; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2199 if (msg_col >= Columns) // can happen after screen resize |
7 | 2200 msg_col = Columns - 1; |
2201 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2202 // Display char in last column before showing more-prompt. |
446 | 2203 if (*s >= ' ' |
2204 #ifdef FEAT_RIGHTLEFT | |
2205 && !cmdmsg_rl | |
2206 #endif | |
2207 ) | |
2208 { | |
2209 if (has_mbyte) | |
2210 { | |
2211 if (enc_utf8 && maxlen >= 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2212 // avoid including composing chars after the end |
474 | 2213 l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); |
446 | 2214 else |
474 | 2215 l = (*mb_ptr2len)(s); |
446 | 2216 s = screen_puts_mbyte(s, l, attr); |
2217 } | |
2218 else | |
2219 msg_screen_putchar(*s++, attr); | |
1381 | 2220 did_last_char = TRUE; |
446 | 2221 } |
1381 | 2222 else |
2223 did_last_char = FALSE; | |
446 | 2224 |
2225 if (p_more) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2226 // store text for scrolling back |
446 | 2227 store_sb_text(&sb_str, s, attr, &sb_col, TRUE); |
2228 | |
539 | 2229 inc_msg_scrolled(); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2230 need_wait_return = TRUE; // may need wait_return in main() |
7 | 2231 redraw_cmdline = TRUE; |
2232 if (cmdline_row > 0 && !exmode_active) | |
2233 --cmdline_row; | |
2234 | |
2235 /* | |
446 | 2236 * If screen is completely filled and 'more' is set then wait |
2237 * for a character. | |
7 | 2238 */ |
1342 | 2239 if (lines_left > 0) |
2240 --lines_left; | |
957 | 2241 if (p_more && lines_left == 0 && State != HITRETURN |
7 | 2242 && !msg_no_more && !exmode_active) |
2243 { | |
2244 #ifdef FEAT_CON_DIALOG | |
446 | 2245 if (do_more_prompt(NUL)) |
2246 s = confirm_msg_tail; | |
2247 #else | |
2248 (void)do_more_prompt(NUL); | |
7 | 2249 #endif |
2250 if (quit_more) | |
446 | 2251 return; |
7 | 2252 } |
539 | 2253 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2254 // When we displayed a char in last column need to check if there |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2255 // is still more. |
1381 | 2256 if (did_last_char) |
539 | 2257 continue; |
7 | 2258 } |
2259 | |
446 | 2260 wrap = *s == '\n' |
7 | 2261 || msg_col + t_col >= Columns |
2262 || (has_mbyte && (*mb_ptr2cells)(s) > 1 | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2263 && msg_col + t_col >= Columns - 1); |
446 | 2264 if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' |
2265 || *s == '\t' || *s == BELL)) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2266 // output any postponed text |
446 | 2267 t_puts(&t_col, t_s, s, attr); |
2268 | |
2269 if (wrap && p_more && !recurse) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2270 // store text for scrolling back |
446 | 2271 store_sb_text(&sb_str, s, attr, &sb_col, TRUE); |
7 | 2272 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2273 if (*s == '\n') // go to next line |
7 | 2274 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2275 msg_didout = FALSE; // remember that line is empty |
474 | 2276 #ifdef FEAT_RIGHTLEFT |
2277 if (cmdmsg_rl) | |
2278 msg_col = Columns - 1; | |
2279 else | |
2280 #endif | |
2281 msg_col = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2282 if (++msg_row >= Rows) // safety check |
7 | 2283 msg_row = Rows - 1; |
2284 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2285 else if (*s == '\r') // go to column 0 |
7 | 2286 { |
2287 msg_col = 0; | |
2288 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2289 else if (*s == '\b') // go to previous char |
7 | 2290 { |
2291 if (msg_col) | |
2292 --msg_col; | |
2293 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2294 else if (*s == TAB) // translate Tab into spaces |
7 | 2295 { |
2296 do | |
2297 msg_screen_putchar(' ', attr); | |
2298 while (msg_col & 7); | |
2299 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2300 else if (*s == BELL) // beep (from ":sh") |
6949 | 2301 vim_beep(BO_SH); |
7 | 2302 else |
2303 { | |
2304 if (has_mbyte) | |
2305 { | |
2306 cw = (*mb_ptr2cells)(s); | |
2307 if (enc_utf8 && maxlen >= 0) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2308 // avoid including composing chars after the end |
474 | 2309 l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); |
7 | 2310 else |
474 | 2311 l = (*mb_ptr2len)(s); |
7 | 2312 } |
2313 else | |
2314 { | |
2315 cw = 1; | |
2316 l = 1; | |
2317 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2318 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2319 // When drawing from right to left or when a double-wide character |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2320 // doesn't fit, draw a single character here. Otherwise collect |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2321 // characters and draw them all at once later. |
7 | 2322 if ( |
2323 # ifdef FEAT_RIGHTLEFT | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2324 cmdmsg_rl || |
7 | 2325 # endif |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2326 (cw > 1 && msg_col + t_col >= Columns - 1)) |
7 | 2327 { |
2328 if (l > 1) | |
2329 s = screen_puts_mbyte(s, l, attr) - 1; | |
2330 else | |
2331 msg_screen_putchar(*s, attr); | |
2332 } | |
2333 else | |
2334 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2335 // postpone this character until later |
7 | 2336 if (t_col == 0) |
2337 t_s = s; | |
2338 t_col += cw; | |
2339 s += l - 1; | |
2340 } | |
2341 } | |
2342 ++s; | |
2343 } | |
2344 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2345 // output any postponed text |
7 | 2346 if (t_col > 0) |
446 | 2347 t_puts(&t_col, t_s, s, attr); |
2348 if (p_more && !recurse) | |
2349 store_sb_text(&sb_str, s, attr, &sb_col, FALSE); | |
7 | 2350 |
2351 msg_check(); | |
2352 } | |
2353 | |
2354 /* | |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2355 * Return TRUE when ":filter pattern" was used and "msg" does not match |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2356 * "pattern". |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2357 */ |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2358 int |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2359 message_filtered(char_u *msg) |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2360 { |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2361 int match; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2362 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22592
diff
changeset
|
2363 if (cmdmod.cmod_filter_regmatch.regprog == NULL) |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9941
diff
changeset
|
2364 return FALSE; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22592
diff
changeset
|
2365 match = vim_regexec(&cmdmod.cmod_filter_regmatch, msg, (colnr_T)0); |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22592
diff
changeset
|
2366 return cmdmod.cmod_filter_force ? match : !match; |
9941
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2367 } |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2368 |
e975914c17e9
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Christian Brabandt <cb@256bit.org>
parents:
9894
diff
changeset
|
2369 /* |
446 | 2370 * Scroll the screen up one line for displaying the next message line. |
2371 */ | |
2372 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2373 msg_scroll_up(void) |
446 | 2374 { |
2375 #ifdef FEAT_GUI | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2376 // Remove the cursor before scrolling, ScreenLines[] is going |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2377 // to become invalid. |
446 | 2378 if (gui.in_use) |
2379 gui_undraw_cursor(); | |
2380 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2381 // scrolling up always works |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
2382 mch_disable_flush(); |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
2383 screen_del_lines(0, 0, 1, (int)Rows, TRUE, 0, NULL); |
13150
808625d4b71b
patch 8.0.1449: slow redrawing with DirectX
Christian Brabandt <cb@256bit.org>
parents:
12865
diff
changeset
|
2384 mch_enable_flush(); |
446 | 2385 |
2386 if (!can_clear((char_u *)" ")) | |
2387 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2388 // Scrolling up doesn't result in the right background. Set the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2389 // background here. It's not efficient, but avoids that we have to do |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2390 // it all over the code. |
446 | 2391 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); |
2392 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2393 // Also clear the last char of the last but one line if it was not |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2394 // cleared before to avoid a scroll-up. |
446 | 2395 if (ScreenAttrs[LineOffset[Rows - 2] + Columns - 1] == (sattr_T)-1) |
2396 screen_fill((int)Rows - 2, (int)Rows - 1, | |
2397 (int)Columns - 1, (int)Columns, ' ', ' ', 0); | |
2398 } | |
2399 } | |
2400 | |
2401 /* | |
539 | 2402 * Increment "msg_scrolled". |
2403 */ | |
2404 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2405 inc_msg_scrolled(void) |
539 | 2406 { |
2407 #ifdef FEAT_EVAL | |
2408 if (*get_vim_var_str(VV_SCROLLSTART) == NUL) | |
2409 { | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2410 char_u *p = SOURCING_NAME; |
539 | 2411 char_u *tofree = NULL; |
2412 int len; | |
2413 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2414 // v:scrollstart is empty, set it to the script/function name and line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2415 // number |
539 | 2416 if (p == NULL) |
2417 p = (char_u *)_("Unknown"); | |
2418 else | |
2419 { | |
835 | 2420 len = (int)STRLEN(p) + 40; |
539 | 2421 tofree = alloc(len); |
2422 if (tofree != NULL) | |
2423 { | |
2424 vim_snprintf((char *)tofree, len, _("%s line %ld"), | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2425 p, (long)SOURCING_LNUM); |
539 | 2426 p = tofree; |
2427 } | |
2428 } | |
2429 set_vim_var_string(VV_SCROLLSTART, p, -1); | |
2430 vim_free(tofree); | |
2431 } | |
2432 #endif | |
2433 ++msg_scrolled; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2434 if (must_redraw < VALID) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2435 must_redraw = VALID; |
539 | 2436 } |
2437 | |
2438 /* | |
446 | 2439 * To be able to scroll back at the "more" and "hit-enter" prompts we need to |
2440 * store the displayed text and remember where screen lines start. | |
2441 */ | |
2442 typedef struct msgchunk_S msgchunk_T; | |
2443 struct msgchunk_S | |
2444 { | |
2445 msgchunk_T *sb_next; | |
2446 msgchunk_T *sb_prev; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2447 char sb_eol; // TRUE when line ends after this text |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2448 int sb_msg_col; // column in which text starts |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2449 int sb_attr; // text attributes |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2450 char_u sb_text[1]; // text to be displayed, actually longer |
446 | 2451 }; |
2452 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2453 static msgchunk_T *last_msgchunk = NULL; // last displayed text |
446 | 2454 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
2455 static msgchunk_T *msg_sb_start(msgchunk_T *mps); |
446 | 2456 |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2457 typedef enum { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2458 SB_CLEAR_NONE = 0, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2459 SB_CLEAR_ALL, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2460 SB_CLEAR_CMDLINE_BUSY, |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2461 SB_CLEAR_CMDLINE_DONE |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2462 } sb_clear_T; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2463 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2464 // When to clear text on next msg. |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2465 static sb_clear_T do_clear_sb_text = SB_CLEAR_NONE; |
447 | 2466 |
446 | 2467 /* |
2468 * Store part of a printed message for displaying when scrolling back. | |
2469 */ | |
2470 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2471 store_sb_text( |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2472 char_u **sb_str, // start of string |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2473 char_u *s, // just after string |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2474 int attr, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2475 int *sb_col, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2476 int finish) // line ends |
446 | 2477 { |
2478 msgchunk_T *mp; | |
2479 | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2480 if (do_clear_sb_text == SB_CLEAR_ALL |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2481 || do_clear_sb_text == SB_CLEAR_CMDLINE_DONE) |
447 | 2482 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2483 clear_sb_text(do_clear_sb_text == SB_CLEAR_ALL); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2484 do_clear_sb_text = SB_CLEAR_NONE; |
447 | 2485 } |
2486 | |
446 | 2487 if (s > *sb_str) |
2488 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2489 mp = alloc(sizeof(msgchunk_T) + (s - *sb_str)); |
446 | 2490 if (mp != NULL) |
2491 { | |
2492 mp->sb_eol = finish; | |
2493 mp->sb_msg_col = *sb_col; | |
2494 mp->sb_attr = attr; | |
2495 vim_strncpy(mp->sb_text, *sb_str, s - *sb_str); | |
2496 | |
2497 if (last_msgchunk == NULL) | |
2498 { | |
2499 last_msgchunk = mp; | |
2500 mp->sb_prev = NULL; | |
2501 } | |
2502 else | |
2503 { | |
2504 mp->sb_prev = last_msgchunk; | |
2505 last_msgchunk->sb_next = mp; | |
2506 last_msgchunk = mp; | |
2507 } | |
2508 mp->sb_next = NULL; | |
2509 } | |
2510 } | |
2511 else if (finish && last_msgchunk != NULL) | |
2512 last_msgchunk->sb_eol = TRUE; | |
2513 | |
2514 *sb_str = s; | |
2515 *sb_col = 0; | |
2516 } | |
2517 | |
2518 /* | |
447 | 2519 * Finished showing messages, clear the scroll-back text on the next message. |
2520 */ | |
2521 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2522 may_clear_sb_text(void) |
447 | 2523 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2524 do_clear_sb_text = SB_CLEAR_ALL; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2525 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2526 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2527 /* |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2528 * Starting to edit the command line, do not clear messages now. |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2529 */ |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2530 void |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2531 sb_text_start_cmdline(void) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2532 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2533 do_clear_sb_text = SB_CLEAR_CMDLINE_BUSY; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2534 msg_sb_eol(); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2535 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2536 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2537 /* |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2538 * Ending to edit the command line. Clear old lines but the last one later. |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2539 */ |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2540 void |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2541 sb_text_end_cmdline(void) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2542 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2543 do_clear_sb_text = SB_CLEAR_CMDLINE_DONE; |
447 | 2544 } |
2545 | |
2546 /* | |
446 | 2547 * Clear any text remembered for scrolling back. |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2548 * When "all" is FALSE keep the last line. |
446 | 2549 * Called when redrawing the screen. |
2550 */ | |
2551 void | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2552 clear_sb_text(int all) |
446 | 2553 { |
2554 msgchunk_T *mp; | |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2555 msgchunk_T **lastp; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2556 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2557 if (all) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2558 lastp = &last_msgchunk; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2559 else |
446 | 2560 { |
11163
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2561 if (last_msgchunk == NULL) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2562 return; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2563 lastp = &last_msgchunk->sb_prev; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2564 } |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2565 |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2566 while (*lastp != NULL) |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2567 { |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2568 mp = (*lastp)->sb_prev; |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2569 vim_free(*lastp); |
f4d1fad4ac00
patch 8.0.0468: after aborting an Ex command g< does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2570 *lastp = mp; |
446 | 2571 } |
2572 } | |
2573 | |
2574 /* | |
447 | 2575 * "g<" command. |
2576 */ | |
2577 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2578 show_sb_text(void) |
447 | 2579 { |
2580 msgchunk_T *mp; | |
2581 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2582 // Only show something if there is more than one line, otherwise it looks |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2583 // weird, typing a command without output results in one line. |
447 | 2584 mp = msg_sb_start(last_msgchunk); |
2585 if (mp == NULL || mp->sb_prev == NULL) | |
6949 | 2586 vim_beep(BO_MESS); |
447 | 2587 else |
2588 { | |
2589 do_more_prompt('G'); | |
2590 wait_return(FALSE); | |
2591 } | |
2592 } | |
2593 | |
2594 /* | |
446 | 2595 * Move to the start of screen line in already displayed text. |
2596 */ | |
2597 static msgchunk_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2598 msg_sb_start(msgchunk_T *mps) |
446 | 2599 { |
2600 msgchunk_T *mp = mps; | |
2601 | |
2602 while (mp != NULL && mp->sb_prev != NULL && !mp->sb_prev->sb_eol) | |
2603 mp = mp->sb_prev; | |
2604 return mp; | |
2605 } | |
2606 | |
2607 /* | |
3435 | 2608 * Mark the last message chunk as finishing the line. |
2609 */ | |
2610 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2611 msg_sb_eol(void) |
3435 | 2612 { |
2613 if (last_msgchunk != NULL) | |
2614 last_msgchunk->sb_eol = TRUE; | |
2615 } | |
2616 | |
2617 /* | |
446 | 2618 * Display a screen line from previously displayed text at row "row". |
2619 * Returns a pointer to the text for the next line (can be NULL). | |
2620 */ | |
2621 static msgchunk_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2622 disp_sb_line(int row, msgchunk_T *smp) |
446 | 2623 { |
2624 msgchunk_T *mp = smp; | |
2625 char_u *p; | |
2626 | |
2627 for (;;) | |
2628 { | |
2629 msg_row = row; | |
2630 msg_col = mp->sb_msg_col; | |
2631 p = mp->sb_text; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2632 if (*p == '\n') // don't display the line break |
446 | 2633 ++p; |
2634 msg_puts_display(p, -1, mp->sb_attr, TRUE); | |
2635 if (mp->sb_eol || mp->sb_next == NULL) | |
2636 break; | |
2637 mp = mp->sb_next; | |
2638 } | |
2639 return mp->sb_next; | |
2640 } | |
2641 | |
2642 /* | |
7 | 2643 * Output any postponed text for msg_puts_attr_len(). |
2644 */ | |
2645 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2646 t_puts( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2647 int *t_col, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2648 char_u *t_s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2649 char_u *s, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2650 int attr) |
7 | 2651 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2652 // output postponed text |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2653 msg_didout = TRUE; // remember that line is not empty |
7 | 2654 screen_puts_len(t_s, (int)(s - t_s), msg_row, msg_col, attr); |
446 | 2655 msg_col += *t_col; |
2656 *t_col = 0; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2657 // If the string starts with a composing character don't increment the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2658 // column position for it. |
7 | 2659 if (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s))) |
2660 --msg_col; | |
2661 if (msg_col >= Columns) | |
2662 { | |
2663 msg_col = 0; | |
2664 ++msg_row; | |
2665 } | |
2666 } | |
2667 | |
2668 /* | |
2669 * Returns TRUE when messages should be printed with mch_errmsg(). | |
2670 * This is used when there is no valid screen, so we can see error messages. | |
2671 * If termcap is not active, we may be writing in an alternate console | |
2672 * window, cursor positioning may not work correctly (window size may be | |
2673 * different, e.g. for Win32 console) or we just don't know where the | |
2674 * cursor is. | |
2675 */ | |
2676 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2677 msg_use_printf(void) |
7 | 2678 { |
2679 return (!msg_check_screen() | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2680 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2681 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2682 || (!gui.in_use && !termcap_active) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2683 # else |
7 | 2684 || !termcap_active |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
2685 # endif |
7 | 2686 #endif |
2687 || (swapping_screen() && !termcap_active) | |
2688 ); | |
2689 } | |
2690 | |
446 | 2691 /* |
2692 * Print a message when there is no valid screen. | |
2693 */ | |
2694 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2695 msg_puts_printf(char_u *str, int maxlen) |
446 | 2696 { |
2697 char_u *s = str; | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2698 char_u *buf = NULL; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2699 char_u *p = s; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2700 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2701 #ifdef MSWIN |
446 | 2702 if (!(silent_mode && p_verbose == 0)) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2703 mch_settmode(TMODE_COOK); // handle CR and NL correctly |
446 | 2704 #endif |
10158
dd0531938cb6
commit https://github.com/vim/vim/commit/2321ca2a78286bc026fa7f407281ddbeb04114bb
Christian Brabandt <cb@256bit.org>
parents:
10141
diff
changeset
|
2705 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) |
446 | 2706 { |
2707 if (!(silent_mode && p_verbose == 0)) | |
2708 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2709 // NL --> CR NL translation (for Unix, not for "--version") |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2710 if (*s == NL) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2711 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2712 int n = (int)(s - p); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2713 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2714 buf = alloc(n + 3); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2715 if (buf != NULL) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2716 { |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2717 memcpy(buf, p, n); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2718 if (!info_message) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2719 buf[n++] = CAR; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2720 buf[n++] = NL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2721 buf[n++] = NUL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2722 if (info_message) // informative message, not an error |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2723 mch_msg((char *)buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2724 else |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2725 mch_errmsg((char *)buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2726 vim_free(buf); |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2727 } |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2728 p = s + 1; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2729 } |
446 | 2730 } |
2731 | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2732 // primitive way to compute the current column |
446 | 2733 #ifdef FEAT_RIGHTLEFT |
2734 if (cmdmsg_rl) | |
2735 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2736 if (*s == CAR || *s == NL) |
446 | 2737 msg_col = Columns - 1; |
2738 else | |
2739 --msg_col; | |
2740 } | |
2741 else | |
2742 #endif | |
2743 { | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2744 if (*s == CAR || *s == NL) |
446 | 2745 msg_col = 0; |
2746 else | |
2747 ++msg_col; | |
2748 } | |
2749 ++s; | |
2750 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2751 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2752 if (*p != NUL && !(silent_mode && p_verbose == 0)) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2753 { |
24938
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2754 char_u *tofree = NULL; |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2755 |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2756 if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2757 { |
24938
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2758 tofree = vim_strnsave(p, (size_t)maxlen); |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2759 p = tofree; |
15926
ca0a0b64809c
patch 8.1.0969: message written during startup is truncated
Bram Moolenaar <Bram@vim.org>
parents:
15896
diff
changeset
|
2760 } |
24938
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2761 if (p != NULL) |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2762 { |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2763 if (info_message) |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2764 mch_msg((char *)p); |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2765 else |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2766 mch_errmsg((char *)p); |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2767 vim_free(tofree); |
ac0211a9fb6a
patch 8.2.3006: crash when echoing a value very early
Bram Moolenaar <Bram@vim.org>
parents:
24406
diff
changeset
|
2768 } |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2769 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2770 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
2771 msg_didout = TRUE; // assume that line is not empty |
446 | 2772 |
15868
7fad90423bd2
patch 8.1.0941: macros for MS-Windows are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2773 #ifdef MSWIN |
446 | 2774 if (!(silent_mode && p_verbose == 0)) |
2775 mch_settmode(TMODE_RAW); | |
2776 #endif | |
2777 } | |
2778 | |
2779 /* | |
2780 * Show the more-prompt and handle the user response. | |
2781 * This takes care of scrolling back and displaying previously displayed text. | |
447 | 2782 * When at hit-enter prompt "typed_char" is the already typed character, |
2783 * otherwise it's NUL. | |
446 | 2784 * Returns TRUE when jumping ahead to "confirm_msg_tail". |
2785 */ | |
2786 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2787 do_more_prompt(int typed_char) |
446 | 2788 { |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2789 static int entered = FALSE; |
446 | 2790 int used_typed_char = typed_char; |
2791 int oldState = State; | |
2792 int c; | |
2793 #ifdef FEAT_CON_DIALOG | |
2794 int retval = FALSE; | |
2795 #endif | |
3263 | 2796 int toscroll; |
446 | 2797 msgchunk_T *mp_last = NULL; |
2798 msgchunk_T *mp; | |
2799 int i; | |
2800 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2801 // We get called recursively when a timer callback outputs a message. In |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2802 // that case don't show another prompt. Also when at the hit-Enter prompt |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2803 // and nothing was typed. |
9185
70d3337ff173
commit https://github.com/vim/vim/commit/a0055ad3a789b8eeb0c983d8a18d4bcaeaf456b8
Christian Brabandt <cb@256bit.org>
parents:
8905
diff
changeset
|
2804 if (entered || (State == HITRETURN && typed_char == 0)) |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2805 return FALSE; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2806 entered = TRUE; |
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
2807 |
447 | 2808 if (typed_char == 'G') |
2809 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2810 // "g<": Find first line on the last page. |
447 | 2811 mp_last = msg_sb_start(last_msgchunk); |
2812 for (i = 0; i < Rows - 2 && mp_last != NULL | |
2813 && mp_last->sb_prev != NULL; ++i) | |
2814 mp_last = msg_sb_start(mp_last->sb_prev); | |
2815 } | |
2816 | |
446 | 2817 State = ASKMORE; |
2818 setmouse(); | |
447 | 2819 if (typed_char == NUL) |
2820 msg_moremsg(FALSE); | |
446 | 2821 for (;;) |
2822 { | |
2823 /* | |
2824 * Get a typed character directly from the user. | |
2825 */ | |
2826 if (used_typed_char != NUL) | |
2827 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2828 c = used_typed_char; // was typed at hit-enter prompt |
446 | 2829 used_typed_char = NUL; |
2830 } | |
2831 else | |
2832 c = get_keystroke(); | |
2833 | |
2834 #if defined(FEAT_MENU) && defined(FEAT_GUI) | |
2835 if (c == K_MENU) | |
2836 { | |
2837 int idx = get_menu_index(current_menu, ASKMORE); | |
2838 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2839 // Used a menu. If it starts with CTRL-Y, it must |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2840 // be a "Copy" for the clipboard. Otherwise |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2841 // assume that we end |
446 | 2842 if (idx == MENU_INDEX_INVALID) |
2843 continue; | |
2844 c = *current_menu->strings[idx]; | |
2845 if (c != NUL && current_menu->strings[idx][1] != NUL) | |
2846 ins_typebuf(current_menu->strings[idx] + 1, | |
2847 current_menu->noremap[idx], 0, TRUE, | |
2848 current_menu->silent[idx]); | |
2849 } | |
2850 #endif | |
2851 | |
3263 | 2852 toscroll = 0; |
446 | 2853 switch (c) |
2854 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2855 case BS: // scroll one line back |
446 | 2856 case K_BS: |
2857 case 'k': | |
2858 case K_UP: | |
3263 | 2859 toscroll = -1; |
446 | 2860 break; |
2861 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2862 case CAR: // one extra line |
446 | 2863 case NL: |
2864 case 'j': | |
2865 case K_DOWN: | |
3263 | 2866 toscroll = 1; |
446 | 2867 break; |
2868 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2869 case 'u': // Up half a page |
3263 | 2870 toscroll = -(Rows / 2); |
446 | 2871 break; |
2872 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2873 case 'd': // Down half a page |
3263 | 2874 toscroll = Rows / 2; |
446 | 2875 break; |
2876 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2877 case 'b': // one page back |
1820 | 2878 case K_PAGEUP: |
3263 | 2879 toscroll = -(Rows - 1); |
446 | 2880 break; |
2881 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2882 case ' ': // one extra page |
1820 | 2883 case 'f': |
446 | 2884 case K_PAGEDOWN: |
2885 case K_LEFTMOUSE: | |
3263 | 2886 toscroll = Rows - 1; |
446 | 2887 break; |
2888 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2889 case 'g': // all the way back to the start |
3263 | 2890 toscroll = -999999; |
447 | 2891 break; |
2892 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2893 case 'G': // all the way to the end |
3263 | 2894 toscroll = 999999; |
447 | 2895 lines_left = 999999; |
2896 break; | |
2897 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2898 case ':': // start new command line |
446 | 2899 #ifdef FEAT_CON_DIALOG |
2900 if (!confirm_msg_used) | |
2901 #endif | |
2902 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2903 // Since got_int is set all typeahead will be flushed, but we |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2904 // want to keep this ':', remember that in a special way. |
446 | 2905 typeahead_noflush(':'); |
14129
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2906 #ifdef FEAT_TERMINAL |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2907 skip_term_loop = TRUE; |
cb731d098241
patch 8.1.0082: in terminal window, typing : at more prompt, inserts ':'
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
2908 #endif |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2909 cmdline_row = Rows - 1; // put ':' on this line |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2910 skip_redraw = TRUE; // skip redraw once |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2911 need_wait_return = FALSE; // don't wait in main() |
446 | 2912 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2913 // FALLTHROUGH |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2914 case 'q': // quit |
446 | 2915 case Ctrl_C: |
2916 case ESC: | |
2917 #ifdef FEAT_CON_DIALOG | |
2918 if (confirm_msg_used) | |
2919 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2920 // Jump to the choices of the dialog. |
446 | 2921 retval = TRUE; |
2922 } | |
2923 else | |
2924 #endif | |
2925 { | |
2926 got_int = TRUE; | |
2927 quit_more = TRUE; | |
2928 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2929 // When there is some more output (wrapping line) display that |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2930 // without another prompt. |
1829 | 2931 lines_left = Rows - 1; |
446 | 2932 break; |
2933 | |
2934 #ifdef FEAT_CLIPBOARD | |
2935 case Ctrl_Y: | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2936 // Strange way to allow copying (yanking) a modeless |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2937 // selection at the more prompt. Use CTRL-Y, |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2938 // because the same is used in Cmdline-mode and at the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2939 // hit-enter prompt. However, scrolling one line up |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2940 // might be expected... |
446 | 2941 if (clip_star.state == SELECT_DONE) |
2942 clip_copy_modeless_selection(TRUE); | |
2943 continue; | |
2944 #endif | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2945 default: // no valid response |
446 | 2946 msg_moremsg(TRUE); |
2947 continue; | |
2948 } | |
2949 | |
3263 | 2950 if (toscroll != 0) |
446 | 2951 { |
3263 | 2952 if (toscroll < 0) |
446 | 2953 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2954 // go to start of last line |
446 | 2955 if (mp_last == NULL) |
2956 mp = msg_sb_start(last_msgchunk); | |
2957 else if (mp_last->sb_prev != NULL) | |
2958 mp = msg_sb_start(mp_last->sb_prev); | |
2959 else | |
2960 mp = NULL; | |
2961 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2962 // go to start of line at top of the screen |
446 | 2963 for (i = 0; i < Rows - 2 && mp != NULL && mp->sb_prev != NULL; |
2964 ++i) | |
2965 mp = msg_sb_start(mp->sb_prev); | |
2966 | |
2967 if (mp != NULL && mp->sb_prev != NULL) | |
2968 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2969 // Find line to be displayed at top. |
3263 | 2970 for (i = 0; i > toscroll; --i) |
446 | 2971 { |
2972 if (mp == NULL || mp->sb_prev == NULL) | |
2973 break; | |
2974 mp = msg_sb_start(mp->sb_prev); | |
2975 if (mp_last == NULL) | |
2976 mp_last = msg_sb_start(last_msgchunk); | |
2977 else | |
2978 mp_last = msg_sb_start(mp_last->sb_prev); | |
2979 } | |
2980 | |
3263 | 2981 if (toscroll == -1 && screen_ins_lines(0, 0, 1, |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
12015
diff
changeset
|
2982 (int)Rows, 0, NULL) == OK) |
446 | 2983 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2984 // display line at top |
446 | 2985 (void)disp_sb_line(0, mp); |
2986 } | |
2987 else | |
2988 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
2989 // redisplay all lines |
446 | 2990 screenclear(); |
870 | 2991 for (i = 0; mp != NULL && i < Rows - 1; ++i) |
2992 { | |
446 | 2993 mp = disp_sb_line(i, mp); |
870 | 2994 ++msg_scrolled; |
2995 } | |
446 | 2996 } |
3263 | 2997 toscroll = 0; |
446 | 2998 } |
2999 } | |
3000 else | |
3001 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3002 // First display any text that we scrolled back. |
3263 | 3003 while (toscroll > 0 && mp_last != NULL) |
446 | 3004 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3005 // scroll up, display line at bottom |
446 | 3006 msg_scroll_up(); |
539 | 3007 inc_msg_scrolled(); |
446 | 3008 screen_fill((int)Rows - 2, (int)Rows - 1, 0, |
3009 (int)Columns, ' ', ' ', 0); | |
3010 mp_last = disp_sb_line((int)Rows - 2, mp_last); | |
3263 | 3011 --toscroll; |
446 | 3012 } |
3013 } | |
3014 | |
3263 | 3015 if (toscroll <= 0) |
446 | 3016 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3017 // displayed the requested text, more prompt again |
447 | 3018 screen_fill((int)Rows - 1, (int)Rows, 0, |
3019 (int)Columns, ' ', ' ', 0); | |
446 | 3020 msg_moremsg(FALSE); |
3021 continue; | |
3022 } | |
3023 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3024 // display more text, return to caller |
3263 | 3025 lines_left = toscroll; |
446 | 3026 } |
3027 | |
3028 break; | |
3029 } | |
3030 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3031 // clear the --more-- message |
446 | 3032 screen_fill((int)Rows - 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); |
3033 State = oldState; | |
3034 setmouse(); | |
3035 if (quit_more) | |
3036 { | |
3037 msg_row = Rows - 1; | |
3038 msg_col = 0; | |
3039 } | |
3040 #ifdef FEAT_RIGHTLEFT | |
3041 else if (cmdmsg_rl) | |
3042 msg_col = Columns - 1; | |
3043 #endif | |
3044 | |
8627
7c98c5d0298c
commit https://github.com/vim/vim/commit/bfb96c047b79b2aab5fd57a2472871508819f3ef
Christian Brabandt <cb@256bit.org>
parents:
8289
diff
changeset
|
3045 entered = FALSE; |
446 | 3046 #ifdef FEAT_CON_DIALOG |
3047 return retval; | |
3048 #else | |
3049 return FALSE; | |
3050 #endif | |
3051 } | |
3052 | |
7 | 3053 #if defined(USE_MCH_ERRMSG) || defined(PROTO) |
3054 | |
3055 #ifdef mch_errmsg | |
3056 # undef mch_errmsg | |
3057 #endif | |
3058 #ifdef mch_msg | |
3059 # undef mch_msg | |
3060 #endif | |
3061 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3062 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3063 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3064 mch_errmsg_c(char *str) |
7 | 3065 { |
15824
6733b8b1caf3
patch 8.1.0919: compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
3066 int len = (int)STRLEN(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3067 DWORD nwrite = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3068 DWORD mode = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3069 HANDLE h = GetStdHandle(STD_ERROR_HANDLE); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3070 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3071 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3072 && (int)GetConsoleCP() != enc_codepage) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3073 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3074 WCHAR *w = enc_to_utf16((char_u *)str, &len); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3075 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3076 WriteConsoleW(h, w, len, &nwrite, NULL); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3077 vim_free(w); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3078 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3079 else |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3080 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3081 fprintf(stderr, "%s", str); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3082 } |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3083 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3084 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3085 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3086 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3087 * Give an error message. To be used when the screen hasn't been initialized |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3088 * yet. When stderr can't be used, collect error messages until the GUI has |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3089 * started and they can be displayed in a message box. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3090 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3091 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3092 mch_errmsg(char *str) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3093 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3094 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
7 | 3095 int len; |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3096 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3097 |
16596
2f86ca0c1e6b
patch 8.1.1301: when compiled with VIMDLL some messages are not shown
Bram Moolenaar <Bram@vim.org>
parents:
16457
diff
changeset
|
3098 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) && !defined(VIMDLL) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3099 // On Unix use stderr if it's a tty. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3100 // When not going to start the GUI also use stderr. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3101 // On Mac, when started from Finder, stderr is the console. |
7 | 3102 if ( |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3103 # ifdef UNIX |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3104 # ifdef MACOS_X |
7 | 3105 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3106 # else |
7 | 3107 isatty(2) |
3108 # endif | |
3109 # ifdef FEAT_GUI | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3110 || |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3111 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3112 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3113 # ifdef FEAT_GUI |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3114 !(gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3115 # endif |
7 | 3116 ) |
3117 { | |
3118 fprintf(stderr, "%s", str); | |
3119 return; | |
3120 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3121 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3122 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3123 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3124 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3125 if (!(gui.in_use || gui.starting)) |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3126 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3127 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3128 mch_errmsg_c(str); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3129 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3130 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3131 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3132 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3133 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3134 // avoid a delay for a message that isn't there |
7 | 3135 emsg_on_display = FALSE; |
3136 | |
3137 len = (int)STRLEN(str) + 1; | |
3138 if (error_ga.ga_growsize == 0) | |
3139 { | |
3140 error_ga.ga_growsize = 80; | |
3141 error_ga.ga_itemsize = 1; | |
3142 } | |
3143 if (ga_grow(&error_ga, len) == OK) | |
3144 { | |
3145 mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len, | |
3146 (char_u *)str, len); | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3147 # ifdef UNIX |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3148 // remove CR characters, they are displayed |
7 | 3149 { |
3150 char_u *p; | |
3151 | |
3152 p = (char_u *)error_ga.ga_data + error_ga.ga_len; | |
3153 for (;;) | |
3154 { | |
3155 p = vim_strchr(p, '\r'); | |
3156 if (p == NULL) | |
3157 break; | |
3158 *p = ' '; | |
3159 } | |
3160 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3161 # endif |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3162 --len; // don't count the NUL at the end |
7 | 3163 error_ga.ga_len += len; |
3164 } | |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3165 #endif |
7 | 3166 } |
3167 | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3168 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3169 static void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3170 mch_msg_c(char *str) |
7 | 3171 { |
15824
6733b8b1caf3
patch 8.1.0919: compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
15822
diff
changeset
|
3172 int len = (int)STRLEN(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3173 DWORD nwrite = 0; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3174 DWORD mode; |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3175 HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3176 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3177 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3178 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3179 && (int)GetConsoleCP() != enc_codepage) |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3180 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3181 WCHAR *w = enc_to_utf16((char_u *)str, &len); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3182 |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3183 WriteConsoleW(h, w, len, &nwrite, NULL); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3184 vim_free(w); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3185 } |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3186 else |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3187 { |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3188 printf("%s", str); |
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3189 } |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3190 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3191 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3192 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3193 /* |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3194 * Give a message. To be used when the screen hasn't been initialized yet. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3195 * When there is no tty, collect messages until the GUI has started and they |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3196 * can be displayed in a message box. |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3197 */ |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3198 void |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3199 mch_msg(char *str) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3200 { |
16596
2f86ca0c1e6b
patch 8.1.1301: when compiled with VIMDLL some messages are not shown
Bram Moolenaar <Bram@vim.org>
parents:
16457
diff
changeset
|
3201 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) && !defined(VIMDLL) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3202 // On Unix use stdout if we have a tty. This allows "vim -h | more" and |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3203 // uses mch_errmsg() when started from the desktop. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3204 // When not going to start the GUI also use stdout. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3205 // On Mac, when started from Finder, stderr is the console. |
7 | 3206 if ( |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3207 # ifdef UNIX |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3208 # ifdef MACOS_X |
7 | 3209 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3210 # else |
7 | 3211 isatty(2) |
16606
7e733046db1d
patch 8.1.1306: Borland support is outdated and doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
16596
diff
changeset
|
3212 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3213 # ifdef FEAT_GUI |
7 | 3214 || |
3215 # endif | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3216 # endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3217 # ifdef FEAT_GUI |
7 | 3218 !(gui.in_use || gui.starting) |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3219 # endif |
7 | 3220 ) |
3221 { | |
3222 printf("%s", str); | |
3223 return; | |
3224 } | |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3225 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3226 |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3227 #if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL)) |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3228 # ifdef VIMDLL |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3229 if (!(gui.in_use || gui.starting)) |
7 | 3230 # endif |
16451
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3231 { |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3232 mch_msg_c(str); |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3233 return; |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3234 } |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3235 #endif |
7ae2396cef62
patch 8.1.1230: a lot of code is shared between vim.exe and gvim.exe
Bram Moolenaar <Bram@vim.org>
parents:
16393
diff
changeset
|
3236 #if !defined(MSWIN) || defined(FEAT_GUI_MSWIN) |
7 | 3237 mch_errmsg(str); |
15822
9745c25da3bc
patch 8.1.0918: MS-Windows: startup messages are not converted
Bram Moolenaar <Bram@vim.org>
parents:
15607
diff
changeset
|
3238 #endif |
7 | 3239 } |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3240 #endif // USE_MCH_ERRMSG |
7 | 3241 |
3242 /* | |
3243 * Put a character on the screen at the current message position and advance | |
3244 * to the next position. Only for printable ASCII! | |
3245 */ | |
3246 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3247 msg_screen_putchar(int c, int attr) |
7 | 3248 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3249 msg_didout = TRUE; // remember that line is not empty |
7 | 3250 screen_putchar(c, msg_row, msg_col, attr); |
3251 #ifdef FEAT_RIGHTLEFT | |
3252 if (cmdmsg_rl) | |
3253 { | |
3254 if (--msg_col == 0) | |
3255 { | |
3256 msg_col = Columns; | |
3257 ++msg_row; | |
3258 } | |
3259 } | |
3260 else | |
3261 #endif | |
3262 { | |
3263 if (++msg_col >= Columns) | |
3264 { | |
3265 msg_col = 0; | |
3266 ++msg_row; | |
3267 } | |
3268 } | |
3269 } | |
3270 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
3271 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3272 msg_moremsg(int full) |
7 | 3273 { |
446 | 3274 int attr; |
3275 char_u *s = (char_u *)_("-- More --"); | |
7 | 3276 |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3277 attr = HL_ATTR(HLF_M); |
446 | 3278 screen_puts(s, (int)Rows - 1, 0, attr); |
7 | 3279 if (full) |
446 | 3280 screen_puts((char_u *) |
3281 _(" SPACE/d/j: screen/page/line down, b/u/k: up, q: quit "), | |
3282 (int)Rows - 1, vim_strsize(s), attr); | |
7 | 3283 } |
3284 | |
3285 /* | |
3286 * Repeat the message for the current mode: ASKMORE, EXTERNCMD, CONFIRM or | |
3287 * exmode_active. | |
3288 */ | |
3289 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3290 repeat_message(void) |
7 | 3291 { |
3292 if (State == ASKMORE) | |
3293 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3294 msg_moremsg(TRUE); // display --more-- message again |
7 | 3295 msg_row = Rows - 1; |
3296 } | |
3297 #ifdef FEAT_CON_DIALOG | |
3298 else if (State == CONFIRM) | |
3299 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3300 display_confirm_msg(); // display ":confirm" message again |
7 | 3301 msg_row = Rows - 1; |
3302 } | |
3303 #endif | |
3304 else if (State == EXTERNCMD) | |
3305 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3306 windgoto(msg_row, msg_col); // put cursor back |
7 | 3307 } |
3308 else if (State == HITRETURN || State == SETWSIZE) | |
3309 { | |
1445 | 3310 if (msg_row == Rows - 1) |
3311 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3312 // Avoid drawing the "hit-enter" prompt below the previous one, |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3313 // overwrite it. Esp. useful when regaining focus and a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3314 // FocusGained autocmd exists but didn't draw anything. |
1445 | 3315 msg_didout = FALSE; |
3316 msg_col = 0; | |
3317 msg_clr_eos(); | |
3318 } | |
7 | 3319 hit_return_msg(); |
3320 msg_row = Rows - 1; | |
3321 } | |
3322 } | |
3323 | |
3324 /* | |
3325 * msg_check_screen - check if the screen is initialized. | |
3326 * Also check msg_row and msg_col, if they are too big it may cause a crash. | |
3327 * While starting the GUI the terminal codes will be set for the GUI, but the | |
3328 * output goes to the terminal. Don't use the terminal codes then. | |
3329 */ | |
3330 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3331 msg_check_screen(void) |
7 | 3332 { |
3333 if (!full_screen || !screen_valid(FALSE)) | |
3334 return FALSE; | |
3335 | |
3336 if (msg_row >= Rows) | |
3337 msg_row = Rows - 1; | |
3338 if (msg_col >= Columns) | |
3339 msg_col = Columns - 1; | |
3340 return TRUE; | |
3341 } | |
3342 | |
3343 /* | |
3344 * Clear from current message position to end of screen. | |
3345 * Skip this when ":silent" was used, no need to clear for redirection. | |
3346 */ | |
3347 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3348 msg_clr_eos(void) |
7 | 3349 { |
3350 if (msg_silent == 0) | |
3351 msg_clr_eos_force(); | |
3352 } | |
3353 | |
3354 /* | |
3355 * Clear from current message position to end of screen. | |
3356 * Note: msg_col is not updated, so we remember the end of the message | |
3357 * for msg_check(). | |
3358 */ | |
3359 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3360 msg_clr_eos_force(void) |
7 | 3361 { |
3362 if (msg_use_printf()) | |
3363 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3364 if (full_screen) // only when termcap codes are valid |
7 | 3365 { |
3366 if (*T_CD) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3367 out_str(T_CD); // clear to end of display |
7 | 3368 else if (*T_CE) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3369 out_str(T_CE); // clear to end of line |
7 | 3370 } |
3371 } | |
3372 else | |
3373 { | |
3374 #ifdef FEAT_RIGHTLEFT | |
3375 if (cmdmsg_rl) | |
3376 { | |
3377 screen_fill(msg_row, msg_row + 1, 0, msg_col + 1, ' ', ' ', 0); | |
3378 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
3379 } | |
3380 else | |
3381 #endif | |
3382 { | |
3383 screen_fill(msg_row, msg_row + 1, msg_col, (int)Columns, | |
3384 ' ', ' ', 0); | |
3385 screen_fill(msg_row + 1, (int)Rows, 0, (int)Columns, ' ', ' ', 0); | |
3386 } | |
3387 } | |
3388 } | |
3389 | |
3390 /* | |
3391 * Clear the command line. | |
3392 */ | |
3393 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3394 msg_clr_cmdline(void) |
7 | 3395 { |
3396 msg_row = cmdline_row; | |
3397 msg_col = 0; | |
3398 msg_clr_eos_force(); | |
3399 } | |
3400 | |
3401 /* | |
3402 * end putting a message on the screen | |
3403 * call wait_return if the message does not fit in the available space | |
3404 * return TRUE if wait_return not called. | |
3405 */ | |
3406 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3407 msg_end(void) |
7 | 3408 { |
3409 /* | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
4793
diff
changeset
|
3410 * If the string is larger than the window, |
7 | 3411 * or the ruler option is set and we run into it, |
3412 * we have to redraw the window. | |
3413 * Do not do this if we are abandoning the file or editing the command line. | |
3414 */ | |
3415 if (!exiting && need_wait_return && !(State & CMDLINE)) | |
3416 { | |
3417 wait_return(FALSE); | |
3418 return FALSE; | |
3419 } | |
3420 out_flush(); | |
3421 return TRUE; | |
3422 } | |
3423 | |
3424 /* | |
3425 * If the written message runs into the shown command or ruler, we have to | |
3426 * wait for hit-return and redraw the window later. | |
3427 */ | |
3428 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3429 msg_check(void) |
7 | 3430 { |
3431 if (msg_row == Rows - 1 && msg_col >= sc_col) | |
3432 { | |
3433 need_wait_return = TRUE; | |
3434 redraw_cmdline = TRUE; | |
3435 } | |
3436 } | |
3437 | |
3438 /* | |
3439 * May write a string to the redirection file. | |
3440 * When "maxlen" is -1 write the whole string, otherwise up to "maxlen" bytes. | |
3441 */ | |
3442 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3443 redir_write(char_u *str, int maxlen) |
7 | 3444 { |
3445 char_u *s = str; | |
3446 static int cur_col = 0; | |
3447 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3448 // Don't do anything for displaying prompts and the like. |
291 | 3449 if (redir_off) |
3450 return; | |
3451 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3452 // If 'verbosefile' is set prepare for writing in that file. |
3072 | 3453 if (*p_vfile != NUL && verbose_fd == NULL) |
3454 verbose_open(); | |
291 | 3455 |
1854 | 3456 if (redirecting()) |
7 | 3457 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3458 // If the string doesn't start with CR or NL, go to msg_col |
7 | 3459 if (*s != '\n' && *s != '\r') |
3460 { | |
3461 while (cur_col < msg_col) | |
3462 { | |
3463 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3464 if (redir_execute) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3465 execute_redir_str((char_u *)" ", -1); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3466 else if (redir_reg) |
7 | 3467 write_reg_contents(redir_reg, (char_u *)" ", -1, TRUE); |
167 | 3468 else if (redir_vname) |
3469 var_redir_str((char_u *)" ", -1); | |
3072 | 3470 else |
7 | 3471 #endif |
3072 | 3472 if (redir_fd != NULL) |
7 | 3473 fputs(" ", redir_fd); |
3072 | 3474 if (verbose_fd != NULL) |
3475 fputs(" ", verbose_fd); | |
7 | 3476 ++cur_col; |
3477 } | |
3478 } | |
3479 | |
3480 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3481 if (redir_execute) |
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3482 execute_redir_str(s, maxlen); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3483 else if (redir_reg) |
7 | 3484 write_reg_contents(redir_reg, s, maxlen, TRUE); |
9436
f048e5a27253
commit https://github.com/vim/vim/commit/bc5d6dd1dd1dc3a06e4e655fc9479529db288365
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3485 else if (redir_vname) |
167 | 3486 var_redir_str(s, maxlen); |
7 | 3487 #endif |
3488 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3489 // Write and adjust the current column. |
7 | 3490 while (*s != NUL && (maxlen < 0 || (int)(s - str) < maxlen)) |
3491 { | |
3492 #ifdef FEAT_EVAL | |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3493 if (!redir_reg && !redir_vname && !redir_execute) |
7 | 3494 #endif |
3072 | 3495 if (redir_fd != NULL) |
3496 putc(*s, redir_fd); | |
3497 if (verbose_fd != NULL) | |
3498 putc(*s, verbose_fd); | |
7 | 3499 if (*s == '\r' || *s == '\n') |
3500 cur_col = 0; | |
3501 else if (*s == '\t') | |
3502 cur_col += (8 - cur_col % 8); | |
3503 else | |
3504 ++cur_col; | |
3505 ++s; | |
3506 } | |
3507 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3508 if (msg_silent != 0) // should update msg_col |
7 | 3509 msg_col = cur_col; |
3510 } | |
3511 } | |
3512 | |
1854 | 3513 int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3514 redirecting(void) |
1854 | 3515 { |
3072 | 3516 return redir_fd != NULL || *p_vfile != NUL |
1854 | 3517 #ifdef FEAT_EVAL |
9454
9da0cb39cbee
commit https://github.com/vim/vim/commit/79815f1ec77406f2f21a618c053e5793b597db7a
Christian Brabandt <cb@256bit.org>
parents:
9436
diff
changeset
|
3518 || redir_reg || redir_vname || redir_execute |
1854 | 3519 #endif |
3520 ; | |
3521 } | |
3522 | |
7 | 3523 /* |
1189 | 3524 * Before giving verbose message. |
291 | 3525 * Must always be called paired with verbose_leave()! |
3526 */ | |
3527 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3528 verbose_enter(void) |
291 | 3529 { |
3530 if (*p_vfile != NUL) | |
3531 ++msg_silent; | |
3532 } | |
3533 | |
3534 /* | |
3535 * After giving verbose message. | |
3536 * Must always be called paired with verbose_enter()! | |
3537 */ | |
3538 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3539 verbose_leave(void) |
291 | 3540 { |
3541 if (*p_vfile != NUL) | |
3542 if (--msg_silent < 0) | |
3543 msg_silent = 0; | |
3544 } | |
3545 | |
3546 /* | |
3547 * Like verbose_enter() and set msg_scroll when displaying the message. | |
3548 */ | |
3549 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3550 verbose_enter_scroll(void) |
291 | 3551 { |
3552 if (*p_vfile != NUL) | |
3553 ++msg_silent; | |
3554 else | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3555 // always scroll up, don't overwrite |
291 | 3556 msg_scroll = TRUE; |
3557 } | |
3558 | |
3559 /* | |
3560 * Like verbose_leave() and set cmdline_row when displaying the message. | |
3561 */ | |
3562 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3563 verbose_leave_scroll(void) |
291 | 3564 { |
3565 if (*p_vfile != NUL) | |
3566 { | |
3567 if (--msg_silent < 0) | |
3568 msg_silent = 0; | |
3569 } | |
3570 else | |
3571 cmdline_row = msg_row; | |
3572 } | |
3573 | |
3574 /* | |
3575 * Called when 'verbosefile' is set: stop writing to the file. | |
3576 */ | |
3577 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3578 verbose_stop(void) |
291 | 3579 { |
3580 if (verbose_fd != NULL) | |
3581 { | |
3582 fclose(verbose_fd); | |
3583 verbose_fd = NULL; | |
3584 } | |
3585 verbose_did_open = FALSE; | |
3586 } | |
3587 | |
3588 /* | |
3589 * Open the file 'verbosefile'. | |
3590 * Return FAIL or OK. | |
3591 */ | |
3592 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3593 verbose_open(void) |
291 | 3594 { |
3595 if (verbose_fd == NULL && !verbose_did_open) | |
3596 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3597 // Only give the error message once. |
291 | 3598 verbose_did_open = TRUE; |
3599 | |
531 | 3600 verbose_fd = mch_fopen((char *)p_vfile, "a"); |
291 | 3601 if (verbose_fd == NULL) |
3602 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
3603 semsg(_(e_notopen), p_vfile); |
291 | 3604 return FAIL; |
3605 } | |
3606 } | |
3607 return OK; | |
3608 } | |
3609 | |
3610 /* | |
7 | 3611 * Give a warning message (for searching). |
3612 * Use 'w' highlighting and may repeat the message after redrawing | |
3613 */ | |
3614 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3615 give_warning(char_u *message, int hl) |
7 | 3616 { |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3617 give_warning_with_source(message, hl, FALSE); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3618 } |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3619 |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3620 void |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3621 give_warning_with_source(char_u *message, int hl, int with_source) |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3622 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3623 // Don't do this for ":silent". |
7 | 3624 if (msg_silent != 0) |
3625 return; | |
3626 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3627 // Don't want a hit-enter prompt here. |
7 | 3628 ++no_wait_return; |
8 | 3629 |
7 | 3630 #ifdef FEAT_EVAL |
3631 set_vim_var_string(VV_WARNINGMSG, message, -1); | |
3632 #endif | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13188
diff
changeset
|
3633 VIM_CLEAR(keep_msg); |
7 | 3634 if (hl) |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
3635 keep_msg_attr = HL_ATTR(HLF_W); |
7 | 3636 else |
3637 keep_msg_attr = 0; | |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3638 |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3639 if (with_source) |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3640 { |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3641 // Do what msg() does, but with a column offset if the warning should |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3642 // be after the mode message. |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3643 msg_start(); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3644 msg_source(HL_ATTR(HLF_W)); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3645 msg_puts(" "); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3646 msg_puts_attr((char *)message, HL_ATTR(HLF_W) | MSG_HIST); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3647 msg_clr_eos(); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3648 (void)msg_end(); |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3649 } |
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3650 else if (msg_attr((char *)message, keep_msg_attr) && msg_scrolled == 0) |
678 | 3651 set_keep_msg(message, keep_msg_attr); |
25226
a9ea83a3659a
patch 8.2.3149: some plugins have a problem with the error check
Bram Moolenaar <Bram@vim.org>
parents:
24938
diff
changeset
|
3652 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3653 msg_didout = FALSE; // overwrite this message |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3654 msg_nowait = TRUE; // don't wait for this message |
7 | 3655 msg_col = 0; |
8 | 3656 |
7 | 3657 --no_wait_return; |
3658 } | |
3659 | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15551
diff
changeset
|
3660 #if defined(FEAT_EVAL) || defined(PROTO) |
11561
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3661 void |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3662 give_warning2(char_u *message, char_u *a1, int hl) |
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3663 { |
18309
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3664 if (IObuff == NULL) |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3665 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3666 // Very early in initialisation and already something wrong, just give |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3667 // the raw message so the user at least gets a hint. |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3668 give_warning((char_u *)message, hl); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3669 } |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3670 else |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3671 { |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3672 vim_snprintf((char *)IObuff, IOSIZE, (char *)message, a1); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3673 give_warning(IObuff, hl); |
2047cb93eb0c
patch 8.1.2149: crash when running out of memory very early
Bram Moolenaar <Bram@vim.org>
parents:
18293
diff
changeset
|
3674 } |
11561
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3675 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15551
diff
changeset
|
3676 #endif |
11561
7ad79766365a
patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents:
11269
diff
changeset
|
3677 |
7 | 3678 /* |
3679 * Advance msg cursor to column "col". | |
3680 */ | |
3681 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3682 msg_advance(int col) |
7 | 3683 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3684 if (msg_silent != 0) // nothing to advance to |
7 | 3685 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3686 msg_col = col; // for redirection, may fill it up later |
7 | 3687 return; |
3688 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3689 if (col >= Columns) // not enough room |
7 | 3690 col = Columns - 1; |
474 | 3691 #ifdef FEAT_RIGHTLEFT |
3692 if (cmdmsg_rl) | |
3693 while (msg_col > Columns - col) | |
3694 msg_putchar(' '); | |
3695 else | |
3696 #endif | |
3697 while (msg_col < col) | |
3698 msg_putchar(' '); | |
7 | 3699 } |
3700 | |
3701 #if defined(FEAT_CON_DIALOG) || defined(PROTO) | |
3702 /* | |
3703 * Used for "confirm()" function, and the :confirm command prefix. | |
3704 * Versions which haven't got flexible dialogs yet, and console | |
3705 * versions, get this generic handler which uses the command line. | |
3706 * | |
3707 * type = one of: | |
3708 * VIM_QUESTION, VIM_INFO, VIM_WARNING, VIM_ERROR or VIM_GENERIC | |
3709 * title = title string (can be NULL for default) | |
3710 * (neither used in console dialogs at the moment) | |
3711 * | |
3712 * Format of the "buttons" string: | |
3713 * "Button1Name\nButton2Name\nButton3Name" | |
3714 * The first button should normally be the default/accept | |
3715 * The second button should be the 'Cancel' button | |
3716 * Other buttons- use your imagination! | |
3717 * A '&' in a button name becomes a shortcut, so each '&' should be before a | |
3718 * different letter. | |
3719 */ | |
3720 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3721 do_dialog( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3722 int type UNUSED, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3723 char_u *title UNUSED, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3724 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3725 char_u *buttons, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3726 int dfltbutton, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3727 char_u *textfield UNUSED, // IObuff for inputdialog(), NULL |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3728 // otherwise |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3729 int ex_cmd) // when TRUE pressing : accepts default and starts |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3730 // Ex command |
7 | 3731 { |
3732 int oldState; | |
3733 int retval = 0; | |
3734 char_u *hotkeys; | |
3735 int c; | |
3736 int i; | |
21192
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3737 tmode_T save_tmode; |
7 | 3738 |
3739 #ifndef NO_CONSOLE | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3740 // Don't output anything in silent mode ("ex -s") |
7 | 3741 if (silent_mode) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3742 return dfltbutton; // return default option |
7 | 3743 #endif |
3744 | |
3745 #ifdef FEAT_GUI_DIALOG | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3746 // When GUI is running and 'c' not in 'guioptions', use the GUI dialog |
7 | 3747 if (gui.in_use && vim_strchr(p_go, GO_CONDIALOG) == NULL) |
3748 { | |
3749 c = gui_mch_dialog(type, title, message, buttons, dfltbutton, | |
2684 | 3750 textfield, ex_cmd); |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3751 // avoid a hit-enter prompt without clearing the cmdline |
1809 | 3752 need_wait_return = FALSE; |
3753 emsg_on_display = FALSE; | |
3754 cmdline_row = msg_row; | |
7 | 3755 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3756 // Flush output to avoid that further messages and redrawing is done |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3757 // in the wrong order. |
7 | 3758 out_flush(); |
3759 gui_mch_update(); | |
3760 | |
3761 return c; | |
3762 } | |
3763 #endif | |
3764 | |
3765 oldState = State; | |
3766 State = CONFIRM; | |
3767 setmouse(); | |
3768 | |
21192
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3769 // Ensure raw mode here. |
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3770 save_tmode = cur_tmode; |
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3771 settmode(TMODE_RAW); |
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3772 |
7 | 3773 /* |
3774 * Since we wait for a keypress, don't make the | |
3775 * user press RETURN as well afterwards. | |
3776 */ | |
3777 ++no_wait_return; | |
3778 hotkeys = msg_show_console_dialog(message, buttons, dfltbutton); | |
3779 | |
3780 if (hotkeys != NULL) | |
3781 { | |
3782 for (;;) | |
3783 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3784 // Get a typed character directly from the user. |
7 | 3785 c = get_keystroke(); |
3786 switch (c) | |
3787 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3788 case CAR: // User accepts default option |
7 | 3789 case NL: |
3790 retval = dfltbutton; | |
3791 break; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3792 case Ctrl_C: // User aborts/cancels |
7 | 3793 case ESC: |
3794 retval = 0; | |
3795 break; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3796 default: // Could be a hotkey? |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3797 if (c < 0) // special keys are ignored here |
7 | 3798 continue; |
2684 | 3799 if (c == ':' && ex_cmd) |
3800 { | |
3801 retval = dfltbutton; | |
20571
5995db0fe84a
patch 8.2.0839: dropping modifier when putting a character back in typeahead
Bram Moolenaar <Bram@vim.org>
parents:
20162
diff
changeset
|
3802 ins_char_typebuf(':', 0); |
2684 | 3803 break; |
3804 } | |
3805 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3806 // Make the character lowercase, as chars in "hotkeys" are. |
7 | 3807 c = MB_TOLOWER(c); |
3808 retval = 1; | |
3809 for (i = 0; hotkeys[i]; ++i) | |
3810 { | |
3811 if (has_mbyte) | |
3812 { | |
3813 if ((*mb_ptr2char)(hotkeys + i) == c) | |
3814 break; | |
474 | 3815 i += (*mb_ptr2len)(hotkeys + i) - 1; |
7 | 3816 } |
3817 else | |
3818 if (hotkeys[i] == c) | |
3819 break; | |
3820 ++retval; | |
3821 } | |
3822 if (hotkeys[i]) | |
3823 break; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3824 // No hotkey match, so keep waiting |
7 | 3825 continue; |
3826 } | |
3827 break; | |
3828 } | |
3829 | |
3830 vim_free(hotkeys); | |
3831 } | |
3832 | |
21192
0016cba920ef
patch 8.2.1147: :confirm may happen in cooked mode
Bram Moolenaar <Bram@vim.org>
parents:
20782
diff
changeset
|
3833 settmode(save_tmode); |
7 | 3834 State = oldState; |
3835 setmouse(); | |
3836 --no_wait_return; | |
3837 msg_end_prompt(); | |
3838 | |
3839 return retval; | |
3840 } | |
3841 | |
3842 /* | |
3843 * Copy one character from "*from" to "*to", taking care of multi-byte | |
3844 * characters. Return the length of the character in bytes. | |
3845 */ | |
3846 static int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3847 copy_char( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3848 char_u *from, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3849 char_u *to, |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3850 int lowercase) // make character lower case |
7 | 3851 { |
3852 int len; | |
3853 int c; | |
3854 | |
3855 if (has_mbyte) | |
3856 { | |
3857 if (lowercase) | |
3858 { | |
3859 c = MB_TOLOWER((*mb_ptr2char)(from)); | |
3860 return (*mb_char2bytes)(c, to); | |
3861 } | |
3862 else | |
3863 { | |
474 | 3864 len = (*mb_ptr2len)(from); |
7 | 3865 mch_memmove(to, from, (size_t)len); |
3866 return len; | |
3867 } | |
3868 } | |
3869 else | |
3870 { | |
3871 if (lowercase) | |
3872 *to = (char_u)TOLOWER_LOC(*from); | |
3873 else | |
3874 *to = *from; | |
3875 return 1; | |
3876 } | |
3877 } | |
3878 | |
3879 /* | |
3880 * Format the dialog string, and display it at the bottom of | |
3881 * the screen. Return a string of hotkey chars (if defined) for | |
3882 * each 'button'. If a button has no hotkey defined, the first character of | |
3883 * the button is used. | |
3884 * The hotkeys can be multi-byte characters, but without combining chars. | |
3885 * | |
3886 * Returns an allocated string with hotkeys, or NULL for error. | |
3887 */ | |
3888 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3889 msg_show_console_dialog( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3890 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3891 char_u *buttons, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
3892 int dfltbutton) |
7 | 3893 { |
3894 int len = 0; | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3895 #define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3896 int lenhotkey = HOTK_LEN; // count first button |
7 | 3897 char_u *hotk = NULL; |
3898 char_u *msgp = NULL; | |
3899 char_u *hotkp = NULL; | |
3900 char_u *r; | |
3901 int copy; | |
3902 #define HAS_HOTKEY_LEN 30 | |
3903 char_u has_hotkey[HAS_HOTKEY_LEN]; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3904 int first_hotkey = FALSE; // first char of button is hotkey |
7 | 3905 int idx; |
3906 | |
3907 has_hotkey[0] = FALSE; | |
3908 | |
3909 /* | |
3910 * First loop: compute the size of memory to allocate. | |
3911 * Second loop: copy to the allocated memory. | |
3912 */ | |
3913 for (copy = 0; copy <= 1; ++copy) | |
3914 { | |
3915 r = buttons; | |
3916 idx = 0; | |
3917 while (*r) | |
3918 { | |
3919 if (*r == DLG_BUTTON_SEP) | |
3920 { | |
3921 if (copy) | |
3922 { | |
3923 *msgp++ = ','; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3924 *msgp++ = ' '; // '\n' -> ', ' |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3925 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3926 // advance to next hotkey and set default hotkey |
7 | 3927 if (has_mbyte) |
1306 | 3928 hotkp += STRLEN(hotkp); |
7 | 3929 else |
3930 ++hotkp; | |
1306 | 3931 hotkp[copy_char(r + 1, hotkp, TRUE)] = NUL; |
7 | 3932 if (dfltbutton) |
3933 --dfltbutton; | |
3934 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3935 // If no hotkey is specified first char is used. |
7 | 3936 if (idx < HAS_HOTKEY_LEN - 1 && !has_hotkey[++idx]) |
3937 first_hotkey = TRUE; | |
3938 } | |
3939 else | |
3940 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3941 len += 3; // '\n' -> ', '; 'x' -> '(x)' |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3942 lenhotkey += HOTK_LEN; // each button needs a hotkey |
7 | 3943 if (idx < HAS_HOTKEY_LEN - 1) |
3944 has_hotkey[++idx] = FALSE; | |
3945 } | |
3946 } | |
3947 else if (*r == DLG_HOTKEY_CHAR || first_hotkey) | |
3948 { | |
3949 if (*r == DLG_HOTKEY_CHAR) | |
3950 ++r; | |
3951 first_hotkey = FALSE; | |
3952 if (copy) | |
3953 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3954 if (*r == DLG_HOTKEY_CHAR) // '&&a' -> '&a' |
7 | 3955 *msgp++ = *r; |
3956 else | |
3957 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3958 // '&a' -> '[a]' |
7 | 3959 *msgp++ = (dfltbutton == 1) ? '[' : '('; |
3960 msgp += copy_char(r, msgp, FALSE); | |
3961 *msgp++ = (dfltbutton == 1) ? ']' : ')'; | |
3962 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3963 // redefine hotkey |
1306 | 3964 hotkp[copy_char(r, hotkp, TRUE)] = NUL; |
7 | 3965 } |
3966 } | |
3967 else | |
3968 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3969 ++len; // '&a' -> '[a]' |
7 | 3970 if (idx < HAS_HOTKEY_LEN - 1) |
3971 has_hotkey[idx] = TRUE; | |
3972 } | |
3973 } | |
3974 else | |
3975 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3976 // everything else copy literally |
7 | 3977 if (copy) |
3978 msgp += copy_char(r, msgp, FALSE); | |
3979 } | |
3980 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3981 // advance to the next character |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11016
diff
changeset
|
3982 MB_PTR_ADV(r); |
7 | 3983 } |
3984 | |
3985 if (copy) | |
3986 { | |
3987 *msgp++ = ':'; | |
3988 *msgp++ = ' '; | |
3989 *msgp = NUL; | |
3990 } | |
3991 else | |
3992 { | |
835 | 3993 len += (int)(STRLEN(message) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3994 + 2 // for the NL's |
856 | 3995 + STRLEN(buttons) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3996 + 3); // for the ": " and NUL |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3997 lenhotkey++; // for the NUL |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3998 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
3999 // If no hotkey is specified first char is used. |
7 | 4000 if (!has_hotkey[0]) |
4001 { | |
4002 first_hotkey = TRUE; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4003 len += 2; // "x" -> "[x]" |
7 | 4004 } |
4005 | |
4006 /* | |
4007 * Now allocate and load the strings | |
4008 */ | |
4009 vim_free(confirm_msg); | |
4010 confirm_msg = alloc(len); | |
4011 if (confirm_msg == NULL) | |
4012 return NULL; | |
4013 *confirm_msg = NUL; | |
4014 hotk = alloc(lenhotkey); | |
4015 if (hotk == NULL) | |
4016 return NULL; | |
4017 | |
4018 *confirm_msg = '\n'; | |
4019 STRCPY(confirm_msg + 1, message); | |
4020 | |
4021 msgp = confirm_msg + 1 + STRLEN(message); | |
4022 hotkp = hotk; | |
4023 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4024 // Define first default hotkey. Keep the hotkey string NUL |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4025 // terminated to avoid reading past the end. |
1306 | 4026 hotkp[copy_char(buttons, hotkp, TRUE)] = NUL; |
7 | 4027 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4028 // Remember where the choices start, displaying starts here when |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4029 // "hotkp" typed at the more prompt. |
7 | 4030 confirm_msg_tail = msgp; |
4031 *msgp++ = '\n'; | |
4032 } | |
4033 } | |
4034 | |
4035 display_confirm_msg(); | |
4036 return hotk; | |
4037 } | |
4038 | |
4039 /* | |
4040 * Display the ":confirm" message. Also called when screen resized. | |
4041 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17262
diff
changeset
|
4042 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4043 display_confirm_msg(void) |
7 | 4044 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4045 // avoid that 'q' at the more prompt truncates the message here |
7 | 4046 ++confirm_msg_used; |
4047 if (confirm_msg != NULL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15502
diff
changeset
|
4048 msg_puts_attr((char *)confirm_msg, HL_ATTR(HLF_M)); |
7 | 4049 --confirm_msg_used; |
4050 } | |
4051 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4052 #endif // FEAT_CON_DIALOG |
7 | 4053 |
4054 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) | |
4055 | |
4056 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4057 vim_dialog_yesno( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4058 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4059 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4060 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4061 int dflt) |
7 | 4062 { |
4063 if (do_dialog(type, | |
4064 title == NULL ? (char_u *)_("Question") : title, | |
4065 message, | |
2684 | 4066 (char_u *)_("&Yes\n&No"), dflt, NULL, FALSE) == 1) |
7 | 4067 return VIM_YES; |
4068 return VIM_NO; | |
4069 } | |
4070 | |
4071 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4072 vim_dialog_yesnocancel( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4073 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4074 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4075 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4076 int dflt) |
7 | 4077 { |
4078 switch (do_dialog(type, | |
4079 title == NULL ? (char_u *)_("Question") : title, | |
4080 message, | |
2684 | 4081 (char_u *)_("&Yes\n&No\n&Cancel"), dflt, NULL, FALSE)) |
7 | 4082 { |
4083 case 1: return VIM_YES; | |
4084 case 2: return VIM_NO; | |
4085 } | |
4086 return VIM_CANCEL; | |
4087 } | |
4088 | |
4089 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4090 vim_dialog_yesnoallcancel( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4091 int type, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4092 char_u *title, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4093 char_u *message, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4094 int dflt) |
7 | 4095 { |
4096 switch (do_dialog(type, | |
4097 title == NULL ? (char_u *)"Question" : title, | |
4098 message, | |
4099 (char_u *)_("&Yes\n&No\nSave &All\n&Discard All\n&Cancel"), | |
2684 | 4100 dflt, NULL, FALSE)) |
7 | 4101 { |
4102 case 1: return VIM_YES; | |
4103 case 2: return VIM_NO; | |
4104 case 3: return VIM_ALL; | |
4105 case 4: return VIM_DISCARDALL; | |
4106 } | |
4107 return VIM_CANCEL; | |
4108 } | |
4109 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4110 #endif // FEAT_GUI_DIALOG || FEAT_CON_DIALOG |
7 | 4111 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4112 #if defined(FEAT_EVAL) |
449 | 4113 static char *e_printf = N_("E766: Insufficient arguments for printf()"); |
4114 | |
4115 /* | |
4116 * Get number argument from "idxp" entry in "tvs". First entry is 1. | |
4117 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4118 static varnumber_T |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4119 tv_nr(typval_T *tvs, int *idxp) |
449 | 4120 { |
4121 int idx = *idxp - 1; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4122 varnumber_T n = 0; |
449 | 4123 int err = FALSE; |
4124 | |
4125 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4126 emsg(_(e_printf)); |
449 | 4127 else |
4128 { | |
4129 ++*idxp; | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
4130 n = tv_get_number_chk(&tvs[idx], &err); |
449 | 4131 if (err) |
4132 n = 0; | |
4133 } | |
4134 return n; | |
4135 } | |
4136 | |
4137 /* | |
4138 * Get string argument from "idxp" entry in "tvs". First entry is 1. | |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
4139 * If "tofree" is NULL tv_get_string_chk() is used. Some types (e.g. List) |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4140 * are not converted to a string. |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4141 * If "tofree" is not NULL echo_string() is used. All types are converted to |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4142 * a string with the same format as ":echo". The caller must free "*tofree". |
532 | 4143 * Returns NULL for an error. |
449 | 4144 */ |
4145 static char * | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4146 tv_str(typval_T *tvs, int *idxp, char_u **tofree) |
449 | 4147 { |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4148 int idx = *idxp - 1; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4149 char *s = NULL; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4150 static char_u numbuf[NUMBUFLEN]; |
449 | 4151 |
4152 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4153 emsg(_(e_printf)); |
449 | 4154 else |
4155 { | |
4156 ++*idxp; | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4157 if (tofree != NULL) |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4158 s = (char *)echo_string(&tvs[idx], tofree, numbuf, get_copyID()); |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4159 else |
15211
de63593896b3
patch 8.1.0615: get_tv function names are not consistent
Bram Moolenaar <Bram@vim.org>
parents:
15079
diff
changeset
|
4160 s = (char *)tv_get_string_chk(&tvs[idx]); |
449 | 4161 } |
4162 return s; | |
4163 } | |
1619 | 4164 |
4165 # ifdef FEAT_FLOAT | |
4166 /* | |
4167 * Get float argument from "idxp" entry in "tvs". First entry is 1. | |
4168 */ | |
4169 static double | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4170 tv_float(typval_T *tvs, int *idxp) |
1619 | 4171 { |
4172 int idx = *idxp - 1; | |
4173 double f = 0; | |
4174 | |
4175 if (tvs[idx].v_type == VAR_UNKNOWN) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4176 emsg(_(e_printf)); |
1619 | 4177 else |
4178 { | |
4179 ++*idxp; | |
4180 if (tvs[idx].v_type == VAR_FLOAT) | |
4181 f = tvs[idx].vval.v_float; | |
1656 | 4182 else if (tvs[idx].v_type == VAR_NUMBER) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4183 f = (double)tvs[idx].vval.v_number; |
1619 | 4184 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4185 emsg(_("E807: Expected Float argument for printf()")); |
1619 | 4186 } |
4187 return f; | |
4188 } | |
4189 # endif | |
449 | 4190 #endif |
4191 | |
10036
ab6320d74331
commit https://github.com/vim/vim/commit/7f7bd297d6d989254f71c694f1c72d07cbc5c306
Christian Brabandt <cb@256bit.org>
parents:
10015
diff
changeset
|
4192 #ifdef FEAT_FLOAT |
272 | 4193 /* |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4194 * Return the representation of infinity for printf() function: |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4195 * "-inf", "inf", "+inf", " inf", "-INF", "INF", "+INF" or " INF". |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4196 */ |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4197 static const char * |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4198 infinity_str(int positive, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4199 char fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4200 int force_sign, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4201 int space_for_positive) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4202 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4203 static const char *table[] = |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4204 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4205 "-inf", "inf", "+inf", " inf", |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4206 "-INF", "INF", "+INF", " INF" |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4207 }; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4208 int idx = positive * (1 + force_sign + force_sign * space_for_positive); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4209 |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4210 if (ASCII_ISUPPER(fmt_spec)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4211 idx += 4; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4212 return table[idx]; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4213 } |
10036
ab6320d74331
commit https://github.com/vim/vim/commit/7f7bd297d6d989254f71c694f1c72d07cbc5c306
Christian Brabandt <cb@256bit.org>
parents:
10015
diff
changeset
|
4214 #endif |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4215 |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4216 /* |
272 | 4217 * This code was included to provide a portable vsnprintf() and snprintf(). |
715 | 4218 * Some systems may provide their own, but we always use this one for |
272 | 4219 * consistency. |
4220 * | |
4221 * This code is based on snprintf.c - a portable implementation of snprintf | |
4222 * by Mark Martinec <mark.martinec@ijs.si>, Version 2.2, 2000-10-06. | |
1189 | 4223 * Included with permission. It was heavily modified to fit in Vim. |
272 | 4224 * The original code, including useful comments, can be found here: |
4225 * http://www.ijs.si/software/snprintf/ | |
4226 * | |
4227 * This snprintf() only supports the following conversion specifiers: | |
4228 * s, c, d, u, o, x, X, p (and synonyms: i, D, U, O - see below) | |
4229 * with flags: '-', '+', ' ', '0' and '#'. | |
4230 * An asterisk is supported for field width as well as precision. | |
4231 * | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4232 * Limited support for floating point was added: 'f', 'F', 'e', 'E', 'g', 'G'. |
1619 | 4233 * |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4234 * Length modifiers 'h' (short int) and 'l' (long int) and 'll' (long long int) |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4235 * are supported. NOTE: for 'll' the argument is varnumber_T or uvarnumber_T. |
272 | 4236 * |
437 | 4237 * The locale is not used, the string is used as a byte string. This is only |
4238 * relevant for double-byte encodings where the second byte may be '%'. | |
4239 * | |
715 | 4240 * It is permitted for "str_m" to be zero, and it is permitted to specify NULL |
4241 * pointer for resulting string argument if "str_m" is zero (as per ISO C99). | |
272 | 4242 * |
4243 * The return value is the number of characters which would be generated | |
6448 | 4244 * for the given input, excluding the trailing NUL. If this value |
715 | 4245 * is greater or equal to "str_m", not all characters from the result |
4246 * have been stored in str, output bytes beyond the ("str_m"-1) -th character | |
4247 * are discarded. If "str_m" is greater than zero it is guaranteed | |
6448 | 4248 * the resulting string will be NUL-terminated. |
272 | 4249 */ |
4250 | |
4251 /* | |
4252 * When va_list is not supported we only define vim_snprintf(). | |
449 | 4253 * |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4254 * vim_vsnprintf_typval() can be invoked with either "va_list" or a list of |
482 | 4255 * "typval_T". When the latter is not used it must be NULL. |
272 | 4256 */ |
4257 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4258 // When generating prototypes all of this is skipped, cproto doesn't |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4259 // understand this. |
272 | 4260 #ifndef PROTO |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4261 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4262 // Like vim_vsnprintf() but append to the string. |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4263 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4264 vim_snprintf_add(char *str, size_t str_m, const char *fmt, ...) |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4265 { |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4266 va_list ap; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4267 int str_l; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4268 size_t len = STRLEN(str); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4269 size_t space; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4270 |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4271 if (str_m <= len) |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4272 space = 0; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4273 else |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4274 space = str_m - len; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4275 va_start(ap, fmt); |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4276 str_l = vim_vsnprintf(str + len, space, fmt, ap); |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4277 va_end(ap); |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4278 return str_l; |
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
4279 } |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4280 |
272 | 4281 int |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4282 vim_snprintf(char *str, size_t str_m, const char *fmt, ...) |
272 | 4283 { |
4284 va_list ap; | |
4285 int str_l; | |
4286 | |
4287 va_start(ap, fmt); | |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4288 str_l = vim_vsnprintf(str, str_m, fmt, ap); |
272 | 4289 va_end(ap); |
4290 return str_l; | |
4291 } | |
4292 | |
449 | 4293 int |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4294 vim_vsnprintf( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4295 char *str, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4296 size_t str_m, |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4297 const char *fmt, |
11653
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4298 va_list ap) |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4299 { |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4300 return vim_vsnprintf_typval(str, str_m, fmt, ap, NULL); |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4301 } |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4302 |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4303 int |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4304 vim_vsnprintf_typval( |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4305 char *str, |
67cf0d45b006
patch 8.0.0709: libvterm cannot use vsnprintf()
Christian Brabandt <cb@256bit.org>
parents:
11561
diff
changeset
|
4306 size_t str_m, |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4307 const char *fmt, |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4308 va_list ap, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
4309 typval_T *tvs) |
272 | 4310 { |
4311 size_t str_l = 0; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4312 const char *p = fmt; |
272 | 4313 int arg_idx = 1; |
4314 | |
4315 if (p == NULL) | |
4316 p = ""; | |
4317 while (*p != NUL) | |
4318 { | |
4319 if (*p != '%') | |
4320 { | |
4321 char *q = strchr(p + 1, '%'); | |
1883 | 4322 size_t n = (q == NULL) ? STRLEN(p) : (size_t)(q - p); |
272 | 4323 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4324 // Copy up to the next '%' or NUL without any changes. |
272 | 4325 if (str_l < str_m) |
4326 { | |
4327 size_t avail = str_m - str_l; | |
4328 | |
4329 mch_memmove(str + str_l, p, n > avail ? avail : n); | |
4330 } | |
4331 p += n; | |
4332 str_l += n; | |
4333 } | |
4334 else | |
4335 { | |
4336 size_t min_field_width = 0, precision = 0; | |
4337 int zero_padding = 0, precision_specified = 0, justify_left = 0; | |
4338 int alternate_form = 0, force_sign = 0; | |
4339 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4340 // If both the ' ' and '+' flags appear, the ' ' flag should be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4341 // ignored. |
272 | 4342 int space_for_positive = 1; |
4343 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4344 // allowed values: \0, h, l, L |
272 | 4345 char length_modifier = '\0'; |
4346 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4347 // temporary buffer for simple numeric->string conversion |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4348 # if defined(FEAT_FLOAT) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4349 # define TMP_LEN 350 // On my system 1e308 is the biggest number possible. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4350 // That sounds reasonable to use as the maximum |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4351 // printable. |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4352 # else |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4353 # define TMP_LEN 66 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4354 # endif |
1619 | 4355 char tmp[TMP_LEN]; |
272 | 4356 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4357 // string address in case of string argument |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
4358 const char *str_arg = NULL; |
272 | 4359 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4360 // natural field width of arg without padding and sign |
272 | 4361 size_t str_arg_l; |
4362 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4363 // unsigned char argument value - only defined for c conversion. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4364 // N.B. standard explicitly states the char argument for the c |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4365 // conversion is unsigned |
272 | 4366 unsigned char uchar_arg; |
4367 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4368 // number of zeros to be inserted for numeric conversions as |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4369 // required by the precision or minimal field width |
272 | 4370 size_t number_of_zeros_to_pad = 0; |
4371 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4372 // index into tmp where zero padding is to be inserted |
272 | 4373 size_t zero_padding_insertion_ind = 0; |
4374 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4375 // current conversion specifier character |
272 | 4376 char fmt_spec = '\0'; |
4377 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4378 // buffer for 's' and 'S' specs |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4379 char_u *tofree = NULL; |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4380 |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4381 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4382 p++; // skip '%' |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4383 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4384 // parse flags |
272 | 4385 while (*p == '0' || *p == '-' || *p == '+' || *p == ' ' |
4386 || *p == '#' || *p == '\'') | |
4387 { | |
4388 switch (*p) | |
4389 { | |
4390 case '0': zero_padding = 1; break; | |
4391 case '-': justify_left = 1; break; | |
4392 case '+': force_sign = 1; space_for_positive = 0; break; | |
4393 case ' ': force_sign = 1; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4394 // If both the ' ' and '+' flags appear, the ' ' |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4395 // flag should be ignored |
272 | 4396 break; |
4397 case '#': alternate_form = 1; break; | |
4398 case '\'': break; | |
4399 } | |
4400 p++; | |
4401 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4402 // If the '0' and '-' flags both appear, the '0' flag should be |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4403 // ignored. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4404 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4405 // parse field width |
272 | 4406 if (*p == '*') |
4407 { | |
4408 int j; | |
4409 | |
4410 p++; | |
449 | 4411 j = |
4412 # if defined(FEAT_EVAL) | |
482 | 4413 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4414 # endif |
4415 va_arg(ap, int); | |
272 | 4416 if (j >= 0) |
4417 min_field_width = j; | |
4418 else | |
4419 { | |
4420 min_field_width = -j; | |
4421 justify_left = 1; | |
4422 } | |
4423 } | |
4424 else if (VIM_ISDIGIT((int)(*p))) | |
4425 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4426 // size_t could be wider than unsigned int; make sure we treat |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4427 // argument like common implementations do |
272 | 4428 unsigned int uj = *p++ - '0'; |
4429 | |
4430 while (VIM_ISDIGIT((int)(*p))) | |
4431 uj = 10 * uj + (unsigned int)(*p++ - '0'); | |
4432 min_field_width = uj; | |
4433 } | |
4434 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4435 // parse precision |
272 | 4436 if (*p == '.') |
4437 { | |
4438 p++; | |
4439 precision_specified = 1; | |
4440 if (*p == '*') | |
4441 { | |
4442 int j; | |
4443 | |
449 | 4444 j = |
4445 # if defined(FEAT_EVAL) | |
482 | 4446 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4447 # endif |
4448 va_arg(ap, int); | |
272 | 4449 p++; |
4450 if (j >= 0) | |
4451 precision = j; | |
4452 else | |
4453 { | |
4454 precision_specified = 0; | |
4455 precision = 0; | |
4456 } | |
4457 } | |
4458 else if (VIM_ISDIGIT((int)(*p))) | |
4459 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4460 // size_t could be wider than unsigned int; make sure we |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4461 // treat argument like common implementations do |
272 | 4462 unsigned int uj = *p++ - '0'; |
4463 | |
4464 while (VIM_ISDIGIT((int)(*p))) | |
4465 uj = 10 * uj + (unsigned int)(*p++ - '0'); | |
4466 precision = uj; | |
4467 } | |
4468 } | |
4469 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4470 // parse 'h', 'l' and 'll' length modifiers |
272 | 4471 if (*p == 'h' || *p == 'l') |
4472 { | |
4473 length_modifier = *p; | |
4474 p++; | |
4475 if (length_modifier == 'l' && *p == 'l') | |
4476 { | |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4477 // double l = __int64 / varnumber_T |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4478 length_modifier = 'L'; |
272 | 4479 p++; |
4480 } | |
4481 } | |
4482 fmt_spec = *p; | |
4483 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4484 // common synonyms: |
272 | 4485 switch (fmt_spec) |
4486 { | |
4487 case 'i': fmt_spec = 'd'; break; | |
4488 case 'D': fmt_spec = 'd'; length_modifier = 'l'; break; | |
4489 case 'U': fmt_spec = 'u'; length_modifier = 'l'; break; | |
4490 case 'O': fmt_spec = 'o'; length_modifier = 'l'; break; | |
4491 default: break; | |
4492 } | |
4493 | |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4494 # if defined(FEAT_EVAL) |
9497
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4495 switch (fmt_spec) |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4496 { |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4497 case 'd': case 'u': case 'o': case 'x': case 'X': |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4498 if (tvs != NULL && length_modifier == '\0') |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4499 length_modifier = 'L'; |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4500 } |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4501 # endif |
d18d71ae21e5
commit https://github.com/vim/vim/commit/38ee6b041e73ad31c3b6b99d56d20833b59b2b57
Christian Brabandt <cb@256bit.org>
parents:
9454
diff
changeset
|
4502 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4503 // get parameter value, do initial processing |
272 | 4504 switch (fmt_spec) |
4505 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4506 // '%' and 'c' behave similar to 's' regarding flags and field |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4507 // widths |
272 | 4508 case '%': |
4509 case 'c': | |
4510 case 's': | |
3914 | 4511 case 'S': |
272 | 4512 str_arg_l = 1; |
4513 switch (fmt_spec) | |
4514 { | |
4515 case '%': | |
4516 str_arg = p; | |
4517 break; | |
4518 | |
4519 case 'c': | |
4520 { | |
4521 int j; | |
449 | 4522 |
4523 j = | |
4524 # if defined(FEAT_EVAL) | |
482 | 4525 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4526 # endif |
4527 va_arg(ap, int); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4528 // standard demands unsigned char |
272 | 4529 uchar_arg = (unsigned char)j; |
4530 str_arg = (char *)&uchar_arg; | |
4531 break; | |
4532 } | |
4533 | |
4534 case 's': | |
3914 | 4535 case 'S': |
449 | 4536 str_arg = |
4537 # if defined(FEAT_EVAL) | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4538 tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) : |
449 | 4539 # endif |
4540 va_arg(ap, char *); | |
272 | 4541 if (str_arg == NULL) |
4542 { | |
4543 str_arg = "[NULL]"; | |
4544 str_arg_l = 6; | |
4545 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4546 // make sure not to address string beyond the specified |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4547 // precision !!! |
272 | 4548 else if (!precision_specified) |
4549 str_arg_l = strlen(str_arg); | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4550 // truncate string if necessary as requested by precision |
272 | 4551 else if (precision == 0) |
4552 str_arg_l = 0; | |
4553 else | |
4554 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4555 // Don't put the #if inside memchr(), it can be a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4556 // macro. |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4557 // memchr on HP does not like n > 2^31 !!! |
272 | 4558 char *q = memchr(str_arg, '\0', |
881 | 4559 precision <= (size_t)0x7fffffffL ? precision |
4560 : (size_t)0x7fffffffL); | |
1883 | 4561 str_arg_l = (q == NULL) ? precision |
4562 : (size_t)(q - str_arg); | |
272 | 4563 } |
3914 | 4564 if (fmt_spec == 'S') |
4565 { | |
4566 if (min_field_width != 0) | |
4567 min_field_width += STRLEN(str_arg) | |
4568 - mb_string2cells((char_u *)str_arg, -1); | |
4569 if (precision) | |
4570 { | |
18176
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4571 char_u *p1; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4572 size_t i = 0; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4573 |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4574 for (p1 = (char_u *)str_arg; *p1; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4575 p1 += mb_ptr2len(p1)) |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4576 { |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4577 i += (size_t)mb_ptr2cells(p1); |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4578 if (i > precision) |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4579 break; |
dfe9db84e326
patch 8.1.2083: multi-byte chars do not work properly with "%.*S" in printf()
Bram Moolenaar <Bram@vim.org>
parents:
18135
diff
changeset
|
4580 } |
3914 | 4581 str_arg_l = precision = p1 - (char_u *)str_arg; |
4582 } | |
4583 } | |
272 | 4584 break; |
4585 | |
4586 default: | |
4587 break; | |
4588 } | |
4589 break; | |
4590 | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4591 case 'd': case 'u': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4592 case 'b': case 'B': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4593 case 'o': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4594 case 'x': case 'X': |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4595 case 'p': |
272 | 4596 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4597 // NOTE: the u, b, o, x, X and p conversion specifiers |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4598 // imply the value is unsigned; d implies a signed |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4599 // value |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4600 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4601 // 0 if numeric argument is zero (or if pointer is |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4602 // NULL for 'p'), +1 if greater than zero (or nonzero |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4603 // for unsigned arguments), -1 if negative (unsigned |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4604 // argument is never negative) |
272 | 4605 int arg_sign = 0; |
4606 | |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4607 // only set for length modifier h, or for no length |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4608 // modifiers |
272 | 4609 int int_arg = 0; |
4610 unsigned int uint_arg = 0; | |
4611 | |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4612 // only set for length modifier l |
272 | 4613 long int long_arg = 0; |
4614 unsigned long int ulong_arg = 0; | |
4615 | |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4616 // only set for length modifier ll |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4617 varnumber_T llong_arg = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4618 uvarnumber_T ullong_arg = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4619 |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19427
diff
changeset
|
4620 // only set for b conversion |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4621 uvarnumber_T bin_arg = 0; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4622 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4623 // pointer argument value -only defined for p |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4624 // conversion |
272 | 4625 void *ptr_arg = NULL; |
4626 | |
4627 if (fmt_spec == 'p') | |
4628 { | |
4629 length_modifier = '\0'; | |
449 | 4630 ptr_arg = |
4631 # if defined(FEAT_EVAL) | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4632 tvs != NULL ? (void *)tv_str(tvs, &arg_idx, |
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
4633 NULL) : |
449 | 4634 # endif |
4635 va_arg(ap, void *); | |
272 | 4636 if (ptr_arg != NULL) |
4637 arg_sign = 1; | |
4638 } | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4639 else if (fmt_spec == 'b' || fmt_spec == 'B') |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4640 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4641 bin_arg = |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4642 # if defined(FEAT_EVAL) |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4643 tvs != NULL ? |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4644 (uvarnumber_T)tv_nr(tvs, &arg_idx) : |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4645 # endif |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4646 va_arg(ap, uvarnumber_T); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4647 if (bin_arg != 0) |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4648 arg_sign = 1; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4649 } |
272 | 4650 else if (fmt_spec == 'd') |
4651 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4652 // signed |
272 | 4653 switch (length_modifier) |
4654 { | |
4655 case '\0': | |
4656 case 'h': | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4657 // char and short arguments are passed as int. |
449 | 4658 int_arg = |
4659 # if defined(FEAT_EVAL) | |
482 | 4660 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4661 # endif |
4662 va_arg(ap, int); | |
272 | 4663 if (int_arg > 0) |
4664 arg_sign = 1; | |
4665 else if (int_arg < 0) | |
4666 arg_sign = -1; | |
4667 break; | |
4668 case 'l': | |
449 | 4669 long_arg = |
4670 # if defined(FEAT_EVAL) | |
482 | 4671 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
449 | 4672 # endif |
4673 va_arg(ap, long int); | |
272 | 4674 if (long_arg > 0) |
4675 arg_sign = 1; | |
4676 else if (long_arg < 0) | |
4677 arg_sign = -1; | |
4678 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4679 case 'L': |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4680 llong_arg = |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4681 # if defined(FEAT_EVAL) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4682 tvs != NULL ? tv_nr(tvs, &arg_idx) : |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4683 # endif |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4684 va_arg(ap, varnumber_T); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4685 if (llong_arg > 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4686 arg_sign = 1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4687 else if (llong_arg < 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4688 arg_sign = -1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4689 break; |
272 | 4690 } |
4691 } | |
4692 else | |
4693 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4694 // unsigned |
272 | 4695 switch (length_modifier) |
4696 { | |
4697 case '\0': | |
4698 case 'h': | |
449 | 4699 uint_arg = |
4700 # if defined(FEAT_EVAL) | |
1883 | 4701 tvs != NULL ? (unsigned) |
4702 tv_nr(tvs, &arg_idx) : | |
449 | 4703 # endif |
4704 va_arg(ap, unsigned int); | |
272 | 4705 if (uint_arg != 0) |
4706 arg_sign = 1; | |
4707 break; | |
4708 case 'l': | |
449 | 4709 ulong_arg = |
4710 # if defined(FEAT_EVAL) | |
1883 | 4711 tvs != NULL ? (unsigned long) |
4712 tv_nr(tvs, &arg_idx) : | |
449 | 4713 # endif |
4714 va_arg(ap, unsigned long int); | |
272 | 4715 if (ulong_arg != 0) |
4716 arg_sign = 1; | |
4717 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4718 case 'L': |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4719 ullong_arg = |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4720 # if defined(FEAT_EVAL) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4721 tvs != NULL ? (uvarnumber_T) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4722 tv_nr(tvs, &arg_idx) : |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4723 # endif |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4724 va_arg(ap, uvarnumber_T); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4725 if (ullong_arg != 0) |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4726 arg_sign = 1; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4727 break; |
272 | 4728 } |
4729 } | |
4730 | |
4731 str_arg = tmp; | |
4732 str_arg_l = 0; | |
4733 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4734 // NOTE: |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4735 // For d, i, u, o, x, and X conversions, if precision is |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4736 // specified, the '0' flag should be ignored. This is so |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4737 // with Solaris 2.6, Digital UNIX 4.0, HPUX 10, Linux, |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4738 // FreeBSD, NetBSD; but not with Perl. |
272 | 4739 if (precision_specified) |
4740 zero_padding = 0; | |
4741 if (fmt_spec == 'd') | |
4742 { | |
4743 if (force_sign && arg_sign >= 0) | |
4744 tmp[str_arg_l++] = space_for_positive ? ' ' : '+'; | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4745 // leave negative numbers for sprintf to handle, to |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4746 // avoid handling tricky cases like (short int)-32768 |
272 | 4747 } |
4748 else if (alternate_form) | |
4749 { | |
4750 if (arg_sign != 0 | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4751 && (fmt_spec == 'b' || fmt_spec == 'B' |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4752 || fmt_spec == 'x' || fmt_spec == 'X') ) |
272 | 4753 { |
4754 tmp[str_arg_l++] = '0'; | |
4755 tmp[str_arg_l++] = fmt_spec; | |
4756 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4757 // alternate form should have no effect for p |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4758 // conversion, but ... |
272 | 4759 } |
4760 | |
4761 zero_padding_insertion_ind = str_arg_l; | |
4762 if (!precision_specified) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4763 precision = 1; // default precision is 1 |
272 | 4764 if (precision == 0 && arg_sign == 0) |
4765 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4766 // When zero value is formatted with an explicit |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4767 // precision 0, the resulting formatted string is |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4768 // empty (d, i, u, b, B, o, x, X, p). |
272 | 4769 } |
4770 else | |
4771 { | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4772 char f[6]; |
272 | 4773 int f_l = 0; |
4774 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4775 // construct a simple format string for sprintf |
272 | 4776 f[f_l++] = '%'; |
4777 if (!length_modifier) | |
4778 ; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4779 else if (length_modifier == 'L') |
272 | 4780 { |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4781 # ifdef MSWIN |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4782 f[f_l++] = 'I'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4783 f[f_l++] = '6'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4784 f[f_l++] = '4'; |
19427
fdfe44ac6a1a
patch 8.2.0271: the "num64" feature is available everywhere
Bram Moolenaar <Bram@vim.org>
parents:
19181
diff
changeset
|
4785 # else |
272 | 4786 f[f_l++] = 'l'; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4787 f[f_l++] = 'l'; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4788 # endif |
272 | 4789 } |
4790 else | |
4791 f[f_l++] = length_modifier; | |
4792 f[f_l++] = fmt_spec; | |
4793 f[f_l++] = '\0'; | |
4794 | |
4795 if (fmt_spec == 'p') | |
4796 str_arg_l += sprintf(tmp + str_arg_l, f, ptr_arg); | |
9894
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4797 else if (fmt_spec == 'b' || fmt_spec == 'B') |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4798 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4799 char b[8 * sizeof(uvarnumber_T)]; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4800 size_t b_l = 0; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4801 uvarnumber_T bn = bin_arg; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4802 |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4803 do |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4804 { |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4805 b[sizeof(b) - ++b_l] = '0' + (bn & 0x1); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4806 bn >>= 1; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4807 } |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4808 while (bn != 0); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4809 |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4810 memcpy(tmp + str_arg_l, b + sizeof(b) - b_l, b_l); |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4811 str_arg_l += b_l; |
b01afb4e8f66
commit https://github.com/vim/vim/commit/91984b9034d3b698459622be277d963e0c6df60e
Christian Brabandt <cb@256bit.org>
parents:
9892
diff
changeset
|
4812 } |
272 | 4813 else if (fmt_spec == 'd') |
4814 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4815 // signed |
272 | 4816 switch (length_modifier) |
4817 { | |
19615
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4818 case '\0': str_arg_l += sprintf( |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4819 tmp + str_arg_l, f, |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4820 int_arg); |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4821 break; |
272 | 4822 case 'h': str_arg_l += sprintf( |
19615
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4823 tmp + str_arg_l, f, |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4824 (short)int_arg); |
272 | 4825 break; |
4826 case 'l': str_arg_l += sprintf( | |
4827 tmp + str_arg_l, f, long_arg); | |
4828 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4829 case 'L': str_arg_l += sprintf( |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4830 tmp + str_arg_l, f, llong_arg); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4831 break; |
272 | 4832 } |
4833 } | |
4834 else | |
4835 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4836 // unsigned |
272 | 4837 switch (length_modifier) |
4838 { | |
19615
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4839 case '\0': str_arg_l += sprintf( |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4840 tmp + str_arg_l, f, |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4841 uint_arg); |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4842 break; |
272 | 4843 case 'h': str_arg_l += sprintf( |
19615
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4844 tmp + str_arg_l, f, |
2aaef1547255
patch 8.2.0364: printf test failing on Haiku
Bram Moolenaar <Bram@vim.org>
parents:
19554
diff
changeset
|
4845 (unsigned short)uint_arg); |
272 | 4846 break; |
4847 case 'l': str_arg_l += sprintf( | |
4848 tmp + str_arg_l, f, ulong_arg); | |
4849 break; | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4850 case 'L': str_arg_l += sprintf( |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4851 tmp + str_arg_l, f, ullong_arg); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9185
diff
changeset
|
4852 break; |
272 | 4853 } |
4854 } | |
4855 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4856 // include the optional minus sign and possible |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4857 // "0x" in the region before the zero padding |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4858 // insertion point |
272 | 4859 if (zero_padding_insertion_ind < str_arg_l |
4860 && tmp[zero_padding_insertion_ind] == '-') | |
4861 zero_padding_insertion_ind++; | |
4862 if (zero_padding_insertion_ind + 1 < str_arg_l | |
4863 && tmp[zero_padding_insertion_ind] == '0' | |
4864 && (tmp[zero_padding_insertion_ind + 1] == 'x' | |
4865 || tmp[zero_padding_insertion_ind + 1] == 'X')) | |
4866 zero_padding_insertion_ind += 2; | |
4867 } | |
4868 | |
4869 { | |
4870 size_t num_of_digits = str_arg_l | |
4871 - zero_padding_insertion_ind; | |
4872 | |
4873 if (alternate_form && fmt_spec == 'o' | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4874 // unless zero is already the first |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4875 // character |
272 | 4876 && !(zero_padding_insertion_ind < str_arg_l |
4877 && tmp[zero_padding_insertion_ind] == '0')) | |
4878 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4879 // assure leading zero for alternate-form |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4880 // octal numbers |
272 | 4881 if (!precision_specified |
4882 || precision < num_of_digits + 1) | |
4883 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4884 // precision is increased to force the |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4885 // first character to be zero, except if a |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4886 // zero value is formatted with an |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4887 // explicit precision of zero |
272 | 4888 precision = num_of_digits + 1; |
4889 } | |
4890 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4891 // zero padding to specified precision? |
272 | 4892 if (num_of_digits < precision) |
4893 number_of_zeros_to_pad = precision - num_of_digits; | |
4894 } | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4895 // zero padding to specified minimal field width? |
272 | 4896 if (!justify_left && zero_padding) |
4897 { | |
835 | 4898 int n = (int)(min_field_width - (str_arg_l |
4899 + number_of_zeros_to_pad)); | |
272 | 4900 if (n > 0) |
4901 number_of_zeros_to_pad += n; | |
4902 } | |
4903 break; | |
4904 } | |
4905 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4906 # ifdef FEAT_FLOAT |
1619 | 4907 case 'f': |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4908 case 'F': |
1619 | 4909 case 'e': |
4910 case 'E': | |
4911 case 'g': | |
4912 case 'G': | |
4913 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4914 // Floating point. |
1619 | 4915 double f; |
4916 double abs_f; | |
4917 char format[40]; | |
4918 int l; | |
4919 int remove_trailing_zeroes = FALSE; | |
4920 | |
4921 f = | |
4922 # if defined(FEAT_EVAL) | |
4923 tvs != NULL ? tv_float(tvs, &arg_idx) : | |
4924 # endif | |
4925 va_arg(ap, double); | |
4926 abs_f = f < 0 ? -f : f; | |
4927 | |
4928 if (fmt_spec == 'g' || fmt_spec == 'G') | |
4929 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4930 // Would be nice to use %g directly, but it prints |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4931 // "1.0" as "1", we don't want that. |
1619 | 4932 if ((abs_f >= 0.001 && abs_f < 10000000.0) |
4933 || abs_f == 0.0) | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4934 fmt_spec = ASCII_ISUPPER(fmt_spec) ? 'F' : 'f'; |
1619 | 4935 else |
4936 fmt_spec = fmt_spec == 'g' ? 'e' : 'E'; | |
4937 remove_trailing_zeroes = TRUE; | |
4938 } | |
4939 | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4940 if ((fmt_spec == 'f' || fmt_spec == 'F') && |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4941 # ifdef VAX |
1783 | 4942 abs_f > 1.0e38 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4943 # else |
1783 | 4944 abs_f > 1.0e307 |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
4945 # endif |
1783 | 4946 ) |
1619 | 4947 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4948 // Avoid a buffer overflow |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4949 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4950 force_sign, space_for_positive)); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4951 str_arg_l = STRLEN(tmp); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4952 zero_padding = 0; |
1619 | 4953 } |
4954 else | |
4955 { | |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4956 if (isnan(f)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4957 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4958 // Not a number: nan or NAN |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4959 STRCPY(tmp, ASCII_ISUPPER(fmt_spec) ? "NAN" |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4960 : "nan"); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4961 str_arg_l = 3; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4962 zero_padding = 0; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4963 } |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4964 else if (isinf(f)) |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4965 { |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4966 STRCPY(tmp, infinity_str(f > 0.0, fmt_spec, |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4967 force_sign, space_for_positive)); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4968 str_arg_l = STRLEN(tmp); |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4969 zero_padding = 0; |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4970 } |
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4971 else |
13188
a49a5419a83f
patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
4972 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4973 // Regular float number |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4974 format[0] = '%'; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4975 l = 1; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4976 if (force_sign) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4977 format[l++] = space_for_positive ? ' ' : '+'; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4978 if (precision_specified) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4979 { |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4980 size_t max_prec = TMP_LEN - 10; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4981 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4982 // Make sure we don't get more digits than we |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
4983 // have room for. |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4984 if ((fmt_spec == 'f' || fmt_spec == 'F') |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4985 && abs_f > 1.0) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4986 max_prec -= (size_t)log10(abs_f); |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4987 if (precision > max_prec) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4988 precision = max_prec; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4989 l += sprintf(format + l, ".%d", (int)precision); |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4990 } |
10040
48f70e0c696a
commit https://github.com/vim/vim/commit/965ed14973fd3f1b2aace7bae4d4722b71ca04f9
Christian Brabandt <cb@256bit.org>
parents:
10038
diff
changeset
|
4991 format[l] = fmt_spec == 'F' ? 'f' : fmt_spec; |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4992 format[l + 1] = NUL; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
4993 |
10015
5ac2dd61ca8f
commit https://github.com/vim/vim/commit/e999782e369999539a1783a7ebe4eadcc6da28a8
Christian Brabandt <cb@256bit.org>
parents:
9988
diff
changeset
|
4994 str_arg_l = sprintf(tmp, format, f); |
13188
a49a5419a83f
patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents:
13150
diff
changeset
|
4995 } |
9986
9bef7b5d02cb
commit https://github.com/vim/vim/commit/9992237a3e791fbc0c1ebf743ece1b75e1488410
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
4996 |
1619 | 4997 if (remove_trailing_zeroes) |
4998 { | |
4999 int i; | |
1757 | 5000 char *tp; |
1619 | 5001 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5002 // Using %g or %G: remove superfluous zeroes. |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5003 if (fmt_spec == 'f' || fmt_spec == 'F') |
1757 | 5004 tp = tmp + str_arg_l - 1; |
1619 | 5005 else |
5006 { | |
1757 | 5007 tp = (char *)vim_strchr((char_u *)tmp, |
1619 | 5008 fmt_spec == 'e' ? 'e' : 'E'); |
1757 | 5009 if (tp != NULL) |
1619 | 5010 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5011 // Remove superfluous '+' and leading |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5012 // zeroes from the exponent. |
1757 | 5013 if (tp[1] == '+') |
1619 | 5014 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5015 // Change "1.0e+07" to "1.0e07" |
1757 | 5016 STRMOVE(tp + 1, tp + 2); |
1619 | 5017 --str_arg_l; |
5018 } | |
1757 | 5019 i = (tp[1] == '-') ? 2 : 1; |
5020 while (tp[i] == '0') | |
1619 | 5021 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5022 // Change "1.0e07" to "1.0e7" |
1757 | 5023 STRMOVE(tp + i, tp + i + 1); |
1619 | 5024 --str_arg_l; |
5025 } | |
1757 | 5026 --tp; |
1619 | 5027 } |
5028 } | |
5029 | |
1757 | 5030 if (tp != NULL && !precision_specified) |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5031 // Remove trailing zeroes, but keep the one |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5032 // just after a dot. |
1757 | 5033 while (tp > tmp + 2 && *tp == '0' |
5034 && tp[-1] != '.') | |
1619 | 5035 { |
1757 | 5036 STRMOVE(tp, tp + 1); |
5037 --tp; | |
1619 | 5038 --str_arg_l; |
5039 } | |
5040 } | |
5041 else | |
5042 { | |
1757 | 5043 char *tp; |
1619 | 5044 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5045 // Be consistent: some printf("%e") use 1.0e+12 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5046 // and some 1.0e+012. Remove one zero in the last |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5047 // case. |
1757 | 5048 tp = (char *)vim_strchr((char_u *)tmp, |
1619 | 5049 fmt_spec == 'e' ? 'e' : 'E'); |
1757 | 5050 if (tp != NULL && (tp[1] == '+' || tp[1] == '-') |
5051 && tp[2] == '0' | |
5052 && vim_isdigit(tp[3]) | |
5053 && vim_isdigit(tp[4])) | |
1619 | 5054 { |
1757 | 5055 STRMOVE(tp + 2, tp + 3); |
1619 | 5056 --str_arg_l; |
5057 } | |
5058 } | |
5059 } | |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5060 if (zero_padding && min_field_width > str_arg_l |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5061 && (tmp[0] == '-' || force_sign)) |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5062 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5063 // padding 0's should be inserted after the sign |
10038
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5064 number_of_zeros_to_pad = min_field_width - str_arg_l; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5065 zero_padding_insertion_ind = 1; |
7cf4e210cf3c
commit https://github.com/vim/vim/commit/04186095346daa60e82e981dad114de2b641d672
Christian Brabandt <cb@256bit.org>
parents:
10036
diff
changeset
|
5066 } |
1619 | 5067 str_arg = tmp; |
5068 break; | |
5069 } | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
5070 # endif |
1619 | 5071 |
272 | 5072 default: |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5073 // unrecognized conversion specifier, keep format string |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5074 // as-is |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5075 zero_padding = 0; // turn zero padding off for non-numeric |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5076 // conversion |
272 | 5077 justify_left = 1; |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5078 min_field_width = 0; // reset flags |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5079 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5080 // discard the unrecognized conversion, just keep * |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5081 // the unrecognized conversion character |
272 | 5082 str_arg = p; |
5083 str_arg_l = 0; | |
5084 if (*p != NUL) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5085 str_arg_l++; // include invalid conversion specifier |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5086 // unchanged if not at end-of-string |
272 | 5087 break; |
5088 } | |
5089 | |
5090 if (*p != NUL) | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5091 p++; // step over the just processed conversion specifier |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5092 |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5093 // insert padding to the left as requested by min_field_width; |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5094 // this does not include the zero padding in case of numerical |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5095 // conversions |
272 | 5096 if (!justify_left) |
5097 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5098 // left padding with blank or zero |
835 | 5099 int pn = (int)(min_field_width - (str_arg_l + number_of_zeros_to_pad)); |
275 | 5100 |
5101 if (pn > 0) | |
272 | 5102 { |
5103 if (str_l < str_m) | |
5104 { | |
5105 size_t avail = str_m - str_l; | |
5106 | |
5107 vim_memset(str + str_l, zero_padding ? '0' : ' ', | |
1883 | 5108 (size_t)pn > avail ? avail |
5109 : (size_t)pn); | |
272 | 5110 } |
275 | 5111 str_l += pn; |
272 | 5112 } |
5113 } | |
5114 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5115 // zero padding as requested by the precision or by the minimal |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5116 // field width for numeric conversions required? |
330 | 5117 if (number_of_zeros_to_pad == 0) |
272 | 5118 { |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5119 // will not copy first part of numeric right now, * |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5120 // force it to be copied later in its entirety |
272 | 5121 zero_padding_insertion_ind = 0; |
5122 } | |
5123 else | |
5124 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5125 // insert first part of numerics (sign or '0x') before zero |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5126 // padding |
835 | 5127 int zn = (int)zero_padding_insertion_ind; |
275 | 5128 |
5129 if (zn > 0) | |
272 | 5130 { |
5131 if (str_l < str_m) | |
5132 { | |
5133 size_t avail = str_m - str_l; | |
5134 | |
5135 mch_memmove(str + str_l, str_arg, | |
1883 | 5136 (size_t)zn > avail ? avail |
5137 : (size_t)zn); | |
272 | 5138 } |
275 | 5139 str_l += zn; |
272 | 5140 } |
5141 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5142 // insert zero padding as requested by the precision or min |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5143 // field width |
835 | 5144 zn = (int)number_of_zeros_to_pad; |
275 | 5145 if (zn > 0) |
272 | 5146 { |
5147 if (str_l < str_m) | |
5148 { | |
11937
c893d6c00497
patch 8.0.0848: using multiple ch_log functions is clumsy
Christian Brabandt <cb@256bit.org>
parents:
11653
diff
changeset
|
5149 size_t avail = str_m - str_l; |
272 | 5150 |
275 | 5151 vim_memset(str + str_l, '0', |
1883 | 5152 (size_t)zn > avail ? avail |
5153 : (size_t)zn); | |
272 | 5154 } |
275 | 5155 str_l += zn; |
272 | 5156 } |
5157 } | |
5158 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5159 // insert formatted string |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5160 // (or as-is conversion specifier for unknown conversions) |
272 | 5161 { |
835 | 5162 int sn = (int)(str_arg_l - zero_padding_insertion_ind); |
275 | 5163 |
5164 if (sn > 0) | |
272 | 5165 { |
5166 if (str_l < str_m) | |
5167 { | |
5168 size_t avail = str_m - str_l; | |
5169 | |
5170 mch_memmove(str + str_l, | |
5171 str_arg + zero_padding_insertion_ind, | |
1883 | 5172 (size_t)sn > avail ? avail : (size_t)sn); |
272 | 5173 } |
275 | 5174 str_l += sn; |
272 | 5175 } |
5176 } | |
5177 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5178 // insert right padding |
272 | 5179 if (justify_left) |
5180 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5181 // right blank padding to the field width |
1619 | 5182 int pn = (int)(min_field_width |
5183 - (str_arg_l + number_of_zeros_to_pad)); | |
275 | 5184 |
5185 if (pn > 0) | |
272 | 5186 { |
5187 if (str_l < str_m) | |
5188 { | |
5189 size_t avail = str_m - str_l; | |
5190 | |
275 | 5191 vim_memset(str + str_l, ' ', |
1883 | 5192 (size_t)pn > avail ? avail |
5193 : (size_t)pn); | |
272 | 5194 } |
275 | 5195 str_l += pn; |
272 | 5196 } |
5197 } | |
9892
41c5d59e7e10
commit https://github.com/vim/vim/commit/e5a8f35b4286135f3469f3b00a6c2220553d9658
Christian Brabandt <cb@256bit.org>
parents:
9698
diff
changeset
|
5198 vim_free(tofree); |
272 | 5199 } |
5200 } | |
5201 | |
5202 if (str_m > 0) | |
5203 { | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5204 // make sure the string is nul-terminated even at the expense of |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5205 // overwriting the last character (shouldn't happen, but just in case) |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5206 // |
272 | 5207 str[str_l <= str_m - 1 ? str_l : str_m - 1] = '\0'; |
5208 } | |
5209 | |
482 | 5210 if (tvs != NULL && tvs[arg_idx - 1].v_type != VAR_UNKNOWN) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15219
diff
changeset
|
5211 emsg(_("E767: Too many arguments to printf()")); |
449 | 5212 |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5213 // Return the number of characters formatted (excluding trailing nul |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5214 // character), that is, the number of characters that would have been |
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5215 // written to the buffer if it were large enough. |
272 | 5216 return (int)str_l; |
5217 } | |
5218 | |
18931
80b40bd5ec1a
patch 8.2.0026: still some /* */ comments
Bram Moolenaar <Bram@vim.org>
parents:
18866
diff
changeset
|
5219 #endif // PROTO |