@@ -3806,6 +3806,112 @@ qf_set_title_var(qf_list_T *qfl)
38063806 set_internal_string_var ((char_u * )"w:quickfix_title" , qfl -> qf_title );
38073807}
38083808
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+
38093915/*
38103916 * ":copen": open a window that shows the list of errors.
38113917 * ":lopen": open a window that shows the location list.
@@ -3815,10 +3921,7 @@ ex_copen(exarg_T *eap)
38153921{
38163922 qf_info_T * qi = & ql_info ;
38173923 int height ;
3818- win_T * win ;
3819- tabpage_T * prevtab = curtab ;
3820- buf_T * qf_buf ;
3821- win_T * oldwin = curwin ;
3924+ int status = FAIL ;
38223925
38233926 if (is_loclist_cmd (eap -> cmdidx ))
38243927 {
@@ -3835,107 +3938,28 @@ ex_copen(exarg_T *eap)
38353938 else
38363939 height = QF_WINHEIGHT ;
38373940
3838- reset_VIsual_and_resel (); /* stop Visual mode */
3941+ reset_VIsual_and_resel (); // stop Visual mode
38393942#ifdef FEAT_GUI
38403943 need_mouse_correct = TRUE;
38413944#endif
38423945
3843- /*
3844- * Find existing quickfix window, or open a new one.
3845- */
3846- win = qf_find_win (qi );
3847-
3848- if (win != NULL && cmdmod .tab == 0 )
3849- {
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- }
3946+ // Find an existing quickfix window, or open a new one.
3947+ if (cmdmod .tab == 0 )
3948+ status = qf_goto_cwindow (qi , eap -> addr_count != 0 , height ,
3949+ cmdmod .split & WSP_VERT );
3950+ if (status == FAIL )
3951+ if (qf_open_new_cwindow (qi , height ) == FAIL )
3952+ return ;
39273953
39283954 qf_set_title_var (& qi -> qf_lists [qi -> qf_curlist ]);
39293955
3930- /*
3931- * Fill the buffer with the quickfix list.
3932- */
3956+ // Fill the buffer with the quickfix list.
39333957 qf_fill_buffer (qi , curbuf , NULL );
39343958
39353959 curwin -> w_cursor .lnum = qi -> qf_lists [qi -> qf_curlist ].qf_index ;
39363960 curwin -> w_cursor .col = 0 ;
39373961 check_cursor ();
3938- update_topline (); /* scroll to show the line */
3962+ update_topline (); // scroll to show the line
39393963}
39403964
39413965/*
0 commit comments