Example #1
0
/*
 * Return appropriate space number for breakindent, taking influencing
 * parameters into account. Window must be specified, since it is not
 * necessarily always the current one.
 */
int get_breakindent_win(win_T *wp, char_u *line) {
  static int prev_indent = 0;  /* cached indent value */
  static int prev_ts     = 0L; /* cached tabstop value */
  static char_u *prev_line = NULL; /* cached pointer to line */
  int bri = 0;
  /* window width minus window margin space, i.e. what rests for text */
  const int eff_wwidth = wp->w_width
    - ((wp->w_p_nu || wp->w_p_rnu)
        && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
        ? number_width(wp) + 1 : 0);

  /* used cached indent, unless pointer or 'tabstop' changed */
  if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts)
  {
    prev_line = line;
    prev_ts = wp->w_buffer->b_p_ts;
    prev_indent = get_indent_str(line,
            (int)wp->w_buffer->b_p_ts, wp->w_p_list);
  }
  bri = prev_indent + wp->w_p_brishift;

  /* indent minus the length of the showbreak string */
  if (wp->w_p_brisbr)
    bri -= vim_strsize(p_sbr);

  /* Add offset for number column, if 'n' is in 'cpoptions' */
  bri += win_col_off2(wp);

  /* never indent past left window margin */
  if (bri < 0)
    bri = 0;
  /* always leave at least bri_min characters on the left,
   * if text width is sufficient */
  else if (bri > eff_wwidth - wp->w_p_brimin)
    bri = (eff_wwidth - wp->w_p_brimin < 0)
      ? 0 : eff_wwidth - wp->w_p_brimin;

  return bri;
}
Example #2
0
// Count the size (in window cells) of the indent in line "lnum" of buffer
// "buf".
int get_indent_buf(buf_T *buf, linenr_T lnum)
{
  return get_indent_str(ml_get_buf(buf, lnum, false), (int)buf->b_p_ts);
}
Example #3
0
// Count the size (in window cells) of the indent in line "lnum".
int get_indent_lnum(linenr_T lnum)
{
  return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts);
}
Example #4
0
// Count the size (in window cells) of the indent in the current line.
int get_indent(void)
{
  return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts);
}
Example #5
0
// Count the size (in window cells) of the indent in the current line.
int get_indent(void)
{
  return get_indent_str(get_cursor_line_ptr(), (int)curbuf->b_p_ts, false);
}