comparison src/buffer.c @ 15470:55ccc2d353bd v8.1.0743

patch 8.1.0743: giving error messages is not flexible commit https://github.com/vim/vim/commit/f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 13 23:38:42 2019 +0100 patch 8.1.0743: giving error messages is not flexible Problem: Giving error messages is not flexible. Solution: Add semsg(). Change argument from "char_u *" to "char *", also for msg() and get rid of most MSG macros. (Ozaki Kiichi, closes #3302) Also make emsg() accept a "char *" argument. Get rid of an enormous number of type casts.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Jan 2019 23:45:08 +0100
parents a6330a49e036
children 98c35d312987
comparison
equal deleted inserted replaced
15469:bc9b5261ed01 15470:55ccc2d353bd
160 * if there is no memfile at all, exit 160 * if there is no memfile at all, exit
161 * This is OK, since there are no changes to lose. 161 * This is OK, since there are no changes to lose.
162 */ 162 */
163 if (curbuf == NULL) 163 if (curbuf == NULL)
164 { 164 {
165 EMSG(_("E82: Cannot allocate any buffer, exiting...")); 165 emsg(_("E82: Cannot allocate any buffer, exiting..."));
166 getout(2); 166 getout(2);
167 } 167 }
168 EMSG(_("E83: Cannot allocate buffer, using other one...")); 168 emsg(_("E83: Cannot allocate buffer, using other one..."));
169 enter_buffer(curbuf); 169 enter_buffer(curbuf);
170 #ifdef FEAT_SYN_HL 170 #ifdef FEAT_SYN_HL
171 if (old_tw != curbuf->b_p_tw) 171 if (old_tw != curbuf->b_p_tw)
172 check_colorcolumn(curwin); 172 check_colorcolumn(curwin);
173 #endif 173 #endif
394 static void 394 static void
395 buf_hashtab_add(buf_T *buf) 395 buf_hashtab_add(buf_T *buf)
396 { 396 {
397 sprintf((char *)buf->b_key, "%x", buf->b_fnum); 397 sprintf((char *)buf->b_key, "%x", buf->b_fnum);
398 if (hash_add(&buf_hashtab, buf->b_key) == FAIL) 398 if (hash_add(&buf_hashtab, buf->b_key) == FAIL)
399 EMSG(_("E931: Buffer cannot be registered")); 399 emsg(_("E931: Buffer cannot be registered"));
400 } 400 }
401 401
402 static void 402 static void
403 buf_hashtab_remove(buf_T *buf) 403 buf_hashtab_remove(buf_T *buf)
404 { 404 {
428 can_unload = FALSE; 428 can_unload = FALSE;
429 break; 429 break;
430 } 430 }
431 } 431 }
432 if (!can_unload) 432 if (!can_unload)
433 EMSG(_("E937: Attempt to delete a buffer that is in use")); 433 emsg(_("E937: Attempt to delete a buffer that is in use"));
434 return can_unload; 434 return can_unload;
435 } 435 }
436 436
437 /* 437 /*
438 * Close the link to a buffer. 438 * Close the link to a buffer.
546 FALSE, buf) 546 FALSE, buf)
547 && !bufref_valid(&bufref)) 547 && !bufref_valid(&bufref))
548 { 548 {
549 /* Autocommands deleted the buffer. */ 549 /* Autocommands deleted the buffer. */
550 aucmd_abort: 550 aucmd_abort:
551 EMSG(_(e_auabort)); 551 emsg(_(e_auabort));
552 return; 552 return;
553 } 553 }
554 --buf->b_locked; 554 --buf->b_locked;
555 if (abort_if_last && one_window()) 555 if (abort_if_last && one_window())
556 /* Autocommands made this the only window. */ 556 /* Autocommands made this the only window. */
1113 * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or 1113 * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or
1114 * DOBUF_DEL (":bdel") 1114 * DOBUF_DEL (":bdel")
1115 * 1115 *
1116 * Returns error message or NULL 1116 * Returns error message or NULL
1117 */ 1117 */
1118 char_u * 1118 char *
1119 do_bufdel( 1119 do_bufdel(
1120 int command, 1120 int command,
1121 char_u *arg, /* pointer to extra arguments */ 1121 char_u *arg, /* pointer to extra arguments */
1122 int addr_count, 1122 int addr_count,
1123 int start_bnr, /* first buffer number in a range */ 1123 int start_bnr, /* first buffer number in a range */
1124 int end_bnr, /* buffer nr or last buffer nr in a range */ 1124 int end_bnr, /* buffer nr or last buffer nr in a range */
1125 int forceit) 1125 int forceit)
1126 { 1126 {
1127 int do_current = 0; /* delete current buffer? */ 1127 int do_current = 0; /* delete current buffer? */
1128 int deleted = 0; /* number of buffers deleted */ 1128 int deleted = 0; /* number of buffers deleted */
1129 char_u *errormsg = NULL; /* return value */ 1129 char *errormsg = NULL; /* return value */
1130 int bnr; /* buffer number */ 1130 int bnr; /* buffer number */
1131 char_u *p; 1131 char_u *p;
1132 1132
1133 if (addr_count == 0) 1133 if (addr_count == 0)
1134 { 1134 {
1137 else 1137 else
1138 { 1138 {
1139 if (addr_count == 2) 1139 if (addr_count == 2)
1140 { 1140 {
1141 if (*arg) /* both range and argument is not allowed */ 1141 if (*arg) /* both range and argument is not allowed */
1142 return (char_u *)_(e_trailing); 1142 return _(e_trailing);
1143 bnr = start_bnr; 1143 bnr = start_bnr;
1144 } 1144 }
1145 else /* addr_count == 1 */ 1145 else /* addr_count == 1 */
1146 bnr = end_bnr; 1146 bnr = end_bnr;
1147 1147
1195 STRCPY(IObuff, _("E515: No buffers were unloaded")); 1195 STRCPY(IObuff, _("E515: No buffers were unloaded"));
1196 else if (command == DOBUF_DEL) 1196 else if (command == DOBUF_DEL)
1197 STRCPY(IObuff, _("E516: No buffers were deleted")); 1197 STRCPY(IObuff, _("E516: No buffers were deleted"));
1198 else 1198 else
1199 STRCPY(IObuff, _("E517: No buffers were wiped out")); 1199 STRCPY(IObuff, _("E517: No buffers were wiped out"));
1200 errormsg = IObuff; 1200 errormsg = (char *)IObuff;
1201 } 1201 }
1202 else if (deleted >= p_report) 1202 else if (deleted >= p_report)
1203 { 1203 {
1204 if (command == DOBUF_UNLOAD) 1204 if (command == DOBUF_UNLOAD)
1205 smsg((char_u *)NGETTEXT("%d buffer unloaded", 1205 smsg(NGETTEXT("%d buffer unloaded",
1206 "%d buffers unloaded", deleted), deleted); 1206 "%d buffers unloaded", deleted), deleted);
1207 else if (command == DOBUF_DEL) 1207 else if (command == DOBUF_DEL)
1208 smsg((char_u *)NGETTEXT("%d buffer deleted", 1208 smsg(NGETTEXT("%d buffer deleted",
1209 "%d buffers deleted", deleted), deleted); 1209 "%d buffers deleted", deleted), deleted);
1210 else 1210 else
1211 smsg((char_u *)NGETTEXT("%d buffer wiped out", 1211 smsg(NGETTEXT("%d buffer wiped out",
1212 "%d buffers wiped out", deleted), deleted); 1212 "%d buffers wiped out", deleted), deleted);
1213 } 1213 }
1214 } 1214 }
1215 1215
1216 1216
1231 buf_T *buf = curbuf; 1231 buf_T *buf = curbuf;
1232 bufref_T bufref; 1232 bufref_T bufref;
1233 1233
1234 if (action == DOBUF_UNLOAD) 1234 if (action == DOBUF_UNLOAD)
1235 { 1235 {
1236 EMSG(_("E90: Cannot unload last buffer")); 1236 emsg(_("E90: Cannot unload last buffer"));
1237 return FAIL; 1237 return FAIL;
1238 } 1238 }
1239 1239
1240 set_bufref(&bufref, buf); 1240 set_bufref(&bufref, buf);
1241 if (close_others) 1241 if (close_others)
1305 } 1305 }
1306 while (buf != curbuf && !bufIsChanged(buf)); 1306 while (buf != curbuf && !bufIsChanged(buf));
1307 } 1307 }
1308 if (!bufIsChanged(buf)) 1308 if (!bufIsChanged(buf))
1309 { 1309 {
1310 EMSG(_("E84: No modified buffer found")); 1310 emsg(_("E84: No modified buffer found"));
1311 return FAIL; 1311 return FAIL;
1312 } 1312 }
1313 } 1313 }
1314 else if (start == DOBUF_FIRST && count) /* find specified buffer number */ 1314 else if (start == DOBUF_FIRST && count) /* find specified buffer number */
1315 { 1315 {
1344 bp = NULL; /* use this buffer as new starting point */ 1344 bp = NULL; /* use this buffer as new starting point */
1345 } 1345 }
1346 if (bp == buf) 1346 if (bp == buf)
1347 { 1347 {
1348 /* back where we started, didn't find anything. */ 1348 /* back where we started, didn't find anything. */
1349 EMSG(_("E85: There is no listed buffer")); 1349 emsg(_("E85: There is no listed buffer"));
1350 return FAIL; 1350 return FAIL;
1351 } 1351 }
1352 } 1352 }
1353 } 1353 }
1354 1354
1356 { 1356 {
1357 if (start == DOBUF_FIRST) 1357 if (start == DOBUF_FIRST)
1358 { 1358 {
1359 /* don't warn when deleting */ 1359 /* don't warn when deleting */
1360 if (!unload) 1360 if (!unload)
1361 EMSGN(_(e_nobufnr), count); 1361 semsg(_(e_nobufnr), count);
1362 } 1362 }
1363 else if (dir == FORWARD) 1363 else if (dir == FORWARD)
1364 EMSG(_("E87: Cannot go beyond last buffer")); 1364 emsg(_("E87: Cannot go beyond last buffer"));
1365 else 1365 else
1366 EMSG(_("E88: Cannot go before first buffer")); 1366 emsg(_("E88: Cannot go before first buffer"));
1367 return FAIL; 1367 return FAIL;
1368 } 1368 }
1369 1369
1370 #ifdef FEAT_GUI 1370 #ifdef FEAT_GUI
1371 need_mouse_correct = TRUE; 1371 need_mouse_correct = TRUE;
1405 return FAIL; 1405 return FAIL;
1406 } 1406 }
1407 else 1407 else
1408 #endif 1408 #endif
1409 { 1409 {
1410 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), 1410 semsg(_("E89: No write since last change for buffer %ld (add ! to override)"),
1411 buf->b_fnum); 1411 buf->b_fnum);
1412 return FAIL; 1412 return FAIL;
1413 } 1413 }
1414 } 1414 }
1415 1415
1830 void 1830 void
1831 no_write_message(void) 1831 no_write_message(void)
1832 { 1832 {
1833 #ifdef FEAT_TERMINAL 1833 #ifdef FEAT_TERMINAL
1834 if (term_job_running(curbuf->b_term)) 1834 if (term_job_running(curbuf->b_term))
1835 EMSG(_("E948: Job still running (add ! to end the job)")); 1835 emsg(_("E948: Job still running (add ! to end the job)"));
1836 else 1836 else
1837 #endif 1837 #endif
1838 EMSG(_("E37: No write since last change (add ! to override)")); 1838 emsg(_("E37: No write since last change (add ! to override)"));
1839 } 1839 }
1840 1840
1841 void 1841 void
1842 no_write_message_nobang(buf_T *buf UNUSED) 1842 no_write_message_nobang(buf_T *buf UNUSED)
1843 { 1843 {
1844 #ifdef FEAT_TERMINAL 1844 #ifdef FEAT_TERMINAL
1845 if (term_job_running(buf->b_term)) 1845 if (term_job_running(buf->b_term))
1846 EMSG(_("E948: Job still running")); 1846 emsg(_("E948: Job still running"));
1847 else 1847 else
1848 #endif 1848 #endif
1849 EMSG(_("E37: No write since last change")); 1849 emsg(_("E37: No write since last change"));
1850 } 1850 }
1851 1851
1852 /* 1852 /*
1853 * functions for dealing with the buffer list 1853 * functions for dealing with the buffer list
1854 */ 1854 */
2055 lastbuf = buf; 2055 lastbuf = buf;
2056 2056
2057 buf->b_fnum = top_file_num++; 2057 buf->b_fnum = top_file_num++;
2058 if (top_file_num < 0) /* wrap around (may cause duplicates) */ 2058 if (top_file_num < 0) /* wrap around (may cause duplicates) */
2059 { 2059 {
2060 EMSG(_("W14: Warning: List of file names overflow")); 2060 emsg(_("W14: Warning: List of file names overflow"));
2061 if (emsg_silent == 0) 2061 if (emsg_silent == 0)
2062 { 2062 {
2063 out_flush(); 2063 out_flush();
2064 ui_delay(3000L, TRUE); /* make sure it is noticed */ 2064 ui_delay(3000L, TRUE); /* make sure it is noticed */
2065 } 2065 }
2279 2279
2280 buf = buflist_findnr(n); 2280 buf = buflist_findnr(n);
2281 if (buf == NULL) 2281 if (buf == NULL)
2282 { 2282 {
2283 if ((options & GETF_ALT) && n == 0) 2283 if ((options & GETF_ALT) && n == 0)
2284 EMSG(_(e_noalt)); 2284 emsg(_(e_noalt));
2285 else 2285 else
2286 EMSGN(_("E92: Buffer %ld not found"), n); 2286 semsg(_("E92: Buffer %ld not found"), n);
2287 return FAIL; 2287 return FAIL;
2288 } 2288 }
2289 2289
2290 /* if alternate file is the current buffer, nothing to do */ 2290 /* if alternate file is the current buffer, nothing to do */
2291 if (buf == curbuf) 2291 if (buf == curbuf)
2566 2566
2567 vim_free(pat); 2567 vim_free(pat);
2568 } 2568 }
2569 2569
2570 if (match == -2) 2570 if (match == -2)
2571 EMSG2(_("E93: More than one match for %s"), pattern); 2571 semsg(_("E93: More than one match for %s"), pattern);
2572 else if (match < 0) 2572 else if (match < 0)
2573 EMSG2(_("E94: No matching buffer for %s"), pattern); 2573 semsg(_("E94: No matching buffer for %s"), pattern);
2574 return match; 2574 return match;
2575 } 2575 }
2576 2576
2577 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 2577 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
2578 2578
3170 if (obuf != NULL && obuf != buf) 3170 if (obuf != NULL && obuf != buf)
3171 { 3171 {
3172 if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ 3172 if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */
3173 { 3173 {
3174 if (message) 3174 if (message)
3175 EMSG(_("E95: Buffer with this name already exists")); 3175 emsg(_("E95: Buffer with this name already exists"));
3176 vim_free(ffname); 3176 vim_free(ffname);
3177 return FAIL; 3177 return FAIL;
3178 } 3178 }
3179 /* delete from the list */ 3179 /* delete from the list */
3180 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); 3180 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE);
3296 linenr_T dummy; 3296 linenr_T dummy;
3297 3297
3298 if (buflist_name_nr(0, &fname, &dummy) == FAIL) 3298 if (buflist_name_nr(0, &fname, &dummy) == FAIL)
3299 { 3299 {
3300 if (errmsg) 3300 if (errmsg)
3301 EMSG(_(e_noalt)); 3301 emsg(_(e_noalt));
3302 return NULL; 3302 return NULL;
3303 } 3303 }
3304 return fname; 3304 return fname;
3305 } 3305 }
3306 3306
5728 int 5728 int
5729 bt_dontwrite_msg(buf_T *buf) 5729 bt_dontwrite_msg(buf_T *buf)
5730 { 5730 {
5731 if (bt_dontwrite(buf)) 5731 if (bt_dontwrite(buf))
5732 { 5732 {
5733 EMSG(_("E382: Cannot write, 'buftype' option is set")); 5733 emsg(_("E382: Cannot write, 'buftype' option is set"));
5734 return TRUE; 5734 return TRUE;
5735 } 5735 }
5736 return FALSE; 5736 return FALSE;
5737 } 5737 }
5738 5738