Mercurial > vim
comparison src/fold.c @ 31600:f1d5ad2b978e v9.0.1132
patch 9.0.1132: code is indented more than needed
Commit: https://github.com/vim/vim/commit/dc4daa3a3915fba11ac87d27977240d9a5e0d47d
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Mon Jan 2 16:54:53 2023 +0000
patch 9.0.1132: code is indented more than needed
Problem: Code is indented more than needed.
Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan,
closes #11769)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 02 Jan 2023 18:00:04 +0100 |
parents | 37aa9fd2ed72 |
children | e5ee2ffd826a |
comparison
equal
deleted
inserted
replaced
31599:7eb3096f4493 | 31600:f1d5ad2b978e |
---|---|
642 i = 0; | 642 i = 0; |
643 else | 643 else |
644 i = (int)(fp - (fold_T *)gap->ga_data); | 644 i = (int)(fp - (fold_T *)gap->ga_data); |
645 } | 645 } |
646 | 646 |
647 if (ga_grow(gap, 1) == OK) | 647 if (ga_grow(gap, 1) != OK) |
648 { | 648 return; |
649 fp = (fold_T *)gap->ga_data + i; | 649 |
650 ga_init2(&fold_ga, sizeof(fold_T), 10); | 650 fp = (fold_T *)gap->ga_data + i; |
651 | 651 ga_init2(&fold_ga, sizeof(fold_T), 10); |
652 // Count number of folds that will be contained in the new fold. | 652 |
653 for (cont = 0; i + cont < gap->ga_len; ++cont) | 653 // Count number of folds that will be contained in the new fold. |
654 if (fp[cont].fd_top > end_rel) | 654 for (cont = 0; i + cont < gap->ga_len; ++cont) |
655 break; | 655 if (fp[cont].fd_top > end_rel) |
656 if (cont > 0 && ga_grow(&fold_ga, cont) == OK) | 656 break; |
657 { | 657 if (cont > 0 && ga_grow(&fold_ga, cont) == OK) |
658 // If the first fold starts before the new fold, let the new fold | 658 { |
659 // start there. Otherwise the existing fold would change. | 659 // If the first fold starts before the new fold, let the new fold |
660 if (start_rel > fp->fd_top) | 660 // start there. Otherwise the existing fold would change. |
661 start_rel = fp->fd_top; | 661 if (start_rel > fp->fd_top) |
662 | 662 start_rel = fp->fd_top; |
663 // When last contained fold isn't completely contained, adjust end | 663 |
664 // of new fold. | 664 // When last contained fold isn't completely contained, adjust end |
665 if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) | 665 // of new fold. |
666 end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; | 666 if (end_rel < fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1) |
667 // Move contained folds to inside new fold. | 667 end_rel = fp[cont - 1].fd_top + fp[cont - 1].fd_len - 1; |
668 mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); | 668 // Move contained folds to inside new fold. |
669 fold_ga.ga_len += cont; | 669 mch_memmove(fold_ga.ga_data, fp, sizeof(fold_T) * cont); |
670 i += cont; | 670 fold_ga.ga_len += cont; |
671 | 671 i += cont; |
672 // Adjust line numbers in contained folds to be relative to the | 672 |
673 // new fold. | 673 // Adjust line numbers in contained folds to be relative to the |
674 for (j = 0; j < cont; ++j) | 674 // new fold. |
675 ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; | 675 for (j = 0; j < cont; ++j) |
676 } | 676 ((fold_T *)fold_ga.ga_data)[j].fd_top -= start_rel; |
677 // Move remaining entries to after the new fold. | 677 } |
678 if (i < gap->ga_len) | 678 // Move remaining entries to after the new fold. |
679 mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, | 679 if (i < gap->ga_len) |
680 sizeof(fold_T) * (gap->ga_len - i)); | 680 mch_memmove(fp + 1, (fold_T *)gap->ga_data + i, |
681 gap->ga_len = gap->ga_len + 1 - cont; | 681 sizeof(fold_T) * (gap->ga_len - i)); |
682 | 682 gap->ga_len = gap->ga_len + 1 - cont; |
683 // insert new fold | 683 |
684 fp->fd_nested = fold_ga; | 684 // insert new fold |
685 fp->fd_top = start_rel; | 685 fp->fd_nested = fold_ga; |
686 fp->fd_len = end_rel - start_rel + 1; | 686 fp->fd_top = start_rel; |
687 | 687 fp->fd_len = end_rel - start_rel + 1; |
688 // We want the new fold to be closed. If it would remain open because | 688 |
689 // of using 'foldlevel', need to adjust fd_flags of containing folds. | 689 // We want the new fold to be closed. If it would remain open because |
690 if (use_level && !closed && level < curwin->w_p_fdl) | 690 // of using 'foldlevel', need to adjust fd_flags of containing folds. |
691 closeFold(start, 1L); | 691 if (use_level && !closed && level < curwin->w_p_fdl) |
692 if (!use_level) | 692 closeFold(start, 1L); |
693 curwin->w_fold_manual = TRUE; | 693 if (!use_level) |
694 fp->fd_flags = FD_CLOSED; | 694 curwin->w_fold_manual = TRUE; |
695 fp->fd_small = MAYBE; | 695 fp->fd_flags = FD_CLOSED; |
696 | 696 fp->fd_small = MAYBE; |
697 // redraw | 697 |
698 changed_window_setting(); | 698 // redraw |
699 } | 699 changed_window_setting(); |
700 } | 700 } |
701 | 701 |
702 // deleteFold() {{{2 | 702 // deleteFold() {{{2 |
703 /* | 703 /* |
704 * Delete a fold at line "start" in the current window. | 704 * Delete a fold at line "start" in the current window. |
1717 linenr_T lnum_off) // offset for fp->fd_top | 1717 linenr_T lnum_off) // offset for fp->fd_top |
1718 { | 1718 { |
1719 int count; | 1719 int count; |
1720 int n; | 1720 int n; |
1721 | 1721 |
1722 if (fp->fd_small == MAYBE) | 1722 if (fp->fd_small != MAYBE) |
1723 { | 1723 return; |
1724 // Mark any nested folds to maybe-small | 1724 |
1725 setSmallMaybe(&fp->fd_nested); | 1725 // Mark any nested folds to maybe-small |
1726 | 1726 setSmallMaybe(&fp->fd_nested); |
1727 if (fp->fd_len > curwin->w_p_fml) | 1727 |
1728 fp->fd_small = FALSE; | 1728 if (fp->fd_len > curwin->w_p_fml) |
1729 else | 1729 fp->fd_small = FALSE; |
1730 { | 1730 else |
1731 count = 0; | 1731 { |
1732 for (n = 0; n < fp->fd_len; ++n) | 1732 count = 0; |
1733 { | 1733 for (n = 0; n < fp->fd_len; ++n) |
1734 count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); | 1734 { |
1735 if (count > curwin->w_p_fml) | 1735 count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); |
1736 { | 1736 if (count > curwin->w_p_fml) |
1737 fp->fd_small = FALSE; | 1737 { |
1738 return; | 1738 fp->fd_small = FALSE; |
1739 } | 1739 return; |
1740 } | 1740 } |
1741 fp->fd_small = TRUE; | 1741 } |
1742 } | 1742 fp->fd_small = TRUE; |
1743 } | 1743 } |
1744 } | 1744 } |
1745 | 1745 |
1746 // setSmallMaybe() {{{2 | 1746 // setSmallMaybe() {{{2 |
1747 /* | 1747 /* |
1797 | 1797 |
1798 // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end | 1798 // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end |
1799 line = ml_get(lnum); | 1799 line = ml_get(lnum); |
1800 line_len = (int)STRLEN(line); | 1800 line_len = (int)STRLEN(line); |
1801 | 1801 |
1802 if (u_save(lnum - 1, lnum + 1) == OK) | 1802 if (u_save(lnum - 1, lnum + 1) != OK) |
1803 { | 1803 return; |
1804 // Check if the line ends with an unclosed comment | 1804 |
1805 (void)skip_comment(line, FALSE, FALSE, &line_is_comment); | 1805 // Check if the line ends with an unclosed comment |
1806 newline = alloc(line_len + markerlen + STRLEN(cms) + 1); | 1806 (void)skip_comment(line, FALSE, FALSE, &line_is_comment); |
1807 if (newline == NULL) | 1807 newline = alloc(line_len + markerlen + STRLEN(cms) + 1); |
1808 return; | 1808 if (newline == NULL) |
1809 STRCPY(newline, line); | 1809 return; |
1810 // Append the marker to the end of the line | 1810 STRCPY(newline, line); |
1811 if (p == NULL || line_is_comment) | 1811 // Append the marker to the end of the line |
1812 vim_strncpy(newline + line_len, marker, markerlen); | 1812 if (p == NULL || line_is_comment) |
1813 else | 1813 vim_strncpy(newline + line_len, marker, markerlen); |
1814 { | 1814 else |
1815 STRCPY(newline + line_len, cms); | 1815 { |
1816 STRNCPY(newline + line_len + (p - cms), marker, markerlen); | 1816 STRCPY(newline + line_len, cms); |
1817 STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); | 1817 STRNCPY(newline + line_len + (p - cms), marker, markerlen); |
1818 } | 1818 STRCPY(newline + line_len + (p - cms) + markerlen, p + 2); |
1819 | 1819 } |
1820 ml_replace(lnum, newline, FALSE); | 1820 |
1821 } | 1821 ml_replace(lnum, newline, FALSE); |
1822 } | 1822 } |
1823 | 1823 |
1824 // deleteFoldMarkers() {{{2 | 1824 // deleteFoldMarkers() {{{2 |
1825 /* | 1825 /* |
1826 * Delete the markers for a fold, causing it to be deleted. | 1826 * Delete the markers for a fold, causing it to be deleted. |