// This function handles deadly signals. // It tries to preserve any swap files and exit properly. // (partly from Elvis). // NOTE: Avoid unsafe functions, such as allocating memory, they can result in // a deadlock. static void deadly_signal(int signum) { // Set the v:dying variable. set_vim_var_nr(VV_DYING, 1); snprintf((char *)IObuff, sizeof(IObuff), "Vim: Caught deadly signal '%s'\n", signal_name(signum)); // Preserve files and exit. preserve_exit(); }
// This function handles deadly signals. // It tries to preserve any swap files and exit properly. // (partly from Elvis). // NOTE: Avoid unsafe functions, such as allocating memory, they can result in // a deadlock. static void deadly_signal(int signum) { // Set the v:dying variable. set_vim_var_nr(VV_DYING, 1); sprintf((char *)IObuff, "Vim: Caught deadly signal '%s'\n", signal_name(signum)); // Preserve files and exit. This sets the really_exiting flag to prevent // calling free(). preserve_exit(); }
// Get indent level from 'indentexpr'. int get_expr_indent(void) { int indent; pos_T save_pos; colnr_T save_curswant; int save_set_curswant; int save_State; int use_sandbox = was_set_insecurely((char_u *)"indentexpr", OPT_LOCAL); // Save and restore cursor position and curswant, in case it was changed // * via :normal commands. save_pos = curwin->w_cursor; save_curswant = curwin->w_curswant; save_set_curswant = curwin->w_set_curswant; set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum); if (use_sandbox) { sandbox++; } textlock++; indent = eval_to_number(curbuf->b_p_inde); if (use_sandbox) { sandbox--; } textlock--; // Restore the cursor position so that 'indentexpr' doesn't need to. // Pretend to be in Insert mode, allow cursor past end of line for "o" // command. save_State = State; State = INSERT; curwin->w_cursor = save_pos; curwin->w_curswant = save_curswant; curwin->w_set_curswant = save_set_curswant; check_cursor(); State = save_State; // If there is an error, just keep the current indent. if (indent < 0) { indent = get_indent(); } return indent; }
/* * 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; 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; # ifdef FEAT_WINDOWS win_T *cw; # endif #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 (!p_beval || balloonEval == NULL || msg_scrolled > 0) 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(balloonEval, 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) { # ifdef FEAT_WINDOWS /* Convert window pointer to number. */ for (cw = firstwin; cw != wp; cw = cw->w_next) ++winnr; # endif 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; vim_free(result); result = eval_to_string(bexpr, NULL, TRUE); /* Remove one trailing newline, it is added when the result was a * list and it's hardly every 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; set_vim_var_string(VV_BEVAL_TEXT, NULL, -1); if (result != NULL && result[0] != NUL) { gui_mch_post_balloon(beval, result); recursive = FALSE; return; } } } #endif #ifdef FEAT_NETBEANS_INTG if (bevalServers & BEVAL_NETBEANS) netbeans_beval_cb(beval, state); #endif #ifdef FEAT_SUN_WORKSHOP if (bevalServers & BEVAL_WORKSHOP) workshop_beval_cb(beval, state); #endif recursive = FALSE; }