Mercurial > vim
comparison src/quickfix.c @ 31778:579c846086eb v9.0.1221
patch 9.0.1221: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/f97a295ccaa9803367f3714cdefce4e2283c771d
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Wed Jan 18 18:17:48 2023 +0000
patch 9.0.1221: code is indented more than necessary
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11833)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 18 Jan 2023 19:30:03 +0100 |
parents | b6bef244837e |
children | 50555279168b |
comparison
equal
deleted
inserted
replaced
31777:84bb462086cf | 31778:579c846086eb |
---|---|
1896 static void | 1896 static void |
1897 qf_store_title(qf_list_T *qfl, char_u *title) | 1897 qf_store_title(qf_list_T *qfl, char_u *title) |
1898 { | 1898 { |
1899 VIM_CLEAR(qfl->qf_title); | 1899 VIM_CLEAR(qfl->qf_title); |
1900 | 1900 |
1901 if (title != NULL) | 1901 if (title == NULL) |
1902 { | 1902 return; |
1903 char_u *p = alloc_id(STRLEN(title) + 2, aid_qf_title); | 1903 |
1904 | 1904 char_u *p = alloc_id(STRLEN(title) + 2, aid_qf_title); |
1905 qfl->qf_title = p; | 1905 |
1906 if (p != NULL) | 1906 qfl->qf_title = p; |
1907 STRCPY(p, title); | 1907 if (p != NULL) |
1908 } | 1908 STRCPY(p, title); |
1909 } | 1909 } |
1910 | 1910 |
1911 /* | 1911 /* |
1912 * The title of a quickfix/location list is set, by default, to the command | 1912 * The title of a quickfix/location list is set, by default, to the command |
1913 * that created the quickfix list with the ":" prefix. | 1913 * that created the quickfix list with the ":" prefix. |
1974 locstack_queue_delreq(qf_info_T *qi) | 1974 locstack_queue_delreq(qf_info_T *qi) |
1975 { | 1975 { |
1976 qf_delq_T *q; | 1976 qf_delq_T *q; |
1977 | 1977 |
1978 q = ALLOC_ONE(qf_delq_T); | 1978 q = ALLOC_ONE(qf_delq_T); |
1979 if (q != NULL) | 1979 if (q == NULL) |
1980 { | 1980 return; |
1981 q->qi = qi; | 1981 |
1982 q->next = qf_delq_head; | 1982 q->qi = qi; |
1983 qf_delq_head = q; | 1983 q->next = qf_delq_head; |
1984 } | 1984 qf_delq_head = q; |
1985 } | 1985 } |
1986 | 1986 |
1987 /* | 1987 /* |
1988 * Return the global quickfix stack window buffer number. | 1988 * Return the global quickfix stack window buffer number. |
1989 */ | 1989 */ |
2000 static void | 2000 static void |
2001 wipe_qf_buffer(qf_info_T *qi) | 2001 wipe_qf_buffer(qf_info_T *qi) |
2002 { | 2002 { |
2003 buf_T *qfbuf; | 2003 buf_T *qfbuf; |
2004 | 2004 |
2005 if (qi->qf_bufnr != INVALID_QFBUFNR) | 2005 if (qi->qf_bufnr == INVALID_QFBUFNR) |
2006 { | 2006 return; |
2007 qfbuf = buflist_findnr(qi->qf_bufnr); | 2007 |
2008 if (qfbuf != NULL && qfbuf->b_nwindows == 0) | 2008 qfbuf = buflist_findnr(qi->qf_bufnr); |
2009 { | 2009 if (qfbuf != NULL && qfbuf->b_nwindows == 0) |
2010 // If the quickfix buffer is not loaded in any window, then | 2010 { |
2011 // wipe the buffer. | 2011 // If the quickfix buffer is not loaded in any window, then |
2012 close_buffer(NULL, qfbuf, DOBUF_WIPE, FALSE, FALSE); | 2012 // wipe the buffer. |
2013 qi->qf_bufnr = INVALID_QFBUFNR; | 2013 close_buffer(NULL, qfbuf, DOBUF_WIPE, FALSE, FALSE); |
2014 } | 2014 qi->qf_bufnr = INVALID_QFBUFNR; |
2015 } | 2015 } |
2016 } | 2016 } |
2017 | 2017 |
2018 /* | 2018 /* |
2019 * Free a location list stack | 2019 * Free a location list stack |
2229 qf_alloc_stack(qfltype_T qfltype) | 2229 qf_alloc_stack(qfltype_T qfltype) |
2230 { | 2230 { |
2231 qf_info_T *qi; | 2231 qf_info_T *qi; |
2232 | 2232 |
2233 qi = ALLOC_CLEAR_ONE_ID(qf_info_T, aid_qf_qfinfo); | 2233 qi = ALLOC_CLEAR_ONE_ID(qf_info_T, aid_qf_qfinfo); |
2234 if (qi != NULL) | 2234 if (qi == NULL) |
2235 { | 2235 return NULL; |
2236 qi->qf_refcount++; | 2236 |
2237 qi->qfl_type = qfltype; | 2237 qi->qf_refcount++; |
2238 qi->qf_bufnr = INVALID_QFBUFNR; | 2238 qi->qfl_type = qfltype; |
2239 } | 2239 qi->qf_bufnr = INVALID_QFBUFNR; |
2240 return qi; | 2240 return qi; |
2241 } | 2241 } |
2242 | 2242 |
2243 /* | 2243 /* |
2244 * Return the location list stack for window 'wp'. | 2244 * Return the location list stack for window 'wp'. |
4571 win_T *win; | 4571 win_T *win; |
4572 aco_save_T aco; | 4572 aco_save_T aco; |
4573 | 4573 |
4574 // Check if a buffer for the quickfix list exists. Update it. | 4574 // Check if a buffer for the quickfix list exists. Update it. |
4575 buf = qf_find_buf(qi); | 4575 buf = qf_find_buf(qi); |
4576 if (buf != NULL) | 4576 if (buf == NULL) |
4577 { | 4577 return; |
4578 linenr_T old_line_count = buf->b_ml.ml_line_count; | 4578 |
4579 int qf_winid = 0; | 4579 linenr_T old_line_count = buf->b_ml.ml_line_count; |
4580 | 4580 int qf_winid = 0; |
4581 if (IS_LL_STACK(qi)) | 4581 |
4582 { | 4582 if (IS_LL_STACK(qi)) |
4583 if (curwin->w_llist == qi) | 4583 { |
4584 win = curwin; | 4584 if (curwin->w_llist == qi) |
4585 else | 4585 win = curwin; |
4586 { | 4586 else |
4587 // Find the file window (non-quickfix) with this location list | 4587 { |
4588 win = qf_find_win_with_loclist(qi); | 4588 // Find the file window (non-quickfix) with this location list |
4589 if (win == NULL) | 4589 win = qf_find_win_with_loclist(qi); |
4590 // File window is not found. Find the location list window. | 4590 if (win == NULL) |
4591 win = qf_find_win(qi); | 4591 // File window is not found. Find the location list window. |
4592 if (win == NULL) | 4592 win = qf_find_win(qi); |
4593 return; | 4593 if (win == NULL) |
4594 } | 4594 return; |
4595 qf_winid = win->w_id; | 4595 } |
4596 } | 4596 qf_winid = win->w_id; |
4597 | 4597 } |
4598 // autocommands may cause trouble | 4598 |
4599 incr_quickfix_busy(); | 4599 // autocommands may cause trouble |
4600 | 4600 incr_quickfix_busy(); |
4601 int do_fill = TRUE; | 4601 |
4602 int do_fill = TRUE; | |
4603 if (old_last == NULL) | |
4604 { | |
4605 // set curwin/curbuf to buf and save a few things | |
4606 aucmd_prepbuf(&aco, buf); | |
4607 if (curbuf != buf) | |
4608 do_fill = FALSE; // failed to find a window for "buf" | |
4609 } | |
4610 | |
4611 if (do_fill) | |
4612 { | |
4613 qf_update_win_titlevar(qi); | |
4614 | |
4615 qf_fill_buffer(qf_get_curlist(qi), buf, old_last, qf_winid); | |
4616 ++CHANGEDTICK(buf); | |
4617 | |
4602 if (old_last == NULL) | 4618 if (old_last == NULL) |
4603 { | 4619 { |
4604 // set curwin/curbuf to buf and save a few things | 4620 (void)qf_win_pos_update(qi, 0); |
4605 aucmd_prepbuf(&aco, buf); | 4621 |
4606 if (curbuf != buf) | 4622 // restore curwin/curbuf and a few other things |
4607 do_fill = FALSE; // failed to find a window for "buf" | 4623 aucmd_restbuf(&aco); |
4608 } | 4624 } |
4609 | 4625 } |
4610 if (do_fill) | 4626 |
4611 { | 4627 // Only redraw when added lines are visible. This avoids flickering |
4612 qf_update_win_titlevar(qi); | 4628 // when the added lines are not visible. |
4613 | 4629 if ((win = qf_find_win(qi)) != NULL && old_line_count < win->w_botline) |
4614 qf_fill_buffer(qf_get_curlist(qi), buf, old_last, qf_winid); | 4630 redraw_buf_later(buf, UPD_NOT_VALID); |
4615 ++CHANGEDTICK(buf); | 4631 |
4616 | 4632 // always called after incr_quickfix_busy() |
4617 if (old_last == NULL) | 4633 decr_quickfix_busy(); |
4618 { | |
4619 (void)qf_win_pos_update(qi, 0); | |
4620 | |
4621 // restore curwin/curbuf and a few other things | |
4622 aucmd_restbuf(&aco); | |
4623 } | |
4624 } | |
4625 | |
4626 // Only redraw when added lines are visible. This avoids flickering | |
4627 // when the added lines are not visible. | |
4628 if ((win = qf_find_win(qi)) != NULL && old_line_count < win->w_botline) | |
4629 redraw_buf_later(buf, UPD_NOT_VALID); | |
4630 | |
4631 // always called after incr_quickfix_busy() | |
4632 decr_quickfix_busy(); | |
4633 } | |
4634 } | 4634 } |
4635 | 4635 |
4636 /* | 4636 /* |
4637 * Add an error line to the quickfix buffer. | 4637 * Add an error line to the quickfix buffer. |
4638 */ | 4638 */ |
4922 static int | 4922 static int |
4923 qf_restore_list(qf_info_T *qi, int_u save_qfid) | 4923 qf_restore_list(qf_info_T *qi, int_u save_qfid) |
4924 { | 4924 { |
4925 int curlist; | 4925 int curlist; |
4926 | 4926 |
4927 if (qf_get_curlist(qi)->qf_id != save_qfid) | 4927 if (qf_get_curlist(qi)->qf_id == save_qfid) |
4928 { | 4928 return OK; |
4929 curlist = qf_id2nr(qi, save_qfid); | 4929 |
4930 if (curlist < 0) | 4930 curlist = qf_id2nr(qi, save_qfid); |
4931 // list is not present | 4931 if (curlist < 0) |
4932 return FAIL; | 4932 // list is not present |
4933 qi->qf_curlist = curlist; | 4933 return FAIL; |
4934 } | 4934 qi->qf_curlist = curlist; |
4935 return OK; | 4935 return OK; |
4936 } | 4936 } |
4937 | 4937 |
4938 /* | 4938 /* |
4939 * Jump to the first entry if there is one. | 4939 * Jump to the first entry if there is one. |
6542 static void | 6542 static void |
6543 restore_start_dir(char_u *dirname_start) | 6543 restore_start_dir(char_u *dirname_start) |
6544 { | 6544 { |
6545 char_u *dirname_now = alloc(MAXPATHL); | 6545 char_u *dirname_now = alloc(MAXPATHL); |
6546 | 6546 |
6547 if (NULL != dirname_now) | 6547 if (dirname_now == NULL) |
6548 { | 6548 return; |
6549 mch_dirname(dirname_now, MAXPATHL); | 6549 |
6550 if (STRCMP(dirname_start, dirname_now) != 0) | 6550 mch_dirname(dirname_now, MAXPATHL); |
6551 { | 6551 if (STRCMP(dirname_start, dirname_now) != 0) |
6552 // If the directory has changed, change it back by building up an | 6552 { |
6553 // appropriate ex command and executing it. | 6553 // If the directory has changed, change it back by building up an |
6554 exarg_T ea; | 6554 // appropriate ex command and executing it. |
6555 | 6555 exarg_T ea; |
6556 CLEAR_FIELD(ea); | 6556 |
6557 ea.arg = dirname_start; | 6557 CLEAR_FIELD(ea); |
6558 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; | 6558 ea.arg = dirname_start; |
6559 ex_cd(&ea); | 6559 ea.cmdidx = (curwin->w_localdir == NULL) ? CMD_cd : CMD_lcd; |
6560 } | 6560 ex_cd(&ea); |
6561 vim_free(dirname_now); | 6561 } |
6562 } | 6562 vim_free(dirname_now); |
6563 } | 6563 } |
6564 | 6564 |
6565 /* | 6565 /* |
6566 * Load file "fname" into a dummy buffer and return the buffer pointer, | 6566 * Load file "fname" into a dummy buffer and return the buffer pointer, |
6567 * placing the directory resulting from the buffer load into the | 6567 * placing the directory resulting from the buffer load into the |
6721 * 'autochdir' option have changed it. | 6721 * 'autochdir' option have changed it. |
6722 */ | 6722 */ |
6723 static void | 6723 static void |
6724 unload_dummy_buffer(buf_T *buf, char_u *dirname_start) | 6724 unload_dummy_buffer(buf_T *buf, char_u *dirname_start) |
6725 { | 6725 { |
6726 if (curbuf != buf) // safety check | 6726 if (curbuf == buf) // safety check |
6727 { | 6727 return; |
6728 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE, TRUE); | 6728 |
6729 | 6729 close_buffer(NULL, buf, DOBUF_UNLOAD, FALSE, TRUE); |
6730 // When autocommands/'autochdir' option changed directory: go back. | 6730 |
6731 restore_start_dir(dirname_start); | 6731 // When autocommands/'autochdir' option changed directory: go back. |
6732 } | 6732 restore_start_dir(dirname_start); |
6733 } | 6733 } |
6734 | 6734 |
6735 #if defined(FEAT_EVAL) || defined(PROTO) | 6735 #if defined(FEAT_EVAL) || defined(PROTO) |
6736 /* | 6736 /* |
6737 * Copy the specified quickfix entry items into a new dict and append the dict | 6737 * Copy the specified quickfix entry items into a new dict and append the dict |
6860 char_u *errorformat = p_efm; | 6860 char_u *errorformat = p_efm; |
6861 dictitem_T *efm_di; | 6861 dictitem_T *efm_di; |
6862 list_T *l; | 6862 list_T *l; |
6863 | 6863 |
6864 // Only a List value is supported | 6864 // Only a List value is supported |
6865 if (di->di_tv.v_type == VAR_LIST && di->di_tv.vval.v_list != NULL) | 6865 if (di->di_tv.v_type != VAR_LIST || di->di_tv.vval.v_list == NULL) |
6866 { | 6866 return FAIL; |
6867 // If errorformat is supplied then use it, otherwise use the 'efm' | 6867 |
6868 // option setting | 6868 // If errorformat is supplied then use it, otherwise use the 'efm' |
6869 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL) | 6869 // option setting |
6870 { | 6870 if ((efm_di = dict_find(what, (char_u *)"efm", -1)) != NULL) |
6871 if (efm_di->di_tv.v_type != VAR_STRING || | 6871 { |
6872 efm_di->di_tv.vval.v_string == NULL) | 6872 if (efm_di->di_tv.v_type != VAR_STRING || |
6873 return FAIL; | 6873 efm_di->di_tv.vval.v_string == NULL) |
6874 errorformat = efm_di->di_tv.vval.v_string; | |
6875 } | |
6876 | |
6877 l = list_alloc(); | |
6878 if (l == NULL) | |
6879 return FAIL; | 6874 return FAIL; |
6880 | 6875 errorformat = efm_di->di_tv.vval.v_string; |
6881 qi = qf_alloc_stack(QFLT_INTERNAL); | 6876 } |
6882 if (qi != NULL) | 6877 |
6883 { | 6878 l = list_alloc(); |
6884 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, | 6879 if (l == NULL) |
6885 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) | 6880 return FAIL; |
6886 { | 6881 |
6887 (void)get_errorlist(qi, NULL, 0, 0, l); | 6882 qi = qf_alloc_stack(QFLT_INTERNAL); |
6888 qf_free(&qi->qf_lists[0]); | 6883 if (qi != NULL) |
6889 } | 6884 { |
6890 free(qi); | 6885 if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, |
6891 } | 6886 TRUE, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) |
6892 dict_add_list(retdict, "items", l); | 6887 { |
6893 status = OK; | 6888 (void)get_errorlist(qi, NULL, 0, 0, l); |
6894 } | 6889 qf_free(&qi->qf_lists[0]); |
6890 } | |
6891 free(qi); | |
6892 } | |
6893 dict_add_list(retdict, "items", l); | |
6894 status = OK; | |
6895 | 6895 |
6896 return status; | 6896 return status; |
6897 } | 6897 } |
6898 | 6898 |
6899 /* | 6899 /* |
7630 { | 7630 { |
7631 callback_T cb; | 7631 callback_T cb; |
7632 | 7632 |
7633 free_callback(&qfl->qf_qftf_cb); | 7633 free_callback(&qfl->qf_qftf_cb); |
7634 cb = get_callback(&di->di_tv); | 7634 cb = get_callback(&di->di_tv); |
7635 if (cb.cb_name != NULL && *cb.cb_name != NUL) | 7635 if (cb.cb_name == NULL || *cb.cb_name == NUL) |
7636 { | 7636 return OK; |
7637 set_callback(&qfl->qf_qftf_cb, &cb); | 7637 |
7638 if (cb.cb_free_name) | 7638 set_callback(&qfl->qf_qftf_cb, &cb); |
7639 vim_free(cb.cb_name); | 7639 if (cb.cb_free_name) |
7640 } | 7640 vim_free(cb.cb_name); |
7641 | 7641 |
7642 return OK; | 7642 return OK; |
7643 } | 7643 } |
7644 | 7644 |
7645 /* | 7645 /* |
8124 return; | 8124 return; |
8125 | 8125 |
8126 // Evaluate the expression. When the result is a string or a list we can | 8126 // Evaluate the expression. When the result is a string or a list we can |
8127 // use it to fill the errorlist. | 8127 // use it to fill the errorlist. |
8128 tv = eval_expr(eap->arg, eap); | 8128 tv = eval_expr(eap->arg, eap); |
8129 if (tv != NULL) | 8129 if (tv == NULL) |
8130 { | 8130 return; |
8131 (void)cexpr_core(eap, tv); | 8131 |
8132 free_tv(tv); | 8132 (void)cexpr_core(eap, tv); |
8133 } | 8133 free_tv(tv); |
8134 } | 8134 } |
8135 #endif | 8135 #endif |
8136 | 8136 |
8137 /* | 8137 /* |
8138 * Get the location list for ":lhelpgrep" | 8138 * Get the location list for ":lhelpgrep" |