Mercurial > vim
comparison src/textprop.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 | 00aa76a735e7 |
children | 8013b532a1f7 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
17 * Text properties have a type, which can be used to specify highlighting. | 17 * Text properties have a type, which can be used to specify highlighting. |
18 * | 18 * |
19 * TODO: | 19 * TODO: |
20 * - Adjust text property column and length when text is inserted/deleted. | 20 * - Adjust text property column and length when text is inserted/deleted. |
21 * -> a :substitute with a multi-line match | 21 * -> a :substitute with a multi-line match |
22 * -> search for changed_bytes() from ex_cmds.c | 22 * -> search for changed_bytes() from misc1.c |
23 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV? | 23 * - Perhaps we only need TP_FLAG_CONT_NEXT and can drop TP_FLAG_CONT_PREV? |
24 * - Add an arrray for global_proptypes, to quickly lookup a prop type by ID | 24 * - Add an arrray for global_proptypes, to quickly lookup a prop type by ID |
25 * - Add an arrray for b_proptypes, to quickly lookup a prop type by ID | 25 * - Add an arrray for b_proptypes, to quickly lookup a prop type by ID |
26 * - Checking the text length to detect text properties is slow. Use a flag in | 26 * - Checking the text length to detect text properties is slow. Use a flag in |
27 * the index, like DB_MARKED? | 27 * the index, like DB_MARKED? |
104 proptype_T *type = find_prop(name, buf); | 104 proptype_T *type = find_prop(name, buf); |
105 | 105 |
106 if (type == NULL) | 106 if (type == NULL) |
107 type = find_prop(name, NULL); | 107 type = find_prop(name, NULL); |
108 if (type == NULL) | 108 if (type == NULL) |
109 EMSG2(_(e_type_not_exist), name); | 109 semsg(_(e_type_not_exist), name); |
110 return type; | 110 return type; |
111 } | 111 } |
112 | 112 |
113 /* | 113 /* |
114 * Get an optional "bufnr" item from the dict in "arg". | 114 * Get an optional "bufnr" item from the dict in "arg". |
122 { | 122 { |
123 dictitem_T *di; | 123 dictitem_T *di; |
124 | 124 |
125 if (arg->v_type != VAR_DICT) | 125 if (arg->v_type != VAR_DICT) |
126 { | 126 { |
127 EMSG(_(e_dictreq)); | 127 emsg(_(e_dictreq)); |
128 return FAIL; | 128 return FAIL; |
129 } | 129 } |
130 if (arg->vval.v_dict == NULL) | 130 if (arg->vval.v_dict == NULL) |
131 return OK; // NULL dict is like an empty dict | 131 return OK; // NULL dict is like an empty dict |
132 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); | 132 di = dict_find(arg->vval.v_dict, (char_u *)"bufnr", -1); |
165 | 165 |
166 start_lnum = tv_get_number(&argvars[0]); | 166 start_lnum = tv_get_number(&argvars[0]); |
167 start_col = tv_get_number(&argvars[1]); | 167 start_col = tv_get_number(&argvars[1]); |
168 if (start_col < 1) | 168 if (start_col < 1) |
169 { | 169 { |
170 EMSGN(_(e_invalid_col), (long)start_col); | 170 semsg(_(e_invalid_col), (long)start_col); |
171 return; | 171 return; |
172 } | 172 } |
173 if (argvars[2].v_type != VAR_DICT) | 173 if (argvars[2].v_type != VAR_DICT) |
174 { | 174 { |
175 EMSG(_(e_dictreq)); | 175 emsg(_(e_dictreq)); |
176 return; | 176 return; |
177 } | 177 } |
178 dict = argvars[2].vval.v_dict; | 178 dict = argvars[2].vval.v_dict; |
179 | 179 |
180 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL) | 180 if (dict == NULL || dict_find(dict, (char_u *)"type", -1) == NULL) |
181 { | 181 { |
182 EMSG(_("E965: missing property type name")); | 182 emsg(_("E965: missing property type name")); |
183 return; | 183 return; |
184 } | 184 } |
185 type_name = dict_get_string(dict, (char_u *)"type", FALSE); | 185 type_name = dict_get_string(dict, (char_u *)"type", FALSE); |
186 | 186 |
187 if (dict_find(dict, (char_u *)"end_lnum", -1) != NULL) | 187 if (dict_find(dict, (char_u *)"end_lnum", -1) != NULL) |
188 { | 188 { |
189 end_lnum = dict_get_number(dict, (char_u *)"end_lnum"); | 189 end_lnum = dict_get_number(dict, (char_u *)"end_lnum"); |
190 if (end_lnum < start_lnum) | 190 if (end_lnum < start_lnum) |
191 { | 191 { |
192 EMSG2(_(e_invargval), "end_lnum"); | 192 semsg(_(e_invargval), "end_lnum"); |
193 return; | 193 return; |
194 } | 194 } |
195 } | 195 } |
196 else | 196 else |
197 end_lnum = start_lnum; | 197 end_lnum = start_lnum; |
200 { | 200 { |
201 long length = dict_get_number(dict, (char_u *)"length"); | 201 long length = dict_get_number(dict, (char_u *)"length"); |
202 | 202 |
203 if (length < 0 || end_lnum > start_lnum) | 203 if (length < 0 || end_lnum > start_lnum) |
204 { | 204 { |
205 EMSG2(_(e_invargval), "length"); | 205 semsg(_(e_invargval), "length"); |
206 return; | 206 return; |
207 } | 207 } |
208 end_col = start_col + length; | 208 end_col = start_col + length; |
209 } | 209 } |
210 else if (dict_find(dict, (char_u *)"end_col", -1) != NULL) | 210 else if (dict_find(dict, (char_u *)"end_col", -1) != NULL) |
211 { | 211 { |
212 end_col = dict_get_number(dict, (char_u *)"end_col"); | 212 end_col = dict_get_number(dict, (char_u *)"end_col"); |
213 if (end_col <= 0) | 213 if (end_col <= 0) |
214 { | 214 { |
215 EMSG2(_(e_invargval), "end_col"); | 215 semsg(_(e_invargval), "end_col"); |
216 return; | 216 return; |
217 } | 217 } |
218 } | 218 } |
219 else if (start_lnum == end_lnum) | 219 else if (start_lnum == end_lnum) |
220 end_col = start_col; | 220 end_col = start_col; |
231 if (type == NULL) | 231 if (type == NULL) |
232 return; | 232 return; |
233 | 233 |
234 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) | 234 if (start_lnum < 1 || start_lnum > buf->b_ml.ml_line_count) |
235 { | 235 { |
236 EMSGN(_(e_invalid_lnum), (long)start_lnum); | 236 semsg(_(e_invalid_lnum), (long)start_lnum); |
237 return; | 237 return; |
238 } | 238 } |
239 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) | 239 if (end_lnum < start_lnum || end_lnum > buf->b_ml.ml_line_count) |
240 { | 240 { |
241 EMSGN(_(e_invalid_lnum), (long)end_lnum); | 241 semsg(_(e_invalid_lnum), (long)end_lnum); |
242 return; | 242 return; |
243 } | 243 } |
244 | 244 |
245 for (lnum = start_lnum; lnum <= end_lnum; ++lnum) | 245 for (lnum = start_lnum; lnum <= end_lnum; ++lnum) |
246 { | 246 { |
255 col = start_col; | 255 col = start_col; |
256 else | 256 else |
257 col = 1; | 257 col = 1; |
258 if (col - 1 > (colnr_T)textlen) | 258 if (col - 1 > (colnr_T)textlen) |
259 { | 259 { |
260 EMSGN(_(e_invalid_col), (long)start_col); | 260 semsg(_(e_invalid_col), (long)start_col); |
261 return; | 261 return; |
262 } | 262 } |
263 | 263 |
264 if (lnum == end_lnum) | 264 if (lnum == end_lnum) |
265 length = end_col - col; | 265 length = end_col - col; |
338 text = ml_get_buf(buf, lnum, will_change); | 338 text = ml_get_buf(buf, lnum, will_change); |
339 textlen = STRLEN(text) + 1; | 339 textlen = STRLEN(text) + 1; |
340 proplen = buf->b_ml.ml_line_len - textlen; | 340 proplen = buf->b_ml.ml_line_len - textlen; |
341 if (proplen % sizeof(textprop_T) != 0) | 341 if (proplen % sizeof(textprop_T) != 0) |
342 { | 342 { |
343 IEMSG(_("E967: text property info corrupted")); | 343 iemsg(_("E967: text property info corrupted")); |
344 return 0; | 344 return 0; |
345 } | 345 } |
346 if (proplen > 0) | 346 if (proplen > 0) |
347 *props = text + textlen; | 347 *props = text + textlen; |
348 return (int)(proplen / sizeof(textprop_T)); | 348 return (int)(proplen / sizeof(textprop_T)); |
438 return; | 438 return; |
439 } | 439 } |
440 } | 440 } |
441 if (start < 1 || end < 1) | 441 if (start < 1 || end < 1) |
442 { | 442 { |
443 EMSG(_(e_invrange)); | 443 emsg(_(e_invrange)); |
444 return; | 444 return; |
445 } | 445 } |
446 | 446 |
447 for (lnum = start; lnum <= end; ++lnum) | 447 for (lnum = start; lnum <= end; ++lnum) |
448 { | 448 { |
485 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL) | 485 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL) |
486 return; | 486 return; |
487 } | 487 } |
488 if (lnum < 1 || lnum > buf->b_ml.ml_line_count) | 488 if (lnum < 1 || lnum > buf->b_ml.ml_line_count) |
489 { | 489 { |
490 EMSG(_(e_invrange)); | 490 emsg(_(e_invrange)); |
491 return; | 491 return; |
492 } | 492 } |
493 | 493 |
494 if (rettv_list_alloc(rettv) == OK) | 494 if (rettv_list_alloc(rettv) == OK) |
495 { | 495 { |
540 int type_id = -1; | 540 int type_id = -1; |
541 | 541 |
542 rettv->vval.v_number = 0; | 542 rettv->vval.v_number = 0; |
543 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) | 543 if (argvars[0].v_type != VAR_DICT || argvars[0].vval.v_dict == NULL) |
544 { | 544 { |
545 EMSG(_(e_invarg)); | 545 emsg(_(e_invarg)); |
546 return; | 546 return; |
547 } | 547 } |
548 | 548 |
549 if (argvars[1].v_type != VAR_UNKNOWN) | 549 if (argvars[1].v_type != VAR_UNKNOWN) |
550 { | 550 { |
552 end = start; | 552 end = start; |
553 if (argvars[2].v_type != VAR_UNKNOWN) | 553 if (argvars[2].v_type != VAR_UNKNOWN) |
554 end = tv_get_number(&argvars[2]); | 554 end = tv_get_number(&argvars[2]); |
555 if (start < 1 || end < 1) | 555 if (start < 1 || end < 1) |
556 { | 556 { |
557 EMSG(_(e_invrange)); | 557 emsg(_(e_invrange)); |
558 return; | 558 return; |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
562 dict = argvars[0].vval.v_dict; | 562 dict = argvars[0].vval.v_dict; |
583 return; | 583 return; |
584 type_id = type->pt_id; | 584 type_id = type->pt_id; |
585 } | 585 } |
586 if (id == -1 && type_id == -1) | 586 if (id == -1 && type_id == -1) |
587 { | 587 { |
588 EMSG(_("E968: Need at least one of 'id' or 'type'")); | 588 emsg(_("E968: Need at least one of 'id' or 'type'")); |
589 return; | 589 return; |
590 } | 590 } |
591 | 591 |
592 if (end == 0) | 592 if (end == 0) |
593 end = buf->b_ml.ml_line_count; | 593 end = buf->b_ml.ml_line_count; |
659 proptype_T *prop; | 659 proptype_T *prop; |
660 | 660 |
661 name = tv_get_string(&argvars[0]); | 661 name = tv_get_string(&argvars[0]); |
662 if (*name == NUL) | 662 if (*name == NUL) |
663 { | 663 { |
664 EMSG(_(e_invarg)); | 664 emsg(_(e_invarg)); |
665 return; | 665 return; |
666 } | 666 } |
667 | 667 |
668 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL) | 668 if (get_bufnr_from_arg(&argvars[1], &buf) == FAIL) |
669 return; | 669 return; |
674 { | 674 { |
675 hashtab_T **htp; | 675 hashtab_T **htp; |
676 | 676 |
677 if (prop != NULL) | 677 if (prop != NULL) |
678 { | 678 { |
679 EMSG2(_("E969: Property type %s already defined"), name); | 679 semsg(_("E969: Property type %s already defined"), name); |
680 return; | 680 return; |
681 } | 681 } |
682 prop = (proptype_T *)alloc_clear((int)(sizeof(proptype_T) + STRLEN(name))); | 682 prop = (proptype_T *)alloc_clear((int)(sizeof(proptype_T) + STRLEN(name))); |
683 if (prop == NULL) | 683 if (prop == NULL) |
684 return; | 684 return; |
699 } | 699 } |
700 else | 700 else |
701 { | 701 { |
702 if (prop == NULL) | 702 if (prop == NULL) |
703 { | 703 { |
704 EMSG2(_(e_type_not_exist), name); | 704 semsg(_(e_type_not_exist), name); |
705 return; | 705 return; |
706 } | 706 } |
707 } | 707 } |
708 | 708 |
709 if (dict != NULL) | 709 if (dict != NULL) |
717 highlight = dict_get_string(dict, (char_u *)"highlight", FALSE); | 717 highlight = dict_get_string(dict, (char_u *)"highlight", FALSE); |
718 if (highlight != NULL && *highlight != NUL) | 718 if (highlight != NULL && *highlight != NUL) |
719 hl_id = syn_name2id(highlight); | 719 hl_id = syn_name2id(highlight); |
720 if (hl_id <= 0) | 720 if (hl_id <= 0) |
721 { | 721 { |
722 EMSG2(_("E970: Unknown highlight group name: '%s'"), | 722 semsg(_("E970: Unknown highlight group name: '%s'"), |
723 highlight == NULL ? (char_u *)"" : highlight); | 723 highlight == NULL ? (char_u *)"" : highlight); |
724 return; | 724 return; |
725 } | 725 } |
726 prop->pt_hl_id = hl_id; | 726 prop->pt_hl_id = hl_id; |
727 } | 727 } |
779 hashitem_T *hi; | 779 hashitem_T *hi; |
780 | 780 |
781 name = tv_get_string(&argvars[0]); | 781 name = tv_get_string(&argvars[0]); |
782 if (*name == NUL) | 782 if (*name == NUL) |
783 { | 783 { |
784 EMSG(_(e_invarg)); | 784 emsg(_(e_invarg)); |
785 return; | 785 return; |
786 } | 786 } |
787 | 787 |
788 if (argvars[1].v_type != VAR_UNKNOWN) | 788 if (argvars[1].v_type != VAR_UNKNOWN) |
789 { | 789 { |
814 { | 814 { |
815 char_u *name = tv_get_string(&argvars[0]); | 815 char_u *name = tv_get_string(&argvars[0]); |
816 | 816 |
817 if (*name == NUL) | 817 if (*name == NUL) |
818 { | 818 { |
819 EMSG(_(e_invarg)); | 819 emsg(_(e_invarg)); |
820 return; | 820 return; |
821 } | 821 } |
822 if (rettv_dict_alloc(rettv) == OK) | 822 if (rettv_dict_alloc(rettv) == OK) |
823 { | 823 { |
824 proptype_T *prop = NULL; | 824 proptype_T *prop = NULL; |