diff src/edit.c @ 18265:fe5afdc03bd2 v8.1.2127

patch 8.1.2127: the indent.c file is a bit big Commit: https://github.com/vim/vim/commit/14c01f83487d5c53192297a710eda2b8a4ab17c9 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 9 22:53:08 2019 +0200 patch 8.1.2127: the indent.c file is a bit big Problem: The indent.c file is a bit big. Solution: Move C-indent code a a new cindent.c file. Move other indent-related code to indent.c. (Yegappan Lakshmanan, closes #5031)
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Oct 2019 23:00:04 +0200
parents e0ec4cd7a865
children 9f51d0cef8da
line wrap: on
line diff
--- a/src/edit.c
+++ b/src/edit.c
@@ -37,7 +37,6 @@ static void check_spell_redraw(void);
 #endif
 static void stop_insert(pos_T *end_insert_pos, int esc, int nomove);
 static int  echeck_abbr(int);
-static void replace_join(int off);
 static void mb_replace_pop_ins(int cc);
 static void replace_flush(void);
 static void replace_do_bs(int limit_col);
@@ -76,9 +75,6 @@ static int  ins_tab(void);
 static int  ins_digraph(void);
 #endif
 static int  ins_ctrl_ey(int tc);
-#ifdef FEAT_SMARTINDENT
-static void ins_try_si(int c);
-#endif
 #if defined(FEAT_EVAL)
 static char_u *do_insert_char_pre(int c);
 #endif
@@ -97,8 +93,6 @@ static int	did_restart_edit;	/* "restart
 static int	can_cindent;		/* may do cindenting on this line */
 #endif
 
-static int	old_indent = 0;		/* for ^^D command in insert mode */
-
 #ifdef FEAT_RIGHTLEFT
 static int	revins_on;		/* reverse insert mode on */
 static int	revins_chars;		/* how much to skip after edit */
