Mercurial > vim
comparison src/eval.c @ 5938:ccac0aa34eea v7.4.310
updated for version 7.4.310
Problem: getpos()/setpos() don't include curswant.
Solution: Add a fifth number when getting/setting the cursor.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 28 May 2014 14:34:46 +0200 |
parents | 05e1d8afcc5e |
children | f6f754304324 |
comparison
equal
deleted
inserted
replaced
5937:dd7113658e9e | 5938:ccac0aa34eea |
---|---|
762 static void f_winsaveview __ARGS((typval_T *argvars, typval_T *rettv)); | 762 static void f_winsaveview __ARGS((typval_T *argvars, typval_T *rettv)); |
763 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv)); | 763 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv)); |
764 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv)); | 764 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv)); |
765 static void f_xor __ARGS((typval_T *argvars, typval_T *rettv)); | 765 static void f_xor __ARGS((typval_T *argvars, typval_T *rettv)); |
766 | 766 |
767 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump)); | 767 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp)); |
768 static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum)); | 768 static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum)); |
769 static int get_env_len __ARGS((char_u **arg)); | 769 static int get_env_len __ARGS((char_u **arg)); |
770 static int get_id_len __ARGS((char_u **arg)); | 770 static int get_id_len __ARGS((char_u **arg)); |
771 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose)); | 771 static int get_name_len __ARGS((char_u **arg, char_u **alias, int evaluate, int verbose)); |
772 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int flags)); | 772 static char_u *find_name_end __ARGS((char_u *arg, char_u **expr_start, char_u **expr_end, int flags)); |
9797 | 9797 |
9798 rettv->vval.v_number = -1; | 9798 rettv->vval.v_number = -1; |
9799 if (argvars[1].v_type == VAR_UNKNOWN) | 9799 if (argvars[1].v_type == VAR_UNKNOWN) |
9800 { | 9800 { |
9801 pos_T pos; | 9801 pos_T pos; |
9802 | 9802 colnr_T curswant = -1; |
9803 if (list2fpos(argvars, &pos, NULL) == FAIL) | 9803 |
9804 if (list2fpos(argvars, &pos, NULL, &curswant) == FAIL) | |
9804 return; | 9805 return; |
9805 line = pos.lnum; | 9806 line = pos.lnum; |
9806 col = pos.col; | 9807 col = pos.col; |
9807 #ifdef FEAT_VIRTUALEDIT | 9808 #ifdef FEAT_VIRTUALEDIT |
9808 coladd = pos.coladd; | 9809 coladd = pos.coladd; |
9809 #endif | 9810 #endif |
9811 if (curswant >= 0) | |
9812 curwin->w_curswant = curswant - 1; | |
9810 } | 9813 } |
9811 else | 9814 else |
9812 { | 9815 { |
9813 line = get_tv_lnum(argvars); | 9816 line = get_tv_lnum(argvars); |
9814 col = get_tv_number_chk(&argvars[1], NULL); | 9817 col = get_tv_number_chk(&argvars[1], NULL); |
11768 list_append_number(l, | 11771 list_append_number(l, |
11769 #ifdef FEAT_VIRTUALEDIT | 11772 #ifdef FEAT_VIRTUALEDIT |
11770 (fp != NULL) ? (varnumber_T)fp->coladd : | 11773 (fp != NULL) ? (varnumber_T)fp->coladd : |
11771 #endif | 11774 #endif |
11772 (varnumber_T)0); | 11775 (varnumber_T)0); |
11776 if (fp == &curwin->w_cursor) | |
11777 list_append_number(l, (varnumber_T)curwin->w_curswant + 1); | |
11773 } | 11778 } |
11774 else | 11779 else |
11775 rettv->vval.v_number = FALSE; | 11780 rettv->vval.v_number = FALSE; |
11776 } | 11781 } |
11777 | 11782 |
16749 typval_T *rettv; | 16754 typval_T *rettv; |
16750 { | 16755 { |
16751 pos_T pos; | 16756 pos_T pos; |
16752 int fnum; | 16757 int fnum; |
16753 char_u *name; | 16758 char_u *name; |
16759 colnr_T curswant = -1; | |
16754 | 16760 |
16755 rettv->vval.v_number = -1; | 16761 rettv->vval.v_number = -1; |
16756 name = get_tv_string_chk(argvars); | 16762 name = get_tv_string_chk(argvars); |
16757 if (name != NULL) | 16763 if (name != NULL) |
16758 { | 16764 { |
16759 if (list2fpos(&argvars[1], &pos, &fnum) == OK) | 16765 if (list2fpos(&argvars[1], &pos, &fnum, &curswant) == OK) |
16760 { | 16766 { |
16761 if (--pos.col < 0) | 16767 if (--pos.col < 0) |
16762 pos.col = 0; | 16768 pos.col = 0; |
16763 if (name[0] == '.' && name[1] == NUL) | 16769 if (name[0] == '.' && name[1] == NUL) |
16764 { | 16770 { |
16765 /* set cursor */ | 16771 /* set cursor */ |
16766 if (fnum == curbuf->b_fnum) | 16772 if (fnum == curbuf->b_fnum) |
16767 { | 16773 { |
16768 curwin->w_cursor = pos; | 16774 curwin->w_cursor = pos; |
16775 if (curswant >= 0) | |
16776 curwin->w_curswant = curswant - 1; | |
16769 check_cursor(); | 16777 check_cursor(); |
16770 rettv->vval.v_number = 0; | 16778 rettv->vval.v_number = 0; |
16771 } | 16779 } |
16772 else | 16780 else |
16773 EMSG(_(e_invarg)); | 16781 EMSG(_(e_invarg)); |
19530 * it to use 1 for the first column. | 19538 * it to use 1 for the first column. |
19531 * Return FAIL when conversion is not possible, doesn't check the position for | 19539 * Return FAIL when conversion is not possible, doesn't check the position for |
19532 * validity. | 19540 * validity. |
19533 */ | 19541 */ |
19534 static int | 19542 static int |
19535 list2fpos(arg, posp, fnump) | 19543 list2fpos(arg, posp, fnump, curswantp) |
19536 typval_T *arg; | 19544 typval_T *arg; |
19537 pos_T *posp; | 19545 pos_T *posp; |
19538 int *fnump; | 19546 int *fnump; |
19547 colnr_T *curswantp; | |
19539 { | 19548 { |
19540 list_T *l = arg->vval.v_list; | 19549 list_T *l = arg->vval.v_list; |
19541 long i = 0; | 19550 long i = 0; |
19542 long n; | 19551 long n; |
19543 | 19552 |
19544 /* List must be: [fnum, lnum, col, coladd], where "fnum" is only there | 19553 /* List must be: [fnum, lnum, col, coladd, curswant], where "fnum" is only |
19545 * when "fnump" isn't NULL and "coladd" is optional. */ | 19554 * there when "fnump" isn't NULL; "coladd" and "curswant" are optional. */ |
19546 if (arg->v_type != VAR_LIST | 19555 if (arg->v_type != VAR_LIST |
19547 || l == NULL | 19556 || l == NULL |
19548 || l->lv_len < (fnump == NULL ? 2 : 3) | 19557 || l->lv_len < (fnump == NULL ? 2 : 3) |
19549 || l->lv_len > (fnump == NULL ? 3 : 4)) | 19558 || l->lv_len > (fnump == NULL ? 4 : 5)) |
19550 return FAIL; | 19559 return FAIL; |
19551 | 19560 |
19552 if (fnump != NULL) | 19561 if (fnump != NULL) |
19553 { | 19562 { |
19554 n = list_find_nr(l, i++, NULL); /* fnum */ | 19563 n = list_find_nr(l, i++, NULL); /* fnum */ |
19568 if (n < 0) | 19577 if (n < 0) |
19569 return FAIL; | 19578 return FAIL; |
19570 posp->col = n; | 19579 posp->col = n; |
19571 | 19580 |
19572 #ifdef FEAT_VIRTUALEDIT | 19581 #ifdef FEAT_VIRTUALEDIT |
19573 n = list_find_nr(l, i, NULL); | 19582 n = list_find_nr(l, i, NULL); /* off */ |
19574 if (n < 0) | 19583 if (n < 0) |
19575 posp->coladd = 0; | 19584 posp->coladd = 0; |
19576 else | 19585 else |
19577 posp->coladd = n; | 19586 posp->coladd = n; |
19578 #endif | 19587 #endif |
19588 | |
19589 if (curswantp != NULL) | |
19590 *curswantp = list_find_nr(l, i + 1, NULL); /* curswant */ | |
19579 | 19591 |
19580 return OK; | 19592 return OK; |
19581 } | 19593 } |
19582 | 19594 |
19583 /* | 19595 /* |