To: vim_dev@googlegroups.com Subject: Patch 9.0.1098 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1098 Problem: Code uses too much indent. Solution: Use an early return. (Yegappan Lakshmanan, closes #11747) Files: src/cmdhist.c, src/debugger.c, src/diff.c, src/digraph.c, src/drawline.c *** ../vim-9.0.1097/src/cmdhist.c 2022-11-14 14:36:37.827695538 +0000 --- src/cmdhist.c 2022-12-26 12:41:45.861700055 +0000 *************** *** 460,503 **** int last; int found = FALSE; ! regmatch.regprog = NULL; regmatch.rm_ic = FALSE; // always match case ! if (hislen != 0 ! && histype >= 0 ! && histype < HIST_COUNT ! && *str != NUL ! && (idx = hisidx[histype]) >= 0 ! && (regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING)) ! != NULL) { ! i = last = idx; ! do { ! hisptr = &history[histype][i]; ! if (hisptr->hisstr == NULL) ! break; ! if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) { ! found = TRUE; ! vim_free(hisptr->hisstr); clear_hist_entry(hisptr); } ! else ! { ! if (i != last) ! { ! history[histype][last] = *hisptr; ! clear_hist_entry(hisptr); ! } ! if (--last < 0) ! last += hislen; ! } ! if (--i < 0) ! i += hislen; ! } while (i != idx); ! if (history[histype][idx].hisstr == NULL) ! hisidx[histype] = -1; ! } vim_regfree(regmatch.regprog); return found; } --- 460,505 ---- int last; int found = FALSE; ! if (hislen == 0 || histype < 0 || histype >= HIST_COUNT || *str == NUL ! || hisidx[histype] < 0) ! return FALSE; ! ! idx = hisidx[histype]; ! regmatch.regprog = vim_regcomp(str, RE_MAGIC + RE_STRING); ! if (regmatch.regprog == NULL) ! return FALSE; ! regmatch.rm_ic = FALSE; // always match case ! ! i = last = idx; ! do { ! hisptr = &history[histype][i]; ! if (hisptr->hisstr == NULL) ! break; ! if (vim_regexec(®match, hisptr->hisstr, (colnr_T)0)) ! { ! found = TRUE; ! vim_free(hisptr->hisstr); ! clear_hist_entry(hisptr); ! } ! else { ! if (i != last) { ! history[histype][last] = *hisptr; clear_hist_entry(hisptr); } ! if (--last < 0) ! last += hislen; ! } ! if (--i < 0) ! i += hislen; ! } while (i != idx); ! ! if (history[histype][idx].hisstr == NULL) ! hisidx[histype] = -1; ! vim_regfree(regmatch.regprog); return found; } *** ../vim-9.0.1097/src/debugger.c 2022-09-20 13:51:21.355306835 +0100 --- src/debugger.c 2022-12-26 12:41:45.861700055 +0000 *************** *** 682,725 **** gap = &prof_ga; #endif ! if (dbg_parsearg(eap->arg, gap) == OK) ! { ! bp = &DEBUGGY(gap, gap->ga_len); ! bp->dbg_forceit = eap->forceit; ! if (bp->dbg_type != DBG_EXPR) { ! pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); ! if (pat != NULL) ! { ! bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); ! vim_free(pat); ! } ! if (pat == NULL || bp->dbg_prog == NULL) ! vim_free(bp->dbg_name); ! else ! { ! if (bp->dbg_lnum == 0) // default line number is 1 ! bp->dbg_lnum = 1; ! #ifdef FEAT_PROFILE ! if (eap->cmdidx != CMD_profile) ! #endif ! { ! DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; ! ++debug_tick; ! } ! ++gap->ga_len; ! } } else { ! // DBG_EXPR ! DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp; ! ++debug_tick; ! if (gap == &dbg_breakp) ! has_expr_breakpoint = TRUE; } } } /* --- 682,725 ---- gap = &prof_ga; #endif ! if (dbg_parsearg(eap->arg, gap) != OK) ! return; ! bp = &DEBUGGY(gap, gap->ga_len); ! bp->dbg_forceit = eap->forceit; ! ! if (bp->dbg_type != DBG_EXPR) ! { ! pat = file_pat_to_reg_pat(bp->dbg_name, NULL, NULL, FALSE); ! if (pat != NULL) { ! bp->dbg_prog = vim_regcomp(pat, RE_MAGIC + RE_STRING); ! vim_free(pat); } + if (pat == NULL || bp->dbg_prog == NULL) + vim_free(bp->dbg_name); else { ! if (bp->dbg_lnum == 0) // default line number is 1 ! bp->dbg_lnum = 1; ! #ifdef FEAT_PROFILE ! if (eap->cmdidx != CMD_profile) ! #endif ! { ! DEBUGGY(gap, gap->ga_len).dbg_nr = ++last_breakp; ! ++debug_tick; ! } ! ++gap->ga_len; } } + else + { + // DBG_EXPR + DEBUGGY(gap, gap->ga_len++).dbg_nr = ++last_breakp; + ++debug_tick; + if (gap == &dbg_breakp) + has_expr_breakpoint = TRUE; + } } /* *************** *** 822,857 **** } if (todel < 0) semsg(_(e_breakpoint_not_found_str), eap->arg); ! else { ! while (gap->ga_len > 0) ! { ! vim_free(DEBUGGY(gap, todel).dbg_name); #ifdef FEAT_EVAL ! if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR ! && DEBUGGY(gap, todel).dbg_val != NULL) ! free_tv(DEBUGGY(gap, todel).dbg_val); #endif ! vim_regfree(DEBUGGY(gap, todel).dbg_prog); ! --gap->ga_len; ! if (todel < gap->ga_len) ! mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), ! (gap->ga_len - todel) * sizeof(struct debuggy)); #ifdef FEAT_PROFILE ! if (eap->cmdidx == CMD_breakdel) #endif ! ++debug_tick; ! if (!del_all) ! break; ! } ! ! // If all breakpoints were removed clear the array. ! if (gap->ga_len == 0) ! ga_clear(gap); ! if (gap == &dbg_breakp) ! update_has_expr_breakpoint(); } } /* --- 822,858 ---- } if (todel < 0) + { semsg(_(e_breakpoint_not_found_str), eap->arg); ! return; ! } ! ! while (gap->ga_len > 0) { ! vim_free(DEBUGGY(gap, todel).dbg_name); #ifdef FEAT_EVAL ! if (DEBUGGY(gap, todel).dbg_type == DBG_EXPR ! && DEBUGGY(gap, todel).dbg_val != NULL) ! free_tv(DEBUGGY(gap, todel).dbg_val); #endif ! vim_regfree(DEBUGGY(gap, todel).dbg_prog); ! --gap->ga_len; ! if (todel < gap->ga_len) ! mch_memmove(&DEBUGGY(gap, todel), &DEBUGGY(gap, todel + 1), ! (gap->ga_len - todel) * sizeof(struct debuggy)); #ifdef FEAT_PROFILE ! if (eap->cmdidx == CMD_breakdel) #endif ! ++debug_tick; ! if (!del_all) ! break; } + + // If all breakpoints were removed clear the array. + if (gap->ga_len == 0) + ga_clear(gap); + if (gap == &dbg_breakp) + update_has_expr_breakpoint(); } /* *************** *** 864,886 **** int i; if (dbg_breakp.ga_len == 0) msg(_("No breakpoints defined")); ! else ! for (i = 0; i < dbg_breakp.ga_len; ++i) ! { ! bp = &BREAKP(i); ! if (bp->dbg_type == DBG_FILE) ! home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE); ! if (bp->dbg_type != DBG_EXPR) ! smsg(_("%3d %s %s line %ld"), bp->dbg_nr, bp->dbg_type == DBG_FUNC ? "func" : "file", bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, (long)bp->dbg_lnum); ! else ! smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); ! } } /* --- 865,890 ---- int i; if (dbg_breakp.ga_len == 0) + { msg(_("No breakpoints defined")); ! return; ! } ! ! for (i = 0; i < dbg_breakp.ga_len; ++i) ! { ! bp = &BREAKP(i); ! if (bp->dbg_type == DBG_FILE) ! home_replace(NULL, bp->dbg_name, NameBuff, MAXPATHL, TRUE); ! if (bp->dbg_type != DBG_EXPR) ! smsg(_("%3d %s %s line %ld"), bp->dbg_nr, bp->dbg_type == DBG_FUNC ? "func" : "file", bp->dbg_type == DBG_FUNC ? bp->dbg_name : NameBuff, (long)bp->dbg_lnum); ! else ! smsg(_("%3d expr %s"), bp->dbg_nr, bp->dbg_name); ! } } /* *** ../vim-9.0.1097/src/diff.c 2022-11-28 18:51:38.963571609 +0000 --- src/diff.c 2022-12-26 12:41:45.861700055 +0000 *************** *** 1180,1223 **** #endif // Use xdiff for generating the diff. if (dio->dio_internal) - { return diff_file_internal(dio); ! } ! else ! { ! len = STRLEN(tmp_orig) + STRLEN(tmp_new) ! + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; ! cmd = alloc(len); ! if (cmd == NULL) ! return FAIL; ! ! // We don't want $DIFF_OPTIONS to get in the way. ! if (getenv("DIFF_OPTIONS")) ! vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); ! ! // Build the diff command and execute it. Always use -a, binary ! // differences are of no use. Ignore errors, diff returns ! // non-zero when differences have been found. ! vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s", ! diff_a_works == FALSE ? "" : "-a ", #if defined(MSWIN) ! diff_bin_works == TRUE ? "--binary " : "", #else ! "", #endif ! (diff_flags & DIFF_IWHITE) ? "-b " : "", ! (diff_flags & DIFF_IWHITEALL) ? "-w " : "", ! (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "", ! (diff_flags & DIFF_IBLANK) ? "-B " : "", ! (diff_flags & DIFF_ICASE) ? "-i " : "", ! tmp_orig, tmp_new); ! append_redir(cmd, (int)len, p_srr, tmp_diff); ! block_autocmds(); // avoid ShellCmdPost stuff ! (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); ! unblock_autocmds(); ! vim_free(cmd); ! return OK; ! } } /* --- 1180,1219 ---- #endif // Use xdiff for generating the diff. if (dio->dio_internal) return diff_file_internal(dio); ! ! len = STRLEN(tmp_orig) + STRLEN(tmp_new) ! + STRLEN(tmp_diff) + STRLEN(p_srr) + 27; ! cmd = alloc(len); ! if (cmd == NULL) ! return FAIL; ! ! // We don't want $DIFF_OPTIONS to get in the way. ! if (getenv("DIFF_OPTIONS")) ! vim_setenv((char_u *)"DIFF_OPTIONS", (char_u *)""); ! ! // Build the diff command and execute it. Always use -a, binary ! // differences are of no use. Ignore errors, diff returns ! // non-zero when differences have been found. ! vim_snprintf((char *)cmd, len, "diff %s%s%s%s%s%s%s%s %s", ! diff_a_works == FALSE ? "" : "-a ", #if defined(MSWIN) ! diff_bin_works == TRUE ? "--binary " : "", #else ! "", #endif ! (diff_flags & DIFF_IWHITE) ? "-b " : "", ! (diff_flags & DIFF_IWHITEALL) ? "-w " : "", ! (diff_flags & DIFF_IWHITEEOL) ? "-Z " : "", ! (diff_flags & DIFF_IBLANK) ? "-B " : "", ! (diff_flags & DIFF_ICASE) ? "-i " : "", ! tmp_orig, tmp_new); ! append_redir(cmd, (int)len, p_srr, tmp_diff); ! block_autocmds(); // avoid ShellCmdPost stuff ! (void)call_shell(cmd, SHELL_FILTER|SHELL_SILENT|SHELL_DOOUT); ! unblock_autocmds(); ! vim_free(cmd); ! return OK; } /* *************** *** 1432,1462 **** // don't use a new tab page, each tab page has its own diffs cmdmod.cmod_tab = 0; ! if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) ! { ! // Pretend it was a ":split fname" command ! eap->cmdidx = CMD_split; ! curwin->w_p_diff = TRUE; ! do_exedit(eap, old_curwin); ! if (curwin != old_curwin) // split must have worked ! { ! // Set 'diff', 'scrollbind' on and 'wrap' off. ! diff_win_options(curwin, TRUE); ! if (win_valid(old_curwin)) ! { ! diff_win_options(old_curwin, TRUE); ! if (bufref_valid(&old_curbuf)) ! // Move the cursor position to that of the old window. ! curwin->w_cursor.lnum = diff_get_corresponding_line( ! old_curbuf.br_buf, old_curwin->w_cursor.lnum); ! } ! // Now that lines are folded scroll to show the cursor at the same ! // relative position. ! scroll_to_fraction(curwin, curwin->w_height); ! } } } /* --- 1428,1458 ---- // don't use a new tab page, each tab page has its own diffs cmdmod.cmod_tab = 0; ! if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) == FAIL) ! return; ! // Pretend it was a ":split fname" command ! eap->cmdidx = CMD_split; ! curwin->w_p_diff = TRUE; ! do_exedit(eap, old_curwin); ! ! if (curwin == old_curwin) // split didn't work ! return; ! ! // Set 'diff', 'scrollbind' on and 'wrap' off. ! diff_win_options(curwin, TRUE); ! if (win_valid(old_curwin)) ! { ! diff_win_options(old_curwin, TRUE); ! if (bufref_valid(&old_curbuf)) ! // Move the cursor position to that of the old window. ! curwin->w_cursor.lnum = diff_get_corresponding_line( ! old_curbuf.br_buf, old_curwin->w_cursor.lnum); } + // Now that lines are folded scroll to show the cursor at the same + // relative position. + scroll_to_fraction(curwin, curwin->w_height); } /* *** ../vim-9.0.1097/src/digraph.c 2022-10-13 22:12:07.164673822 +0100 --- src/digraph.c 2022-12-26 12:41:45.861700055 +0000 *************** *** 1681,1694 **** } // Add a new digraph to the table. ! if (ga_grow(&user_digraphs, 1) == OK) ! { ! dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len; ! dp->char1 = char1; ! dp->char2 = char2; ! dp->result = n; ! ++user_digraphs.ga_len; ! } } /* --- 1681,1694 ---- } // Add a new digraph to the table. ! if (ga_grow(&user_digraphs, 1) != OK) ! return; ! ! dp = (digr_T *)user_digraphs.ga_data + user_digraphs.ga_len; ! dp->char1 = char1; ! dp->char2 = char2; ! dp->result = n; ! ++user_digraphs.ga_len; } /* *************** *** 1948,2001 **** else list_width = 11; ! if (dp->result != 0) ! { #if defined(USE_UNICODE_DIGRAPHS) ! if (previous != NULL) ! { ! int i; ! for (i = 0; header_table[i].dg_header != NULL; ++i) ! if (*previous < header_table[i].dg_start ! && dp->result >= header_table[i].dg_start ! && dp->result < header_table[i + 1].dg_start) ! { ! digraph_header(_(header_table[i].dg_header)); ! break; ! } ! *previous = dp->result; ! } #endif ! if (msg_col > Columns - list_width) ! msg_putchar('\n'); ! if (msg_col) ! while (msg_col % list_width != 0) ! msg_putchar(' '); ! ! p = buf; ! *p++ = dp->char1; ! *p++ = dp->char2; ! *p++ = ' '; ! *p = NUL; ! msg_outtrans(buf); ! p = buf; ! if (has_mbyte) ! { ! // add a space to draw a composing char on ! if (enc_utf8 && utf_iscomposing(dp->result)) ! *p++ = ' '; ! p += (*mb_char2bytes)(dp->result, p); ! } ! else ! *p++ = (char_u)dp->result; ! *p = NUL; ! msg_outtrans_attr(buf, HL_ATTR(HLF_8)); ! p = buf; ! if (char2cells(dp->result) == 1) *p++ = ' '; ! vim_snprintf((char *)p, sizeof(buf) - (p - buf), " %3d", dp->result); ! msg_outtrans(buf); } } # ifdef FEAT_EVAL --- 1948,2001 ---- else list_width = 11; ! if (dp->result == 0) ! return; ! #if defined(USE_UNICODE_DIGRAPHS) ! if (previous != NULL) ! { ! int i; ! for (i = 0; header_table[i].dg_header != NULL; ++i) ! if (*previous < header_table[i].dg_start ! && dp->result >= header_table[i].dg_start ! && dp->result < header_table[i + 1].dg_start) ! { ! digraph_header(_(header_table[i].dg_header)); ! break; ! } ! *previous = dp->result; ! } #endif ! if (msg_col > Columns - list_width) ! msg_putchar('\n'); ! if (msg_col) ! while (msg_col % list_width != 0) ! msg_putchar(' '); ! ! p = buf; ! *p++ = dp->char1; ! *p++ = dp->char2; ! *p++ = ' '; ! *p = NUL; ! msg_outtrans(buf); ! p = buf; ! if (has_mbyte) ! { ! // add a space to draw a composing char on ! if (enc_utf8 && utf_iscomposing(dp->result)) *p++ = ' '; ! p += (*mb_char2bytes)(dp->result, p); } + else + *p++ = (char_u)dp->result; + *p = NUL; + msg_outtrans_attr(buf, HL_ATTR(HLF_8)); + p = buf; + if (char2cells(dp->result) == 1) + *p++ = ' '; + vim_snprintf((char *)p, sizeof(buf) - (p - buf), " %3d", dp->result); + msg_outtrans(buf); } # ifdef FEAT_EVAL *** ../vim-9.0.1097/src/drawline.c 2022-12-17 15:02:58.651353771 +0000 --- src/drawline.c 2022-12-26 12:41:45.861700055 +0000 *************** *** 225,243 **** // Allocate a buffer, "wlv->extra[]" may already be in use. vim_free(wlv->p_extra_free); wlv->p_extra_free = alloc(MAX_MCO * fdc + 1); ! if (wlv->p_extra_free != NULL) ! { ! wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free, ! wp, FALSE, wlv->lnum); ! wlv->p_extra_free[wlv->n_extra] = NUL; ! wlv->p_extra = wlv->p_extra_free; ! wlv->c_extra = NUL; ! wlv->c_final = NUL; ! if (use_cursor_line_highlight(wp, wlv->lnum)) ! wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF)); ! else ! wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC)); ! } } #endif --- 225,243 ---- // Allocate a buffer, "wlv->extra[]" may already be in use. vim_free(wlv->p_extra_free); wlv->p_extra_free = alloc(MAX_MCO * fdc + 1); ! if (wlv->p_extra_free == NULL) ! return; ! ! wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free, ! wp, FALSE, wlv->lnum); ! wlv->p_extra_free[wlv->n_extra] = NUL; ! wlv->p_extra = wlv->p_extra_free; ! wlv->c_extra = NUL; ! wlv->c_final = NUL; ! if (use_cursor_line_highlight(wp, wlv->lnum)) ! wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF)); ! else ! wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC)); } #endif *** ../vim-9.0.1097/src/version.c 2022-12-25 21:32:01.461075485 +0000 --- src/version.c 2022-12-26 12:49:17.836530235 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1098, /**/ -- TALL KNIGHT: When you have found the shrubbery, then you must cut down the mightiest tree in the forest ... with a herring. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@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 ///