@@ -1763,248 +1757,6 @@ undisplay_dollar(void)
 }
 
 /*
- * Insert an indent (for <Tab> or CTRL-T) or delete an indent (for CTRL-D).
- * Keep the cursor on the same character.
- * type == INDENT_INC	increase indent (for CTRL-T or <Tab>)
- * type == INDENT_DEC	decrease indent (for CTRL-D)
- * type == INDENT_SET	set indent to "amount"
- * if round is TRUE, round the indent to 'shiftwidth' (only with _INC and _Dec).
- */
-    void
-change_indent(
-    int		type,
-    int		amount,
-    int		round,
-    int		replaced,	/* replaced character, put on replace stack */
-    int		call_changed_bytes)	/* call changed_bytes() */
-{
-    int		vcol;
-    int		last_vcol;
-    int		insstart_less;		/* reduction for Insstart.col */
-    int		new_cursor_col;
-    int		i;
-    char_u	*ptr;
-    int		save_p_list;
-    int		start_col;
-    colnr_T	vc;
-    colnr_T	orig_col = 0;		/* init for GCC */
-    char_u	*new_line, *orig_line = NULL;	/* init for GCC */
-
-    /* VREPLACE mode needs to know what the line was like before changing */
-    if (State & VREPLACE_FLAG)
-    {
-	orig_line = vim_strsave(ml_get_curline());  /* Deal with NULL below */
-	orig_col = curwin->w_cursor.col;
-    }
-
-    /* for the following tricks we don't want list mode */
-    save_p_list = curwin->w_p_list;
-    curwin->w_p_list = FALSE;
-    vc = getvcol_nolist(&curwin->w_cursor);
-    vcol = vc;
-
-    /*
-     * For Replace mode we need to fix the replace stack later, which is only
-     * possible when the cursor is in the indent.  Remember the number of
-     * characters before the cursor if it's possible.
-     */
-    start_col = curwin->w_cursor.col;
-
-    /* determine offset from first non-blank */
-    new_cursor_col = curwin->w_cursor.col;
-    beginline(BL_WHITE);
-    new_cursor_col -= curwin->w_cursor.col;
-
-    insstart_less = curwin->w_cursor.col;
-
-    /*
-     * If the cursor is in the indent, compute how many screen columns the
-     * cursor is to the left of the first non-blank.
-     */
-    if (new_cursor_col < 0)
-	vcol = get_indent() - vcol;
-
-    if (new_cursor_col > 0)	    /* can't fix replace stack */
-	start_col = -1;
-
-    /*
-     * Set the new indent.  The cursor will be put on the first non-blank.
-     */
-    if (type == INDENT_SET)
-	(void)set_indent(amount, call_changed_bytes ? SIN_CHANGED : 0);
-    else
-    {
-	int	save_State = State;
-
-	/* Avoid being called recursively. */
-	if (State & VREPLACE_FLAG)
-	    State = INSERT;
-	shift_line(type == INDENT_DEC, round, 1, call_changed_bytes);
-	State = save_State;
-    }
-    insstart_less -= curwin->w_cursor.col;
-
-    /*
-     * Try to put cursor on same character.
-     * If the cursor is at or after the first non-blank in the line,
-     * compute the cursor column relative to the column of the first
-     * non-blank character.
-     * If we are not in insert mode, leave the cursor on the first non-blank.
-     * If the cursor is before the first non-blank, position it relative
-     * to the first non-blank, counted in screen columns.
-     */
-    if (new_cursor_col >= 0)
-    {
-	/*
-	 * When changing the indent while the cursor is touching it, reset
-	 * Insstart_col to 0.
-	 */
-	if (new_cursor_col == 0)
-	    insstart_less = MAXCOL;
-	new_cursor_col += curwin->w_cursor.col;
-    }
-    else if (!(State & INSERT))
-	new_cursor_col = curwin->w_cursor.col;
-    else
-    {
-	/*
-	 * Compute the screen column where the cursor should be.
-	 */
-	vcol = get_indent() - vcol;
-	curwin->w_virtcol = (colnr_T)((vcol < 0) ? 0 : vcol);
-
-	/*
-	 * Advance the cursor until we reach the right screen column.
-	 */
-	vcol = last_vcol = 0;
-	new_cursor_col = -1;
-	ptr = ml_get_curline();
-	while (vcol <= (int)curwin->w_virtcol)
-	{
-	    last_vcol = vcol;
-	    if (has_mbyte && new_cursor_col >= 0)
-		new_cursor_col += (*mb_ptr2len)(ptr + new_cursor_col);
-	    else
-		++new_cursor_col;
-	    vcol += lbr_chartabsize(ptr, ptr + new_cursor_col, (colnr_T)vcol);
-	}
-	vcol = last_vcol;
-
-	/*
-	 * May need to insert spaces to be able to position the cursor on
-	 * the right screen column.
-	 */
-	if (vcol != (int)curwin->w_virtcol)
-	{
-	    curwin->w_cursor.col = (colnr_T)new_cursor_col;
-	    i = (int)curwin->w_virtcol - vcol;
-	    ptr = alloc(i + 1);
-	    if (ptr != NULL)
-	    {
-		new_cursor_col += i;
-		ptr[i] = NUL;
-		while (--i >= 0)
-		    ptr[i] = ' ';
-		ins_str(ptr);
-		vim_free(ptr);
-	    }
-	}
-
-	/*
-	 * When changing the indent while the cursor is in it, reset
-	 * Insstart_col to 0.
-	 */
-	insstart_less = MAXCOL;
-    }
-
-    curwin->w_p_list = save_p_list;
-
-    if (new_cursor_col <= 0)
-	curwin->w_cursor.col = 0;
-    else
-	curwin->w_cursor.col = (colnr_T)new_cursor_col;
-    curwin->w_set_curswant = TRUE;
-    changed_cline_bef_curs();
-
-    /*
-     * May have to adjust the start of the insert.
-     */
-    if (State & INSERT)
-    {
-	if (curwin->w_cursor.lnum == Insstart.lnum && Insstart.col != 0)
-	{
-	    if ((int)Insstart.col <= insstart_less)
-		Insstart.col = 0;
-	    else
-		Insstart.col -= insstart_less;
-	}
-	if ((int)ai_col <= insstart_less)
-	    ai_col = 0;
-	else
-	    ai_col -= insstart_less;
-    }
-
-    /*
-     * For REPLACE mode, may have to fix the replace stack, if it's possible.
-     * If the number of characters before the cursor decreased, need to pop a
-     * few characters from the replace stack.
-     * If the number of characters before the cursor increased, need to push a
-     * few NULs onto the replace stack.
-     */
-    if (REPLACE_NORMAL(State) && start_col >= 0)
-    {
-	while (start_col > (int)curwin->w_cursor.col)
-	{
-	    replace_join(0);	    /* remove a NUL from the replace stack */
-	    --start_col;
-	}
-	while (start_col < (int)curwin->w_cursor.col || replaced)
-	{
-	    replace_push(NUL);
-	    if (replaced)
-	    {
-		replace_push(replaced);
-		replaced = NUL;
-	    }
-	    ++start_col;
-	}
-    }
-
-    /*
-     * For VREPLACE mode, we also have to fix the replace stack.  In this case
-     * it is always possible because we backspace over the whole line and then
-     * put it back again the way we wanted it.
-     */
-    if (State & VREPLACE_FLAG)
-    {
-	/* If orig_line didn't allocate, just return.  At least we did the job,
-	 * even if you can't backspace. */
-	if (orig_line == NULL)
-	    return;
-
-	/* Save new line */
-	new_line = vim_strsave(ml_get_curline());
-	if (new_line == NULL)
-	    return;
-
-	/* We only put back the new line up to the cursor */
-	new_line[curwin->w_cursor.col] = NUL;
-
-	/* Put back original line */
-	ml_replace(curwin->w_cursor.lnum, orig_line, FALSE);
-	curwin->w_cursor.col = orig_col;
-
-	/* Backspace from cursor to start of line */
-	backspace_until_column(0);
-
-	/* Insert new stuff into line again */
-	ins_bytes(new_line);
-
-	vim_free(new_line);
-    }
-}
-
-/*
  * Truncate the space at the end of a line.  This is to be used only in an
  * insert mode.  It handles fixing the replace stack for REPLACE and VREPLACE
  * modes.
@@ -3840,7 +3592,7 @@ replace_pop(void)
  * Join the top two items on the replace stack.  This removes to "off"'th NUL
  * encountered.
  */
