Mercurial > vim
comparison src/evalfunc.c @ 16133:eb087f8a26a8 v8.1.1071
patch 8.1.1071: cannot get composing characters from the screen
commit https://github.com/vim/vim/commit/2912abb3a2fd72074e3901c8ae1d4a77ce764675
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 29 14:16:42 2019 +0100
patch 8.1.1071: cannot get composing characters from the screen
Problem: Cannot get composing characters from the screen.
Solution: Add screenchars() and screenstring(). (partly by Ozaki Kiichi,
closes #4059)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 29 Mar 2019 14:30:05 +0100 |
parents | 0375e54f0adc |
children | 570a296aa0b4 |
comparison
equal
deleted
inserted
replaced
16132:e6681a9165bf | 16133:eb087f8a26a8 |
---|---|
342 #ifdef FEAT_RUBY | 342 #ifdef FEAT_RUBY |
343 static void f_rubyeval(typval_T *argvars, typval_T *rettv); | 343 static void f_rubyeval(typval_T *argvars, typval_T *rettv); |
344 #endif | 344 #endif |
345 static void f_screenattr(typval_T *argvars, typval_T *rettv); | 345 static void f_screenattr(typval_T *argvars, typval_T *rettv); |
346 static void f_screenchar(typval_T *argvars, typval_T *rettv); | 346 static void f_screenchar(typval_T *argvars, typval_T *rettv); |
347 static void f_screenchars(typval_T *argvars, typval_T *rettv); | |
347 static void f_screencol(typval_T *argvars, typval_T *rettv); | 348 static void f_screencol(typval_T *argvars, typval_T *rettv); |
348 static void f_screenrow(typval_T *argvars, typval_T *rettv); | 349 static void f_screenrow(typval_T *argvars, typval_T *rettv); |
350 static void f_screenstring(typval_T *argvars, typval_T *rettv); | |
349 static void f_search(typval_T *argvars, typval_T *rettv); | 351 static void f_search(typval_T *argvars, typval_T *rettv); |
350 static void f_searchdecl(typval_T *argvars, typval_T *rettv); | 352 static void f_searchdecl(typval_T *argvars, typval_T *rettv); |
351 static void f_searchpair(typval_T *argvars, typval_T *rettv); | 353 static void f_searchpair(typval_T *argvars, typval_T *rettv); |
352 static void f_searchpairpos(typval_T *argvars, typval_T *rettv); | 354 static void f_searchpairpos(typval_T *argvars, typval_T *rettv); |
353 static void f_searchpos(typval_T *argvars, typval_T *rettv); | 355 static void f_searchpos(typval_T *argvars, typval_T *rettv); |
837 #ifdef FEAT_RUBY | 839 #ifdef FEAT_RUBY |
838 {"rubyeval", 1, 1, f_rubyeval}, | 840 {"rubyeval", 1, 1, f_rubyeval}, |
839 #endif | 841 #endif |
840 {"screenattr", 2, 2, f_screenattr}, | 842 {"screenattr", 2, 2, f_screenattr}, |
841 {"screenchar", 2, 2, f_screenchar}, | 843 {"screenchar", 2, 2, f_screenchar}, |
844 {"screenchars", 2, 2, f_screenchars}, | |
842 {"screencol", 0, 0, f_screencol}, | 845 {"screencol", 0, 0, f_screencol}, |
843 {"screenrow", 0, 0, f_screenrow}, | 846 {"screenrow", 0, 0, f_screenrow}, |
847 {"screenstring", 2, 2, f_screenstring}, | |
844 {"search", 1, 4, f_search}, | 848 {"search", 1, 4, f_search}, |
845 {"searchdecl", 1, 3, f_searchdecl}, | 849 {"searchdecl", 1, 3, f_searchdecl}, |
846 {"searchpair", 3, 7, f_searchpair}, | 850 {"searchpair", 3, 7, f_searchpair}, |
847 {"searchpairpos", 3, 7, f_searchpairpos}, | 851 {"searchpairpos", 3, 7, f_searchpairpos}, |
848 {"searchpos", 1, 4, f_searchpos}, | 852 {"searchpos", 1, 4, f_searchpos}, |
10428 int off; | 10432 int off; |
10429 int c; | 10433 int c; |
10430 | 10434 |
10431 row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; | 10435 row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; |
10432 col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; | 10436 col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; |
10433 if (row < 0 || row >= screen_Rows | 10437 if (row < 0 || row >= screen_Rows || col < 0 || col >= screen_Columns) |
10434 || col < 0 || col >= screen_Columns) | |
10435 c = -1; | 10438 c = -1; |
10436 else | 10439 else |
10437 { | 10440 { |
10438 off = LineOffset[row] + col; | 10441 off = LineOffset[row] + col; |
10439 if (enc_utf8 && ScreenLinesUC[off] != 0) | 10442 if (enc_utf8 && ScreenLinesUC[off] != 0) |
10443 } | 10446 } |
10444 rettv->vval.v_number = c; | 10447 rettv->vval.v_number = c; |
10445 } | 10448 } |
10446 | 10449 |
10447 /* | 10450 /* |
10451 * "screenchars()" function | |
10452 */ | |
10453 static void | |
10454 f_screenchars(typval_T *argvars, typval_T *rettv) | |
10455 { | |
10456 int row; | |
10457 int col; | |
10458 int off; | |
10459 int c; | |
10460 int i; | |
10461 | |
10462 if (rettv_list_alloc(rettv) == FAIL) | |
10463 return; | |
10464 row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; | |
10465 col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; | |
10466 if (row < 0 || row >= screen_Rows || col < 0 || col >= screen_Columns) | |
10467 return; | |
10468 | |
10469 off = LineOffset[row] + col; | |
10470 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
10471 c = ScreenLinesUC[off]; | |
10472 else | |
10473 c = ScreenLines[off]; | |
10474 list_append_number(rettv->vval.v_list, (varnumber_T)c); | |
10475 | |
10476 if (enc_utf8) | |
10477 | |
10478 for (i = 0; i < Screen_mco && ScreenLinesC[i][off] != 0; ++i) | |
10479 list_append_number(rettv->vval.v_list, | |
10480 (varnumber_T)ScreenLinesC[i][off]); | |
10481 } | |
10482 | |
10483 /* | |
10448 * "screencol()" function | 10484 * "screencol()" function |
10449 * | 10485 * |
10450 * First column is 1 to be consistent with virtcol(). | 10486 * First column is 1 to be consistent with virtcol(). |
10451 */ | 10487 */ |
10452 static void | 10488 static void |
10460 */ | 10496 */ |
10461 static void | 10497 static void |
10462 f_screenrow(typval_T *argvars UNUSED, typval_T *rettv) | 10498 f_screenrow(typval_T *argvars UNUSED, typval_T *rettv) |
10463 { | 10499 { |
10464 rettv->vval.v_number = screen_screenrow() + 1; | 10500 rettv->vval.v_number = screen_screenrow() + 1; |
10501 } | |
10502 | |
10503 /* | |
10504 * "screenstring()" function | |
10505 */ | |
10506 static void | |
10507 f_screenstring(typval_T *argvars, typval_T *rettv) | |
10508 { | |
10509 int row; | |
10510 int col; | |
10511 int off; | |
10512 int c; | |
10513 int i; | |
10514 char_u buf[MB_MAXBYTES + 1]; | |
10515 int buflen = 0; | |
10516 | |
10517 rettv->vval.v_string = NULL; | |
10518 rettv->v_type = VAR_STRING; | |
10519 | |
10520 row = (int)tv_get_number_chk(&argvars[0], NULL) - 1; | |
10521 col = (int)tv_get_number_chk(&argvars[1], NULL) - 1; | |
10522 if (row < 0 || row >= screen_Rows || col < 0 || col >= screen_Columns) | |
10523 return; | |
10524 | |
10525 off = LineOffset[row] + col; | |
10526 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
10527 c = ScreenLinesUC[off]; | |
10528 else | |
10529 c = ScreenLines[off]; | |
10530 buflen += mb_char2bytes(c, buf); | |
10531 | |
10532 if (enc_utf8) | |
10533 for (i = 0; i < Screen_mco && ScreenLinesC[i][off] != 0; ++i) | |
10534 buflen += mb_char2bytes(ScreenLinesC[i][off], buf + buflen); | |
10535 | |
10536 buf[buflen] = NUL; | |
10537 rettv->vval.v_string = vim_strsave(buf); | |
10465 } | 10538 } |
10466 | 10539 |
10467 /* | 10540 /* |
10468 * "search()" function | 10541 * "search()" function |
10469 */ | 10542 */ |