Patch 8.2.4792

16 views
Skip to first unread message

Bram Moolenaar

unread,
Apr 19, 2022, 1:58:57 PM4/19/22
to vim...@googlegroups.com

Patch 8.2.4792
Problem: Indent operator creates an undo entry for every line.
Solution: Create one undo entry for all lines. (closes #10227)
Files: src/indent.c, src/testdir/test_indent.vim


*** ../vim-8.2.4791/src/indent.c 2022-02-21 19:36:08.143004133 +0000
--- src/indent.c 2022-04-19 18:26:44.135894727 +0100
***************
*** 1060,1099 ****
return;
}

! for (i = oap->line_count; --i >= 0 && !got_int; )
! {
! // it's a slow thing to do, so give feedback so there's no worry that
! // the computer's just hung.

! if (i > 1
! && (i % 50 == 0 || i == oap->line_count - 1)
! && oap->line_count > p_report)
! smsg(_("%ld lines to indent... "), i);

! // Be vi-compatible: For lisp indenting the first line is not
! // indented, unless there is only one line.
# ifdef FEAT_LISP
! if (i != oap->line_count - 1 || oap->line_count == 1
! || how != get_lisp_indent)
# endif
- {
- l = skipwhite(ml_get_curline());
- if (*l == NUL) // empty or blank line
- amount = 0;
- else
- amount = how(); // get the indent for this line
-
- if (amount >= 0 && set_indent(amount, SIN_UNDO))
{
! // did change the indent, call changed_lines() later
! if (first_changed == 0)
! first_changed = curwin->w_cursor.lnum;
! last_changed = curwin->w_cursor.lnum;
}
}
- ++curwin->w_cursor.lnum;
- curwin->w_cursor.col = 0; // make sure it's valid
- }

// put cursor on first non-blank of indented line
curwin->w_cursor.lnum = start_lnum;
--- 1060,1103 ----
return;
}

! // Save for undo. Do this once for all lines, much faster than doing this
! // for each line separately, especially when undoing.
! if (u_savecommon(start_lnum - 1, start_lnum + oap->line_count,
! start_lnum + oap->line_count, FALSE) == OK)
! for (i = oap->line_count; --i >= 0 && !got_int; )
! {
! // it's a slow thing to do, so give feedback so there's no worry
! // that the computer's just hung.

! if (i > 1
! && (i % 50 == 0 || i == oap->line_count - 1)
! && oap->line_count > p_report)
! smsg(_("%ld lines to indent... "), i);

! // Be vi-compatible: For lisp indenting the first line is not
! // indented, unless there is only one line.
# ifdef FEAT_LISP
! if (i != oap->line_count - 1 || oap->line_count == 1
! || how != get_lisp_indent)
# endif
{
! l = skipwhite(ml_get_curline());
! if (*l == NUL) // empty or blank line
! amount = 0;
! else
! amount = how(); // get the indent for this line
!
! if (amount >= 0 && set_indent(amount, 0))
! {
! // did change the indent, call changed_lines() later
! if (first_changed == 0)
! first_changed = curwin->w_cursor.lnum;
! last_changed = curwin->w_cursor.lnum;
! }
}
+ ++curwin->w_cursor.lnum;
+ curwin->w_cursor.col = 0; // make sure it's valid
}

// put cursor on first non-blank of indented line
curwin->w_cursor.lnum = start_lnum;
*** ../vim-8.2.4791/src/testdir/test_indent.vim 2021-12-06 19:50:57.706620019 +0000
--- src/testdir/test_indent.vim 2022-04-19 18:24:41.551926208 +0100
***************
*** 59,64 ****
--- 59,87 ----
close!
endfunc

+ " Test indent operator creating one undo entry
+ func Test_indent_operator_undo()
+ enew
+ call setline(1, range(12)->map('"\t" .. v:val'))
+ func FoldExpr()
+ let g:foldcount += 1
+ return '='
+ endfunc
+ set foldmethod=expr foldexpr=FoldExpr()
+ let g:foldcount = 0
+ redraw
+ call assert_equal(12, g:foldcount)
+ normal gg=G
+ call assert_equal(24, g:foldcount)
+ undo
+ call assert_equal(38, g:foldcount)
+
+ bwipe!
+ set foldmethod& foldexpr=
+ delfunc FoldExpr
+ unlet g:foldcount
+ endfunc
+
" Test for shifting a line with a preprocessor directive ('#')
func Test_preproc_indent()
new
*** ../vim-8.2.4791/src/version.c 2022-04-19 16:24:08.607559706 +0100
--- src/version.c 2022-04-19 18:15:21.612131848 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4792,
/**/

--
How To Keep A Healthy Level Of Insanity:
12. Sing along at the opera.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

John Marriott

unread,
Apr 19, 2022, 4:07:20 PM4/19/22
to vim...@googlegroups.com
After this patch, mingw (gcc 11.2.0) throws this warning:
<snip>
gcc -c -I. -Iproto -DWIN32 -DWINVER=0x0603 -D_WIN32_WINNT=0x0603
-DHAVE_PATHDEF -DFEAT_NORMAL -DHAVE_STDINT_H -D__USE_MINGW_ANSI_STDIO
-pipe -march=native -Wall -O3 -fomit-frame-pointer -freg-struct-return
-fpie -fPIE -DFEAT_GUI_MSWIN -DFEAT_CLIPBOARD indent.c -o
gobjnative/indent.o
indent.c: In function 'op_reindent':
indent.c:1118:34: warning: 'i' may be used uninitialized in this
function [-Wmaybe-uninitialized]
 1118 |         i = oap->line_count - (i + 1);
      |                               ~~~^~~~
</snip>

The attached patch tries to fix it.

Cheers
John
indent.c.8.2.4792.patch

Tony Mechelynck

unread,
Apr 19, 2022, 5:49:46 PM4/19/22
to vim_dev
I get the same warning on Linux in gcc 11.2.1 in Normal, Big and Huge builds.
>
> The attached patch tries to fix it.
>
> Cheers
> John

Best regards,
Tony.

Bram Moolenaar

unread,
Apr 20, 2022, 5:24:20 AM4/20/22
to vim...@googlegroups.com, John Marriott
I see, thanks for the patch.

--
How To Keep A Healthy Level Of Insanity:
15. Five days in advance, tell your friends you can't attend their
party because you're not in the mood.
Reply all
Reply to author
Forward
0 new messages