comparison src/quickfix.c @ 14796:74fd69162d50 v8.1.0410

patch 8.1.0410: the ex_copen() function is too long commit https://github.com/vim/vim/commit/476c0db00205590974395df717519407a7717270 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Sep 19 21:56:02 2018 +0200 patch 8.1.0410: the ex_copen() function is too long Problem: The ex_copen() function is too long. Solution: Refactor to split off two functions. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Wed, 19 Sep 2018 22:00:06 +0200
parents 3ca7aba1116e
children 6040d93396de
comparison
equal deleted inserted replaced
14795:7ed5ba209a79 14796:74fd69162d50
3805 if (qfl->qf_title != NULL) 3805 if (qfl->qf_title != NULL)
3806 set_internal_string_var((char_u *)"w:quickfix_title", qfl->qf_title); 3806 set_internal_string_var((char_u *)"w:quickfix_title", qfl->qf_title);
3807 } 3807 }
3808 3808
3809 /* 3809 /*
3810 * Goto a quickfix or location list window (if present).
3811 * Returns OK if the window is found, FAIL otherwise.
3812 */
3813 static int
3814 qf_goto_cwindow(qf_info_T *qi, int resize, int sz, int vertsplit)
3815 {
3816 win_T *win;
3817
3818 win = qf_find_win(qi);
3819 if (win == NULL)
3820 return FAIL;
3821
3822 win_goto(win);
3823 if (resize)
3824 {
3825 if (vertsplit)
3826 {
3827 if (sz != win->w_width)
3828 win_setwidth(sz);
3829 }
3830 else if (sz != win->w_height)
3831 win_setheight(sz);
3832 }
3833
3834 return OK;
3835 }
3836
3837 /*
3838 * Open a new quickfix or location list window, load the quickfix buffer and
3839 * set the appropriate options for the window.
3840 * Returns FAIL if the window could not be opened.
3841 */
3842 static int
3843 qf_open_new_cwindow(qf_info_T *qi, int height)
3844 {
3845 buf_T *qf_buf;
3846 win_T *oldwin = curwin;
3847 tabpage_T *prevtab = curtab;
3848 int flags = 0;
3849 win_T *win;
3850
3851 qf_buf = qf_find_buf(qi);
3852
3853 // The current window becomes the previous window afterwards.
3854 win = curwin;
3855
3856 if (IS_QF_STACK(qi) && cmdmod.split == 0)
3857 // Create the new quickfix window at the very bottom, except when
3858 // :belowright or :aboveleft is used.
3859 win_goto(lastwin);
3860 // Default is to open the window below the current window
3861 if (cmdmod.split == 0)
3862 flags = WSP_BELOW;
3863 flags |= WSP_NEWLOC;
3864 if (win_split(height, flags) == FAIL)
3865 return FAIL; // not enough room for window
3866 RESET_BINDING(curwin);
3867
3868 if (IS_LL_STACK(qi))
3869 {
3870 // For the location list window, create a reference to the
3871 // location list from the window 'win'.
3872 curwin->w_llist_ref = win->w_llist;
3873 win->w_llist->qf_refcount++;
3874 }
3875
3876 if (oldwin != curwin)
3877 oldwin = NULL; // don't store info when in another window
3878 if (qf_buf != NULL)
3879 {
3880 // Use the existing quickfix buffer
3881 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
3882 ECMD_HIDE + ECMD_OLDBUF, oldwin);
3883 }
3884 else
3885 {
3886 // Create a new quickfix buffer
3887 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
3888
3889 // switch off 'swapfile'
3890 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
3891 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
3892 OPT_LOCAL);
3893 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL);
3894 RESET_BINDING(curwin);
3895 #ifdef FEAT_DIFF
3896 curwin->w_p_diff = FALSE;
3897 #endif
3898 #ifdef FEAT_FOLDING
3899 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual",
3900 OPT_LOCAL);
3901 #endif
3902 }
3903
3904 // Only set the height when still in the same tab page and there is no
3905 // window to the side.
3906 if (curtab == prevtab && curwin->w_width == Columns)
3907 win_setheight(height);
3908 curwin->w_p_wfh = TRUE; // set 'winfixheight'
3909 if (win_valid(win))
3910 prevwin = win;
3911
3912 return OK;
3913 }
3914
3915 /*
3810 * ":copen": open a window that shows the list of errors. 3916 * ":copen": open a window that shows the list of errors.
3811 * ":lopen": open a window that shows the location list. 3917 * ":lopen": open a window that shows the location list.
3812 */ 3918 */
3813 void 3919 void
3814 ex_copen(exarg_T *eap) 3920 ex_copen(exarg_T *eap)
3815 { 3921 {
3816 qf_info_T *qi = &ql_info; 3922 qf_info_T *qi = &ql_info;
3817 int height; 3923 int height;
3818 win_T *win; 3924 int status = FAIL;
3819 tabpage_T *prevtab = curtab;
3820 buf_T *qf_buf;
3821 win_T *oldwin = curwin;
3822 3925
3823 if (is_loclist_cmd(eap->cmdidx)) 3926 if (is_loclist_cmd(eap->cmdidx))
3824 { 3927 {
3825 qi = GET_LOC_LIST(curwin); 3928 qi = GET_LOC_LIST(curwin);
3826 if (qi == NULL) 3929 if (qi == NULL)
3833 if (eap->addr_count != 0) 3936 if (eap->addr_count != 0)
3834 height = eap->line2; 3937 height = eap->line2;
3835 else 3938 else
3836 height = QF_WINHEIGHT; 3939 height = QF_WINHEIGHT;
3837 3940
3838 reset_VIsual_and_resel(); /* stop Visual mode */ 3941 reset_VIsual_and_resel(); // stop Visual mode
3839 #ifdef FEAT_GUI 3942 #ifdef FEAT_GUI
3840 need_mouse_correct = TRUE; 3943 need_mouse_correct = TRUE;
3841 #endif 3944 #endif
3842 3945
3843 /* 3946 // Find an existing quickfix window, or open a new one.
3844 * Find existing quickfix window, or open a new one. 3947 if (cmdmod.tab == 0)
3845 */ 3948 status = qf_goto_cwindow(qi, eap->addr_count != 0, height,
3846 win = qf_find_win(qi); 3949 cmdmod.split & WSP_VERT);
3847 3950 if (status == FAIL)
3848 if (win != NULL && cmdmod.tab == 0) 3951 if (qf_open_new_cwindow(qi, height) == FAIL)
3849 { 3952 return;
3850 win_goto(win);
3851 if (eap->addr_count != 0)
3852 {
3853 if (cmdmod.split & WSP_VERT)
3854 {
3855 if (height != win->w_width)
3856 win_setwidth(height);
3857 }
3858 else if (height != win->w_height)
3859 win_setheight(height);
3860 }
3861 }
3862 else
3863 {
3864 int flags = 0;
3865
3866 qf_buf = qf_find_buf(qi);
3867
3868 /* The current window becomes the previous window afterwards. */
3869 win = curwin;
3870
3871 if ((eap->cmdidx == CMD_copen || eap->cmdidx == CMD_cwindow)
3872 && cmdmod.split == 0)
3873 /* Create the new quickfix window at the very bottom, except when
3874 * :belowright or :aboveleft is used. */
3875 win_goto(lastwin);
3876 /* Default is to open the window below the current window */
3877 if (cmdmod.split == 0)
3878 flags = WSP_BELOW;
3879 flags |= WSP_NEWLOC;
3880 if (win_split(height, flags) == FAIL)
3881 return; /* not enough room for window */
3882 RESET_BINDING(curwin);
3883
3884 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow)
3885 {
3886 /*
3887 * For the location list window, create a reference to the
3888 * location list from the window 'win'.
3889 */
3890 curwin->w_llist_ref = win->w_llist;
3891 win->w_llist->qf_refcount++;
3892 }
3893
3894 if (oldwin != curwin)
3895 oldwin = NULL; /* don't store info when in another window */
3896 if (qf_buf != NULL)
3897 /* Use the existing quickfix buffer */
3898 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
3899 ECMD_HIDE + ECMD_OLDBUF, oldwin);
3900 else
3901 {
3902 /* Create a new quickfix buffer */
3903 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
3904 /* switch off 'swapfile' */
3905 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
3906 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
3907 OPT_LOCAL);
3908 set_option_value((char_u *)"bh", 0L, (char_u *)"wipe", OPT_LOCAL);
3909 RESET_BINDING(curwin);
3910 #ifdef FEAT_DIFF
3911 curwin->w_p_diff = FALSE;
3912 #endif
3913 #ifdef FEAT_FOLDING
3914 set_option_value((char_u *)"fdm", 0L, (char_u *)"manual",
3915 OPT_LOCAL);
3916 #endif
3917 }
3918
3919 /* Only set the height when still in the same tab page and there is no
3920 * window to the side. */
3921 if (curtab == prevtab && curwin->w_width == Columns)
3922 win_setheight(height);
3923 curwin->w_p_wfh = TRUE; /* set 'winfixheight' */
3924 if (win_valid(win))
3925 prevwin = win;
3926 }
3927 3953
3928 qf_set_title_var(&qi->qf_lists[qi->qf_curlist]); 3954 qf_set_title_var(&qi->qf_lists[qi->qf_curlist]);
3929 3955
3930 /* 3956 // Fill the buffer with the quickfix list.
3931 * Fill the buffer with the quickfix list.
3932 */
3933 qf_fill_buffer(qi, curbuf, NULL); 3957 qf_fill_buffer(qi, curbuf, NULL);
3934 3958
3935 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index; 3959 curwin->w_cursor.lnum = qi->qf_lists[qi->qf_curlist].qf_index;
3936 curwin->w_cursor.col = 0; 3960 curwin->w_cursor.col = 0;
3937 check_cursor(); 3961 check_cursor();
3938 update_topline(); /* scroll to show the line */ 3962 update_topline(); // scroll to show the line
3939 } 3963 }
3940 3964
3941 /* 3965 /*
3942 * Move the cursor in the quickfix window to "lnum". 3966 * Move the cursor in the quickfix window to "lnum".
3943 */ 3967 */