Mercurial > vim
comparison src/window.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 | 29f3d59bb6f0 |
children | 98c35d312987 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
99 #ifdef FEAT_CMDWIN | 99 #ifdef FEAT_CMDWIN |
100 # define CHECK_CMDWIN \ | 100 # define CHECK_CMDWIN \ |
101 do { \ | 101 do { \ |
102 if (cmdwin_type != 0) \ | 102 if (cmdwin_type != 0) \ |
103 { \ | 103 { \ |
104 EMSG(_(e_cmdwin)); \ | 104 emsg(_(e_cmdwin)); \ |
105 return; \ | 105 return; \ |
106 } \ | 106 } \ |
107 } while (0) | 107 } while (0) |
108 #else | 108 #else |
109 # define CHECK_CMDWIN do { /**/ } while (0) | 109 # define CHECK_CMDWIN do { /**/ } while (0) |
154 | 154 |
155 if (buflist_findnr(Prenum == 0 | 155 if (buflist_findnr(Prenum == 0 |
156 ? curwin->w_alt_fnum : Prenum) == NULL) | 156 ? curwin->w_alt_fnum : Prenum) == NULL) |
157 { | 157 { |
158 if (Prenum == 0) | 158 if (Prenum == 0) |
159 EMSG(_(e_noalt)); | 159 emsg(_(e_noalt)); |
160 else | 160 else |
161 EMSGN(_("E92: Buffer %ld not found"), Prenum); | 161 semsg(_("E92: Buffer %ld not found"), Prenum); |
162 break; | 162 break; |
163 } | 163 } |
164 | 164 |
165 if (!curbuf_locked() && win_split(0, 0) == OK) | 165 if (!curbuf_locked() && win_split(0, 0) == OK) |
166 (void)buflist_getfile( | 166 (void)buflist_getfile( |
218 case 'P': | 218 case 'P': |
219 FOR_ALL_WINDOWS(wp) | 219 FOR_ALL_WINDOWS(wp) |
220 if (wp->w_p_pvw) | 220 if (wp->w_p_pvw) |
221 break; | 221 break; |
222 if (wp == NULL) | 222 if (wp == NULL) |
223 EMSG(_("E441: There is no preview window")); | 223 emsg(_("E441: There is no preview window")); |
224 else | 224 else |
225 win_goto(wp); | 225 win_goto(wp); |
226 break; | 226 break; |
227 #endif | 227 #endif |
228 | 228 |
737 | 737 |
738 /* Add flags from ":vertical", ":topleft" and ":botright". */ | 738 /* Add flags from ":vertical", ":topleft" and ":botright". */ |
739 flags |= cmdmod.split; | 739 flags |= cmdmod.split; |
740 if ((flags & WSP_TOP) && (flags & WSP_BOT)) | 740 if ((flags & WSP_TOP) && (flags & WSP_BOT)) |
741 { | 741 { |
742 EMSG(_("E442: Can't split topleft and botright at the same time")); | 742 emsg(_("E442: Can't split topleft and botright at the same time")); |
743 return FAIL; | 743 return FAIL; |
744 } | 744 } |
745 | 745 |
746 /* When creating the help window make a snapshot of the window layout. | 746 /* When creating the help window make a snapshot of the window layout. |
747 * Otherwise clear the snapshot, it's now invalid. */ | 747 * Otherwise clear the snapshot, it's now invalid. */ |
792 /* add a status line when p_ls == 1 and splitting the first window */ | 792 /* add a status line when p_ls == 1 and splitting the first window */ |
793 if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0) | 793 if (ONE_WINDOW && p_ls == 1 && oldwin->w_status_height == 0) |
794 { | 794 { |
795 if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL) | 795 if (VISIBLE_HEIGHT(oldwin) <= p_wmh && new_wp == NULL) |
796 { | 796 { |
797 EMSG(_(e_noroom)); | 797 emsg(_(e_noroom)); |
798 return FAIL; | 798 return FAIL; |
799 } | 799 } |
800 need_status = STATUS_HEIGHT; | 800 need_status = STATUS_HEIGHT; |
801 } | 801 } |
802 | 802 |
850 available = oldwin->w_frame->fr_width; | 850 available = oldwin->w_frame->fr_width; |
851 needed += minwidth; | 851 needed += minwidth; |
852 } | 852 } |
853 if (available < needed && new_wp == NULL) | 853 if (available < needed && new_wp == NULL) |
854 { | 854 { |
855 EMSG(_(e_noroom)); | 855 emsg(_(e_noroom)); |
856 return FAIL; | 856 return FAIL; |
857 } | 857 } |
858 if (new_size == 0) | 858 if (new_size == 0) |
859 new_size = oldwin->w_width / 2; | 859 new_size = oldwin->w_width / 2; |
860 if (new_size > available - minwidth - 1) | 860 if (new_size > available - minwidth - 1) |
933 available = oldwin->w_frame->fr_height; | 933 available = oldwin->w_frame->fr_height; |
934 needed += minheight; | 934 needed += minheight; |
935 } | 935 } |
936 if (available < needed && new_wp == NULL) | 936 if (available < needed && new_wp == NULL) |
937 { | 937 { |
938 EMSG(_(e_noroom)); | 938 emsg(_(e_noroom)); |
939 return FAIL; | 939 return FAIL; |
940 } | 940 } |
941 oldwin_height = oldwin->w_height; | 941 oldwin_height = oldwin->w_height; |
942 if (need_status) | 942 if (need_status) |
943 { | 943 { |
1604 | 1604 |
1605 /* Check if all frames in this row/col have one window. */ | 1605 /* Check if all frames in this row/col have one window. */ |
1606 FOR_ALL_FRAMES(frp, curwin->w_frame->fr_parent->fr_child) | 1606 FOR_ALL_FRAMES(frp, curwin->w_frame->fr_parent->fr_child) |
1607 if (frp->fr_win == NULL) | 1607 if (frp->fr_win == NULL) |
1608 { | 1608 { |
1609 EMSG(_("E443: Cannot rotate when another window is split")); | 1609 emsg(_("E443: Cannot rotate when another window is split")); |
1610 return; | 1610 return; |
1611 } | 1611 } |
1612 | 1612 |
1613 while (count--) | 1613 while (count--) |
1614 { | 1614 { |
2307 tabpage_T *prev_curtab = curtab; | 2307 tabpage_T *prev_curtab = curtab; |
2308 frame_T *win_frame = win->w_frame->fr_parent; | 2308 frame_T *win_frame = win->w_frame->fr_parent; |
2309 | 2309 |
2310 if (last_window()) | 2310 if (last_window()) |
2311 { | 2311 { |
2312 EMSG(_("E444: Cannot close last window")); | 2312 emsg(_("E444: Cannot close last window")); |
2313 return FAIL; | 2313 return FAIL; |
2314 } | 2314 } |
2315 | 2315 |
2316 if (win->w_closing || (win->w_buffer != NULL | 2316 if (win->w_closing || (win->w_buffer != NULL |
2317 && win->w_buffer->b_locked > 0)) | 2317 && win->w_buffer->b_locked > 0)) |
2318 return FAIL; /* window is already being closed */ | 2318 return FAIL; /* window is already being closed */ |
2319 if (win == aucmd_win) | 2319 if (win == aucmd_win) |
2320 { | 2320 { |
2321 EMSG(_("E813: Cannot close autocmd window")); | 2321 emsg(_("E813: Cannot close autocmd window")); |
2322 return FAIL; | 2322 return FAIL; |
2323 } | 2323 } |
2324 if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) | 2324 if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) |
2325 { | 2325 { |
2326 EMSG(_("E814: Cannot close window, only autocmd window would remain")); | 2326 emsg(_("E814: Cannot close window, only autocmd window would remain")); |
2327 return FAIL; | 2327 return FAIL; |
2328 } | 2328 } |
2329 | 2329 |
2330 /* When closing the last window in a tab page first go to another tab page | 2330 /* When closing the last window in a tab page first go to another tab page |
2331 * and then close the window and the tab page to avoid that curwin and | 2331 * and then close the window and the tab page to avoid that curwin and |
3417 && !bufIsChanged(wp->w_buffer)); | 3417 && !bufIsChanged(wp->w_buffer)); |
3418 } | 3418 } |
3419 } | 3419 } |
3420 | 3420 |
3421 if (message && !ONE_WINDOW) | 3421 if (message && !ONE_WINDOW) |
3422 EMSG(_("E445: Other window contains changes")); | 3422 emsg(_("E445: Other window contains changes")); |
3423 } | 3423 } |
3424 | 3424 |
3425 /* | 3425 /* |
3426 * Init the current window "curwin". | 3426 * Init the current window "curwin". |
3427 * Called when a new file is being edited. | 3427 * Called when a new file is being edited. |
5445 if (room >= needed) | 5445 if (room >= needed) |
5446 break; | 5446 break; |
5447 --p_wmh; | 5447 --p_wmh; |
5448 if (first) | 5448 if (first) |
5449 { | 5449 { |
5450 EMSG(_(e_noroom)); | 5450 emsg(_(e_noroom)); |
5451 first = FALSE; | 5451 first = FALSE; |
5452 } | 5452 } |
5453 } | 5453 } |
5454 } | 5454 } |
5455 | 5455 |
5471 if (room >= needed) | 5471 if (room >= needed) |
5472 break; | 5472 break; |
5473 --p_wmw; | 5473 --p_wmw; |
5474 if (first) | 5474 if (first) |
5475 { | 5475 { |
5476 EMSG(_(e_noroom)); | 5476 emsg(_(e_noroom)); |
5477 first = FALSE; | 5477 first = FALSE; |
5478 } | 5478 } |
5479 } | 5479 } |
5480 } | 5480 } |
5481 | 5481 |
5948 { | 5948 { |
5949 while (p_ch > old_p_ch) | 5949 while (p_ch > old_p_ch) |
5950 { | 5950 { |
5951 if (frp == NULL) | 5951 if (frp == NULL) |
5952 { | 5952 { |
5953 EMSG(_(e_noroom)); | 5953 emsg(_(e_noroom)); |
5954 p_ch = old_p_ch; | 5954 p_ch = old_p_ch; |
5955 curtab->tp_ch_used = p_ch; | 5955 curtab->tp_ch_used = p_ch; |
5956 cmdline_row = Rows - p_ch; | 5956 cmdline_row = Rows - p_ch; |
5957 break; | 5957 break; |
5958 } | 5958 } |
6039 fp = fr; | 6039 fp = fr; |
6040 while (fp->fr_height <= frame_minheight(fp, NULL)) | 6040 while (fp->fr_height <= frame_minheight(fp, NULL)) |
6041 { | 6041 { |
6042 if (fp == topframe) | 6042 if (fp == topframe) |
6043 { | 6043 { |
6044 EMSG(_(e_noroom)); | 6044 emsg(_(e_noroom)); |
6045 return; | 6045 return; |
6046 } | 6046 } |
6047 /* In a column of frames: go to frame above. If already at | 6047 /* In a column of frames: go to frame above. If already at |
6048 * the top or in a row of frames: go to parent. */ | 6048 * the top or in a row of frames: go to parent. */ |
6049 if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) | 6049 if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) |
6168 while (*ptr != NUL && !vim_isfilec(*ptr)) | 6168 while (*ptr != NUL && !vim_isfilec(*ptr)) |
6169 MB_PTR_ADV(ptr); | 6169 MB_PTR_ADV(ptr); |
6170 if (*ptr == NUL) /* nothing found */ | 6170 if (*ptr == NUL) /* nothing found */ |
6171 { | 6171 { |
6172 if (options & FNAME_MESS) | 6172 if (options & FNAME_MESS) |
6173 EMSG(_("E446: No file name under cursor")); | 6173 emsg(_("E446: No file name under cursor")); |
6174 return NULL; | 6174 return NULL; |
6175 } | 6175 } |
6176 | 6176 |
6177 /* | 6177 /* |
6178 * Search backward for first char of the file name. | 6178 * Search backward for first char of the file name. |
6317 # endif | 6317 # endif |
6318 if (file_name == NULL && (options & FNAME_MESS)) | 6318 if (file_name == NULL && (options & FNAME_MESS)) |
6319 { | 6319 { |
6320 c = ptr[len]; | 6320 c = ptr[len]; |
6321 ptr[len] = NUL; | 6321 ptr[len] = NUL; |
6322 EMSG2(_("E447: Can't find file \"%s\" in path"), ptr); | 6322 semsg(_("E447: Can't find file \"%s\" in path"), ptr); |
6323 ptr[len] = c; | 6323 ptr[len] = c; |
6324 } | 6324 } |
6325 | 6325 |
6326 /* Repeat finding the file "count" times. This matters when it | 6326 /* Repeat finding the file "count" times. This matters when it |
6327 * appears several times in the path. */ | 6327 * appears several times in the path. */ |
6780 | 6780 |
6781 if (*grp == NUL || (pat != NULL && *pat == NUL)) | 6781 if (*grp == NUL || (pat != NULL && *pat == NUL)) |
6782 return -1; | 6782 return -1; |
6783 if (id < -1 || id == 0) | 6783 if (id < -1 || id == 0) |
6784 { | 6784 { |
6785 EMSGN(_("E799: Invalid ID: %ld (must be greater than or equal to 1)"), id); | 6785 semsg(_("E799: Invalid ID: %ld (must be greater than or equal to 1)"), id); |
6786 return -1; | 6786 return -1; |
6787 } | 6787 } |
6788 if (id != -1) | 6788 if (id != -1) |
6789 { | 6789 { |
6790 cur = wp->w_match_head; | 6790 cur = wp->w_match_head; |
6791 while (cur != NULL) | 6791 while (cur != NULL) |
6792 { | 6792 { |
6793 if (cur->id == id) | 6793 if (cur->id == id) |
6794 { | 6794 { |
6795 EMSGN(_("E801: ID already taken: %ld"), id); | 6795 semsg(_("E801: ID already taken: %ld"), id); |
6796 return -1; | 6796 return -1; |
6797 } | 6797 } |
6798 cur = cur->next; | 6798 cur = cur->next; |
6799 } | 6799 } |
6800 } | 6800 } |
6801 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0) | 6801 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0) |
6802 { | 6802 { |
6803 EMSG2(_(e_nogroup), grp); | 6803 semsg(_(e_nogroup), grp); |
6804 return -1; | 6804 return -1; |
6805 } | 6805 } |
6806 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) | 6806 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) |
6807 { | 6807 { |
6808 EMSG2(_(e_invarg2), pat); | 6808 semsg(_(e_invarg2), pat); |
6809 return -1; | 6809 return -1; |
6810 } | 6810 } |
6811 | 6811 |
6812 /* Find available match ID. */ | 6812 /* Find available match ID. */ |
6813 while (id == -1) | 6813 while (id == -1) |
6898 m->pos.pos[i].col = 0; | 6898 m->pos.pos[i].col = 0; |
6899 m->pos.pos[i].len = 0; | 6899 m->pos.pos[i].len = 0; |
6900 } | 6900 } |
6901 else | 6901 else |
6902 { | 6902 { |
6903 EMSG(_("List or number required")); | 6903 emsg(_("List or number required")); |
6904 goto fail; | 6904 goto fail; |
6905 } | 6905 } |
6906 if (toplnum == 0 || lnum < toplnum) | 6906 if (toplnum == 0 || lnum < toplnum) |
6907 toplnum = lnum; | 6907 toplnum = lnum; |
6908 if (botlnum == 0 || lnum >= botlnum) | 6908 if (botlnum == 0 || lnum >= botlnum) |
6967 int rtype = SOME_VALID; | 6967 int rtype = SOME_VALID; |
6968 | 6968 |
6969 if (id < 1) | 6969 if (id < 1) |
6970 { | 6970 { |
6971 if (perr == TRUE) | 6971 if (perr == TRUE) |
6972 EMSGN(_("E802: Invalid ID: %ld (must be greater than or equal to 1)"), | 6972 semsg(_("E802: Invalid ID: %ld (must be greater than or equal to 1)"), |
6973 id); | 6973 id); |
6974 return -1; | 6974 return -1; |
6975 } | 6975 } |
6976 while (cur != NULL && cur->id != id) | 6976 while (cur != NULL && cur->id != id) |
6977 { | 6977 { |
6979 cur = cur->next; | 6979 cur = cur->next; |
6980 } | 6980 } |
6981 if (cur == NULL) | 6981 if (cur == NULL) |
6982 { | 6982 { |
6983 if (perr == TRUE) | 6983 if (perr == TRUE) |
6984 EMSGN(_("E803: ID not found: %ld"), id); | 6984 semsg(_("E803: ID not found: %ld"), id); |
6985 return -1; | 6985 return -1; |
6986 } | 6986 } |
6987 if (cur == prev) | 6987 if (cur == prev) |
6988 wp->w_match_head = cur->next; | 6988 wp->w_match_head = cur->next; |
6989 else | 6989 else |