Patch 9.0.0601
Problem: Too much indent.
Solution: Return out early from a funtion. (Yegappan Lakshmanan,
close #11238)
Files: src/beval.c, src/blob.c
*** ../vim-9.0.0600/src/beval.c 2022-07-25 18:13:33.046580756 +0100
--- src/beval.c 2022-09-27 11:40:09.701171458 +0100
***************
*** 39,132 ****
*textp = NULL;
wp = mouse_find_win(&row, &col, FAIL_POPUP);
! if (wp != NULL && row >= 0 && row < wp->w_height && col < wp->w_width)
{
! // Found a window and the cursor is in the text. Now find the line
! // number.
! if (!mouse_comp_pos(wp, &row, &col, &lnum, NULL))
{
! // Not past end of the file.
! lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
! if (col <= win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
{
! // Not past end of line.
! if (getword)
! {
! // For Netbeans we get the relevant part of the line
! // instead of the whole line.
! int len;
! pos_T *spos = NULL, *epos = NULL;
!
! if (VIsual_active)
! {
! if (LT_POS(VIsual, curwin->w_cursor))
! {
! spos = &VIsual;
! epos = &curwin->w_cursor;
! }
! else
! {
! spos = &curwin->w_cursor;
! epos = &VIsual;
! }
! }
!
! col = vcol2col(wp, lnum, col);
! scol = col;
!
! if (VIsual_active
! && wp->w_buffer == curwin->w_buffer
! && (lnum == spos->lnum
! ? col >= (int)spos->col
! : lnum > spos->lnum)
! && (lnum == epos->lnum
! ? col <= (int)epos->col
! : lnum < epos->lnum))
! {
! // Visual mode and pointing to the line with the
! // Visual selection: return selected text, with a
! // maximum of one line.
! if (spos->lnum != epos->lnum || spos->col == epos->col)
! return FAIL;
!
! lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE);
! len = epos->col - spos->col;
! if (*p_sel != 'e')
! len += mb_ptr2len(lbuf + epos->col);
! lbuf = vim_strnsave(lbuf + spos->col, len);
! lnum = spos->lnum;
! col = spos->col;
! scol = col;
! }
! else
! {
! // Find the word under the cursor.
! ++emsg_off;
! len = find_ident_at_pos(wp, lnum, (colnr_T)col,
! &lbuf, &scol, flags);
! --emsg_off;
! if (len == 0)
! return FAIL;
! lbuf = vim_strnsave(lbuf, len);
! }
! }
! else
! scol = col;
!
! if (winp != NULL)
! *winp = wp;
! if (lnump != NULL)
! *lnump = lnum;
! *textp = lbuf;
! if (colp != NULL)
! *colp = col;
! if (startcolp != NULL)
! *startcolp = scol;
! return OK;
}
}
}
! return FAIL;
}
#endif
--- 39,132 ----
*textp = NULL;
wp = mouse_find_win(&row, &col, FAIL_POPUP);
! 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
! // number.
! if (mouse_comp_pos(wp, &row, &col, &lnum, NULL))
! return FAIL; // position is below the last line
!
! // Not past end of the file.
! lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
! if (col > win_linetabsize(wp, lnum, lbuf, (colnr_T)MAXCOL))
! return FAIL; // past end of line
!
! // Not past end of line.
! if (getword)
{
! // For Netbeans we get the relevant part of the line
! // instead of the whole line.
! int len;
! pos_T *spos = NULL, *epos = NULL;
!
! if (VIsual_active)
{
! if (LT_POS(VIsual, curwin->w_cursor))
! {
! spos = &VIsual;
! epos = &curwin->w_cursor;
! }
! else
{
! spos = &curwin->w_cursor;
! epos = &VIsual;
}
}
+
+ col = vcol2col(wp, lnum, col);
+ scol = col;
+
+ if (VIsual_active
+ && wp->w_buffer == curwin->w_buffer
+ && (lnum == spos->lnum
+ ? col >= (int)spos->col
+ : lnum > spos->lnum)
+ && (lnum == epos->lnum
+ ? col <= (int)epos->col
+ : lnum < epos->lnum))
+ {
+ // Visual mode and pointing to the line with the
+ // Visual selection: return selected text, with a
+ // maximum of one line.
+ if (spos->lnum != epos->lnum || spos->col == epos->col)
+ return FAIL;
+
+ lbuf = ml_get_buf(curwin->w_buffer, VIsual.lnum, FALSE);
+ len = epos->col - spos->col;
+ if (*p_sel != 'e')
+ len += mb_ptr2len(lbuf + epos->col);
+ lbuf = vim_strnsave(lbuf + spos->col, len);
+ lnum = spos->lnum;
+ col = spos->col;
+ scol = col;
+ }
+ else
+ {
+ // Find the word under the cursor.
+ ++emsg_off;
+ len = find_ident_at_pos(wp, lnum, (colnr_T)col,
+ &lbuf, &scol, flags);
+ --emsg_off;
+ if (len == 0)
+ return FAIL;
+ lbuf = vim_strnsave(lbuf, len);
+ }
}
! else
! scol = col;
!
! if (winp != NULL)
! *winp = wp;
! if (lnump != NULL)
! *lnump = lnum;
! *textp = lbuf;
! if (colp != NULL)
! *colp = col;
! if (startcolp != NULL)
! *startcolp = scol;
!
! return OK;
}
#endif
***************
*** 220,225 ****
--- 220,311 ----
) && msg_scrolled == 0;
}
+ # ifdef FEAT_EVAL
+ /*
+ * Evaluate the expression 'bexpr' and set the text in the balloon 'beval'.
+ */
+ static void
+ bexpr_eval(
+ BalloonEval *beval,
+ char_u *bexpr,
+ win_T *wp,
+ linenr_T lnum,
+ int col,
+ char_u *text)
+ {
+ win_T *cw;
+ long winnr = 0;
+ buf_T *save_curbuf;
+ int use_sandbox;
+ static char_u *result = NULL;
+ size_t len;
+
+ sctx_T save_sctx = current_sctx;
+
+ // Convert window pointer to number.
+ for (cw = firstwin; cw != wp; cw = cw->w_next)
+ ++winnr;
+
+ set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum);
+ set_vim_var_nr(VV_BEVAL_WINNR, winnr);
+ set_vim_var_nr(VV_BEVAL_WINID, wp->w_id);
+ set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum);
+ set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1));
+ set_vim_var_string(VV_BEVAL_TEXT, text, -1);
+ vim_free(text);
+
+ /*
+ * Temporarily change the curbuf, so that we can determine whether
+ * the buffer-local balloonexpr option was set insecurely.
+ */
+ save_curbuf = curbuf;
+ curbuf = wp->w_buffer;
+ use_sandbox = was_set_insecurely((char_u *)"balloonexpr",
+ *curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL);
+ curbuf = save_curbuf;
+ if (use_sandbox)
+ ++sandbox;
+ ++textlock;
+
+ if (bexpr == p_bexpr)
+ {
+ sctx_T *sp = get_option_sctx("balloonexpr");
+
+ if (sp != NULL)
+ current_sctx = *sp;
+ }
+ else
+ current_sctx = curbuf->b_p_script_ctx[BV_BEXPR];
+
+ vim_free(result);
+ result = eval_to_string(bexpr, TRUE);
+
+ // Remove one trailing newline, it is added when the result was a
+ // list and it's hardly ever useful. If the user really wants a
+ // trailing newline he can add two and one remains.
+ if (result != NULL)
+ {
+ len = STRLEN(result);
+ if (len > 0 && result[len - 1] == NL)
+ result[len - 1] = NUL;
+ }
+
+ if (use_sandbox)
+ --sandbox;
+ --textlock;
+ current_sctx = save_sctx;
+
+ set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
+ if (result != NULL && result[0] != NUL)
+ post_balloon(beval, result, NULL);
+
+ // The 'balloonexpr' evaluation may show something on the screen
+ // that requires a screen update.
+ if (must_redraw)
+ redraw_after_callback(FALSE, FALSE);
+ }
+ # endif
+
/*
* Common code, invoked when the mouse is resting for a moment.
*/
***************
*** 229,243 ****
#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;
#endif
static int recursive = FALSE;
--- 315,323 ----
***************
*** 259,328 ****
: wp->w_buffer->b_p_bexpr;
if (*bexpr != NUL)
{
! sctx_T save_sctx = current_sctx;
!
! // Convert window pointer to number.
! for (cw = firstwin; cw != wp; cw = cw->w_next)
! ++winnr;
!
! set_vim_var_nr(VV_BEVAL_BUFNR, (long)wp->w_buffer->b_fnum);
! set_vim_var_nr(VV_BEVAL_WINNR, winnr);
! set_vim_var_nr(VV_BEVAL_WINID, wp->w_id);
! set_vim_var_nr(VV_BEVAL_LNUM, (long)lnum);
! set_vim_var_nr(VV_BEVAL_COL, (long)(col + 1));
! set_vim_var_string(VV_BEVAL_TEXT, text, -1);
! vim_free(text);
!
! /*
! * Temporarily change the curbuf, so that we can determine whether
! * the buffer-local balloonexpr option was set insecurely.
! */
! save_curbuf = curbuf;
! curbuf = wp->w_buffer;
! use_sandbox = was_set_insecurely((char_u *)"balloonexpr",
! *curbuf->b_p_bexpr == NUL ? 0 : OPT_LOCAL);
! curbuf = save_curbuf;
! if (use_sandbox)
! ++sandbox;
! ++textlock;
!
! if (bexpr == p_bexpr)
! {
! sctx_T *sp = get_option_sctx("balloonexpr");
!
! if (sp != NULL)
! current_sctx = *sp;
! }
! else
! current_sctx = curbuf->b_p_script_ctx[BV_BEXPR];
!
! vim_free(result);
! result = eval_to_string(bexpr, TRUE);
!
! // Remove one trailing newline, it is added when the result was a
! // list and it's hardly ever useful. If the user really wants a
! // trailing newline he can add two and one remains.
! if (result != NULL)
! {
! len = STRLEN(result);
! if (len > 0 && result[len - 1] == NL)
! result[len - 1] = NUL;
! }
!
! if (use_sandbox)
! --sandbox;
! --textlock;
! current_sctx = save_sctx;
!
! set_vim_var_string(VV_BEVAL_TEXT, NULL, -1);
! if (result != NULL && result[0] != NUL)
! post_balloon(beval, result, NULL);
!
! // The 'balloonexpr' evaluation may show something on the screen
! // that requires a screen update.
! if (must_redraw)
! redraw_after_callback(FALSE, FALSE);
!
recursive = FALSE;
return;
}
--- 339,345 ----
: wp->w_buffer->b_p_bexpr;
if (*bexpr != NUL)
{
! bexpr_eval(beval, bexpr, wp, lnum, col, text);
recursive = FALSE;
return;
}
*** ../vim-9.0.0600/src/blob.c 2022-09-22 17:06:56.299037474 +0100
--- src/blob.c 2022-09-27 11:40:09.701171458 +0100
***************
*** 60,88 ****
int
blob_copy(blob_T *from, typval_T *to)
{
! int ret = OK;
to->v_type = VAR_BLOB;
to->v_lock = 0;
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;
! if (len > 0)
! {
! to->vval.v_blob->bv_ga.ga_data =
! vim_memsave(from->bv_ga.ga_data, len);
! if (to->vval.v_blob->bv_ga.ga_data == NULL)
! len = 0;
! }
! to->vval.v_blob->bv_ga.ga_len = len;
! to->vval.v_blob->bv_ga.ga_maxlen = len;
}
! return ret;
}
void
--- 60,90 ----
int
blob_copy(blob_T *from, typval_T *to)
{
! int len;
to->v_type = VAR_BLOB;
to->v_lock = 0;
if (from == NULL)
{
! to->vval.v_blob = NULL;
! return OK;
! }
! if (rettv_blob_alloc(to) == FAIL)
! return FAIL;
!
! len = from->bv_ga.ga_len;
! if (len > 0)
! {
! to->vval.v_blob->bv_ga.ga_data =
! vim_memsave(from->bv_ga.ga_data, len);
! if (to->vval.v_blob->bv_ga.ga_data == NULL)
! len = 0;
}
! to->vval.v_blob->bv_ga.ga_len = len;
! to->vval.v_blob->bv_ga.ga_maxlen = len;
!
! return OK;
}
void
***************
*** 280,359 ****
return NULL;
}
! 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)
{
! // The resulting variable is a sub-blob. If the indexes
! // are out of range the result is empty.
if (n1 < 0)
{
! n1 = len + n1;
! if (n1 < 0)
! n1 = 0;
! }
! if (n2 < 0)
! n2 = len + n2;
! else if (n2 >= len)
! n2 = len - (exclusive ? 0 : 1);
! if (exclusive)
! --n2;
! if (n1 >= len || n2 < 0 || n1 > n2)
! {
clear_tv(rettv);
! rettv->v_type = VAR_BLOB;
! rettv->vval.v_blob = NULL;
}
! else
! {
! blob_T *new_blob = blob_alloc();
! long i;
! if (new_blob != NULL)
! {
! if (ga_grow(&new_blob->bv_ga, n2 - n1 + 1) == FAIL)
! {
! blob_free(new_blob);
! return FAIL;
! }
! new_blob->bv_ga.ga_len = n2 - n1 + 1;
! for (i = n1; i <= n2; i++)
! blob_set(new_blob, i - n1, blob_get(blob, i));
! clear_tv(rettv);
! rettv_blob_set(rettv, new_blob);
! }
! }
}
else
{
! // The resulting variable is a byte value.
! // If the index is too big or negative that is an error.
! if (n1 < 0)
! n1 = len + n1;
! if (n1 < len && n1 >= 0)
! {
! int v = blob_get(blob, n1);
!
! clear_tv(rettv);
! rettv->v_type = VAR_NUMBER;
! rettv->vval.v_number = v;
! }
! else
! {
! semsg(_(e_blob_index_out_of_range_nr), n1);
! return FAIL;
! }
}
return OK;
}
--- 282,389 ----
return NULL;
}
! /*
! * 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,
! long len,
varnumber_T n1,
varnumber_T n2,
int exclusive,
typval_T *rettv)
{
! if (n1 < 0)
{
! n1 = len + n1;
if (n1 < 0)
+ n1 = 0;
+ }
+ if (n2 < 0)
+ n2 = len + n2;
+ else if (n2 >= len)
+ n2 = len - (exclusive ? 0 : 1);
+ if (exclusive)
+ --n2;
+ if (n1 >= len || n2 < 0 || n1 > n2)
+ {
+ clear_tv(rettv);
+ rettv->v_type = VAR_BLOB;
+ rettv->vval.v_blob = NULL;
+ }
+ else
+ {
+ blob_T *new_blob = blob_alloc();
+ long i;
+
+ if (new_blob != NULL)
{
! if (ga_grow(&new_blob->bv_ga, n2 - n1 + 1) == FAIL)
! {
! blob_free(new_blob);
! return FAIL;
! }
! new_blob->bv_ga.ga_len = n2 - n1 + 1;
! for (i = n1; i <= n2; i++)
! blob_set(new_blob, i - n1, blob_get(blob, i));
!
clear_tv(rettv);
! rettv_blob_set(rettv, new_blob);
}
! }
! 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.
! // If the index is too big or negative that is an error.
! if (idx < 0)
! idx = len + idx;
! if (idx < len && idx >= 0)
! {
! int v = blob_get(blob, idx);
!
! clear_tv(rettv);
! rettv->v_type = VAR_NUMBER;
! rettv->vval.v_number = v;
}
else
{
! semsg(_(e_blob_index_out_of_range_nr), idx);
! 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;
}
*** ../vim-9.0.0600/src/version.c 2022-09-27 11:35:06.095028109 +0100
--- src/version.c 2022-09-27 11:41:38.576725100 +0100
***************
*** 701,702 ****
--- 701,704 ----
{ /* Add new patch number below this line */
+ /**/
+ 601,
/**/
--
hundred-and-one symptoms of being an internet addict:
190. You quickly hand over your wallet, leather jacket, and car keys
during a mugging, then proceed to beat the crap out of your
assailant when he asks for your laptop.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220927104733.D05541C0413%40moolenaar.net.