forked from aniani/vim
patch 9.0.0601: too much indent
Problem: Too much indent. Solution: Return out early from a funtion. (Yegappan Lakshmanan, close #11238)
This commit is contained in:
committed by
Bram Moolenaar
parent
d324742292
commit
368aa69088
105
src/beval.c
105
src/beval.c
@@ -39,16 +39,19 @@ find_word_under_cursor(
|
|||||||
|
|
||||||
*textp = NULL;
|
*textp = NULL;
|
||||||
wp = mouse_find_win(&row, &col, FAIL_POPUP);
|
wp = mouse_find_win(&row, &col, FAIL_POPUP);
|
||||||
if (wp != NULL && row >= 0 && row < wp->w_height && col < wp->w_width)
|
if (wp == NULL || row < 0 || row >= wp->w_height || col >= wp->w_width)
|
||||||
{
|
return FAIL;
|
||||||
|
|
||||||
// Found a window and the cursor is in the text. Now find the line
|
// Found a window and the cursor is in the text. Now find the line
|
||||||
// number.
|
// number.
|
||||||
if (!mouse_comp_pos(wp, &row, &col, &lnum, NULL))
|
if (mouse_comp_pos(wp, &row, &col, &lnum, NULL))
|
||||||
{
|
return FAIL; // position is below the last line
|
||||||
|
|
||||||
// Not past end of the file.
|
// Not past end of the file.
|
||||||
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
||||||
if (col <= win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
|
if (col > win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
|
||||||
{
|
return FAIL; // past end of line
|
||||||
|
|
||||||
// Not past end of line.
|
// Not past end of line.
|
||||||
if (getword)
|
if (getword)
|
||||||
{
|
{
|
||||||
@@ -122,11 +125,8 @@ find_word_under_cursor(
|
|||||||
*colp = col;
|
*colp = col;
|
||||||
if (startcolp != NULL)
|
if (startcolp != NULL)
|
||||||
*startcolp = scol;
|
*startcolp = scol;
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FAIL;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -220,45 +220,26 @@ can_use_beval(void)
|
|||||||
) && msg_scrolled == 0;
|
) && msg_scrolled == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef FEAT_EVAL
|
||||||
/*
|
/*
|
||||||
* Common code, invoked when the mouse is resting for a moment.
|
* Evaluate the expression 'bexpr' and set the text in the balloon 'beval'.
|
||||||
*/
|
*/
|
||||||
void
|
static void
|
||||||
general_beval_cb(BalloonEval *beval, int state UNUSED)
|
bexpr_eval(
|
||||||
|
BalloonEval *beval,
|
||||||
|
char_u *bexpr,
|
||||||
|
win_T *wp,
|
||||||
|
linenr_T lnum,
|
||||||
|
int col,
|
||||||
|
char_u *text)
|
||||||
{
|
{
|
||||||
#ifdef FEAT_EVAL
|
|
||||||
win_T *wp;
|
|
||||||
int col;
|
|
||||||
int use_sandbox;
|
|
||||||
linenr_T lnum;
|
|
||||||
char_u *text;
|
|
||||||
static char_u *result = NULL;
|
|
||||||
long winnr = 0;
|
|
||||||
char_u *bexpr;
|
|
||||||
buf_T *save_curbuf;
|
|
||||||
size_t len;
|
|
||||||
win_T *cw;
|
win_T *cw;
|
||||||
#endif
|
long winnr = 0;
|
||||||
static int recursive = FALSE;
|
buf_T *save_curbuf;
|
||||||
|
int use_sandbox;
|
||||||
|
static char_u *result = NULL;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
// Don't do anything when 'ballooneval' is off, messages scrolled the
|
|
||||||
// windows up or we have no beval area.
|
|
||||||
if (!can_use_beval() || beval == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Don't do this recursively. Happens when the expression evaluation
|
|
||||||
// takes a long time and invokes something that checks for CTRL-C typed.
|
|
||||||
if (recursive)
|
|
||||||
return;
|
|
||||||
recursive = TRUE;
|
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
|
||||||
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
|
|
||||||
{
|
|
||||||
bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr
|
|
||||||
: wp->w_buffer->b_p_bexpr;
|
|
||||||
if (*bexpr != NUL)
|
|
||||||
{
|
|
||||||
sctx_T save_sctx = current_sctx;
|
sctx_T save_sctx = current_sctx;
|
||||||
|
|
||||||
// Convert window pointer to number.
|
// Convert window pointer to number.
|
||||||
@@ -322,7 +303,43 @@ general_beval_cb(BalloonEval *beval, int state UNUSED)
|
|||||||
// that requires a screen update.
|
// that requires a screen update.
|
||||||
if (must_redraw)
|
if (must_redraw)
|
||||||
redraw_after_callback(FALSE, FALSE);
|
redraw_after_callback(FALSE, FALSE);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Common code, invoked when the mouse is resting for a moment.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
general_beval_cb(BalloonEval *beval, int state UNUSED)
|
||||||
|
{
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
win_T *wp;
|
||||||
|
int col;
|
||||||
|
linenr_T lnum;
|
||||||
|
char_u *text;
|
||||||
|
char_u *bexpr;
|
||||||
|
#endif
|
||||||
|
static int recursive = FALSE;
|
||||||
|
|
||||||
|
// Don't do anything when 'ballooneval' is off, messages scrolled the
|
||||||
|
// windows up or we have no beval area.
|
||||||
|
if (!can_use_beval() || beval == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Don't do this recursively. Happens when the expression evaluation
|
||||||
|
// takes a long time and invokes something that checks for CTRL-C typed.
|
||||||
|
if (recursive)
|
||||||
|
return;
|
||||||
|
recursive = TRUE;
|
||||||
|
|
||||||
|
#ifdef FEAT_EVAL
|
||||||
|
if (get_beval_info(beval, TRUE, &wp, &lnum, &text, &col) == OK)
|
||||||
|
{
|
||||||
|
bexpr = (*wp->w_buffer->b_p_bexpr == NUL) ? p_bexpr
|
||||||
|
: wp->w_buffer->b_p_bexpr;
|
||||||
|
if (*bexpr != NUL)
|
||||||
|
{
|
||||||
|
bexpr_eval(beval, bexpr, wp, lnum, col, text);
|
||||||
recursive = FALSE;
|
recursive = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
82
src/blob.c
82
src/blob.c
@@ -60,18 +60,20 @@ rettv_blob_set(typval_T *rettv, blob_T *b)
|
|||||||
int
|
int
|
||||||
blob_copy(blob_T *from, typval_T *to)
|
blob_copy(blob_T *from, typval_T *to)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int len;
|
||||||
|
|
||||||
to->v_type = VAR_BLOB;
|
to->v_type = VAR_BLOB;
|
||||||
to->v_lock = 0;
|
to->v_lock = 0;
|
||||||
if (from == NULL)
|
if (from == NULL)
|
||||||
to->vval.v_blob = NULL;
|
|
||||||
else if (rettv_blob_alloc(to) == FAIL)
|
|
||||||
ret = FAIL;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
int len = from->bv_ga.ga_len;
|
to->vval.v_blob = NULL;
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rettv_blob_alloc(to) == FAIL)
|
||||||
|
return FAIL;
|
||||||
|
|
||||||
|
len = from->bv_ga.ga_len;
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
{
|
{
|
||||||
to->vval.v_blob->bv_ga.ga_data =
|
to->vval.v_blob->bv_ga.ga_data =
|
||||||
@@ -81,8 +83,8 @@ blob_copy(blob_T *from, typval_T *to)
|
|||||||
}
|
}
|
||||||
to->vval.v_blob->bv_ga.ga_len = len;
|
to->vval.v_blob->bv_ga.ga_len = len;
|
||||||
to->vval.v_blob->bv_ga.ga_maxlen = len;
|
to->vval.v_blob->bv_ga.ga_maxlen = len;
|
||||||
}
|
|
||||||
return ret;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -280,21 +282,19 @@ failed:
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/*
|
||||||
blob_slice_or_index(
|
* Returns a slice of 'blob' from index 'n1' to 'n2' in 'rettv'. The length of
|
||||||
|
* the blob is 'len'. Returns an empty blob if the indexes are out of range.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
blob_slice(
|
||||||
blob_T *blob,
|
blob_T *blob,
|
||||||
int is_range,
|
long len,
|
||||||
varnumber_T n1,
|
varnumber_T n1,
|
||||||
varnumber_T n2,
|
varnumber_T n2,
|
||||||
int exclusive,
|
int exclusive,
|
||||||
typval_T *rettv)
|
typval_T *rettv)
|
||||||
{
|
{
|
||||||
long len = blob_len(blob);
|
|
||||||
|
|
||||||
if (is_range)
|
|
||||||
{
|
|
||||||
// The resulting variable is a sub-blob. If the indexes
|
|
||||||
// are out of range the result is empty.
|
|
||||||
if (n1 < 0)
|
if (n1 < 0)
|
||||||
{
|
{
|
||||||
n1 = len + n1;
|
n1 = len + n1;
|
||||||
@@ -333,16 +333,28 @@ blob_slice_or_index(
|
|||||||
rettv_blob_set(rettv, new_blob);
|
rettv_blob_set(rettv, new_blob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
return OK;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the byte value in 'blob' at index 'idx' in 'rettv'. If the index is
|
||||||
|
* too big or negative that is an error. The length of the blob is 'len'.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
blob_index(
|
||||||
|
blob_T *blob,
|
||||||
|
int len,
|
||||||
|
varnumber_T idx,
|
||||||
|
typval_T *rettv)
|
||||||
|
{
|
||||||
// The resulting variable is a byte value.
|
// The resulting variable is a byte value.
|
||||||
// If the index is too big or negative that is an error.
|
// If the index is too big or negative that is an error.
|
||||||
if (n1 < 0)
|
if (idx < 0)
|
||||||
n1 = len + n1;
|
idx = len + idx;
|
||||||
if (n1 < len && n1 >= 0)
|
if (idx < len && idx >= 0)
|
||||||
{
|
{
|
||||||
int v = blob_get(blob, n1);
|
int v = blob_get(blob, idx);
|
||||||
|
|
||||||
clear_tv(rettv);
|
clear_tv(rettv);
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
@@ -350,10 +362,28 @@ blob_slice_or_index(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
semsg(_(e_blob_index_out_of_range_nr), n1);
|
semsg(_(e_blob_index_out_of_range_nr), idx);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
blob_slice_or_index(
|
||||||
|
blob_T *blob,
|
||||||
|
int is_range,
|
||||||
|
varnumber_T n1,
|
||||||
|
varnumber_T n2,
|
||||||
|
int exclusive,
|
||||||
|
typval_T *rettv)
|
||||||
|
{
|
||||||
|
long len = blob_len(blob);
|
||||||
|
|
||||||
|
if (is_range)
|
||||||
|
return blob_slice(blob, len, n1, n2, exclusive, rettv);
|
||||||
|
else
|
||||||
|
return blob_index(blob, len, n1, rettv);
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -699,6 +699,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
601,
|
||||||
/**/
|
/**/
|
||||||
600,
|
600,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user