-    static void
+    void
 replace_join(
     int	    off)	/* offset for which NUL to remove */
 {
@@ -6070,97 +5822,6 @@ ins_ctrl_ey(int tc)
     return c;
 }
 
-#ifdef FEAT_SMARTINDENT
-/*
- * Try to do some very smart auto-indenting.
- * Used when inserting a "normal" character.
- */
-    static void
-ins_try_si(int c)
-{
-    pos_T	*pos, old_pos;
-    char_u	*ptr;
-    int		i;
-    int		temp;
-
-    /*
-     * do some very smart indenting when entering '{' or '}'
-     */
-    if (((did_si || can_si_back) && c == '{') || (can_si && c == '}'))
-    {
-	/*
-	 * for '}' set indent equal to indent of line containing matching '{'
-	 */
-	if (c == '}' && (pos = findmatch(NULL, '{')) != NULL)
-	{
-	    old_pos = curwin->w_cursor;
-	    /*
-	     * If the matching '{' has a ')' immediately before it (ignoring
-	     * white-space), then line up with the start of the line
-	     * containing the matching '(' if there is one.  This handles the
-	     * case where an "if (..\n..) {" statement continues over multiple
-	     * lines -- webb
-	     */
-	    ptr = ml_get(pos->lnum);
-	    i = pos->col;
-	    if (i > 0)		/* skip blanks before '{' */
-		while (--i > 0 && VIM_ISWHITE(ptr[i]))
-		    ;
-	    curwin->w_cursor.lnum = pos->lnum;
-	    curwin->w_cursor.col = i;
-	    if (ptr[i] == ')' && (pos = findmatch(NULL, '(')) != NULL)
-		curwin->w_cursor = *pos;
-	    i = get_indent();
-	    curwin->w_cursor = old_pos;
-	    if (State & VREPLACE_FLAG)
-		change_indent(INDENT_SET, i, FALSE, NUL, TRUE);
-	    else
-		(void)set_indent(i, SIN_CHANGED);
-	}
-	else if (curwin->w_cursor.col > 0)
-	{
-	    /*
-	     * when inserting '{' after "O" reduce indent, but not
-	     * more than indent of previous line
-	     */
-	    temp = TRUE;
-	    if (c == '{' && can_si_back && curwin->w_cursor.lnum > 1)
-	    {
-		old_pos = curwin->w_cursor;
-		i = get_indent();
-		while (curwin->w_cursor.lnum > 1)
-		{
-		    ptr = skipwhite(ml_get(--(curwin->w_cursor.lnum)));
-
-		    /* ignore empty lines and lines starting with '#'. */
-		    if (*ptr != '#' && *ptr != NUL)
-			break;
-		}
-		if (get_indent() >= i)
-		    temp = FALSE;
-		curwin->w_cursor = old_pos;
-	    }
-	    if (temp)
-		shift_line(TRUE, FALSE, 1, TRUE);
-	}
-    }
-
-    /*
-     * set indent of '#' always to 0
-     */
-    if (curwin->w_cursor.col > 0 && can_si && c == '#')
-    {
-	/* remember current indent for next line */
-	old_indent = get_indent();
-	(void)set_indent(0, SIN_CHANGED);
-    }
-
-    /* Adjust ai_col, the char at this position can be deleted. */
-    if (ai_col > curwin->w_cursor.col)
-	ai_col = curwin->w_cursor.col;
-}
-#endif
-
 /*
  * Get the value that w_virtcol would have when 'list' is off.
  * Unless 'cpo' contains the 'L' flag.