Mercurial > vim
comparison src/window.c @ 18010:cf8e0c7e0cb9 v8.1.2001
patch 8.1.2001: some source files are too big
Commit: https://github.com/vim/vim/commit/261f346f8154c0ec7094a4a211c653c74e9f7c2e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 7 15:45:32 2019 +0200
patch 8.1.2001: some source files are too big
Problem: Some source files are too big.
Solution: Move buffer and window related functions to evalbuffer.c and
evalwindow.c. (Yegappan Lakshmanan, closes #4898)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 07 Sep 2019 16:00:03 +0200 |
parents | 079e10a49ea1 |
children | 1868ec23360e |
comparison
equal
deleted
inserted
replaced
18009:40255308856f | 18010:cf8e0c7e0cb9 |
---|---|
6585 wp = wp2; | 6585 wp = wp2; |
6586 } | 6586 } |
6587 return wp; | 6587 return wp; |
6588 } | 6588 } |
6589 | 6589 |
6590 #if defined(FEAT_EVAL) || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \ | |
6591 || defined(PROTO) | |
6592 /* | |
6593 * Set "win" to be the curwin and "tp" to be the current tab page. | |
6594 * restore_win() MUST be called to undo, also when FAIL is returned. | |
6595 * No autocommands will be executed until restore_win() is called. | |
6596 * When "no_display" is TRUE the display won't be affected, no redraw is | |
6597 * triggered, another tabpage access is limited. | |
6598 * Returns FAIL if switching to "win" failed. | |
6599 */ | |
6600 int | |
6601 switch_win( | |
6602 win_T **save_curwin, | |
6603 tabpage_T **save_curtab, | |
6604 win_T *win, | |
6605 tabpage_T *tp, | |
6606 int no_display) | |
6607 { | |
6608 block_autocmds(); | |
6609 return switch_win_noblock(save_curwin, save_curtab, win, tp, no_display); | |
6610 } | |
6611 | |
6612 /* | |
6613 * As switch_win() but without blocking autocommands. | |
6614 */ | |
6615 int | |
6616 switch_win_noblock( | |
6617 win_T **save_curwin, | |
6618 tabpage_T **save_curtab, | |
6619 win_T *win, | |
6620 tabpage_T *tp, | |
6621 int no_display) | |
6622 { | |
6623 *save_curwin = curwin; | |
6624 if (tp != NULL) | |
6625 { | |
6626 *save_curtab = curtab; | |
6627 if (no_display) | |
6628 { | |
6629 curtab->tp_firstwin = firstwin; | |
6630 curtab->tp_lastwin = lastwin; | |
6631 curtab = tp; | |
6632 firstwin = curtab->tp_firstwin; | |
6633 lastwin = curtab->tp_lastwin; | |
6634 } | |
6635 else | |
6636 goto_tabpage_tp(tp, FALSE, FALSE); | |
6637 } | |
6638 if (!win_valid(win)) | |
6639 return FAIL; | |
6640 curwin = win; | |
6641 curbuf = curwin->w_buffer; | |
6642 return OK; | |
6643 } | |
6644 | |
6645 /* | |
6646 * Restore current tabpage and window saved by switch_win(), if still valid. | |
6647 * When "no_display" is TRUE the display won't be affected, no redraw is | |
6648 * triggered. | |
6649 */ | |
6650 void | |
6651 restore_win( | |
6652 win_T *save_curwin, | |
6653 tabpage_T *save_curtab, | |
6654 int no_display) | |
6655 { | |
6656 restore_win_noblock(save_curwin, save_curtab, no_display); | |
6657 unblock_autocmds(); | |
6658 } | |
6659 | |
6660 /* | |
6661 * As restore_win() but without unblocking autocommands. | |
6662 */ | |
6663 void | |
6664 restore_win_noblock( | |
6665 win_T *save_curwin, | |
6666 tabpage_T *save_curtab, | |
6667 int no_display) | |
6668 { | |
6669 if (save_curtab != NULL && valid_tabpage(save_curtab)) | |
6670 { | |
6671 if (no_display) | |
6672 { | |
6673 curtab->tp_firstwin = firstwin; | |
6674 curtab->tp_lastwin = lastwin; | |
6675 curtab = save_curtab; | |
6676 firstwin = curtab->tp_firstwin; | |
6677 lastwin = curtab->tp_lastwin; | |
6678 } | |
6679 else | |
6680 goto_tabpage_tp(save_curtab, FALSE, FALSE); | |
6681 } | |
6682 if (win_valid(save_curwin)) | |
6683 { | |
6684 curwin = save_curwin; | |
6685 curbuf = curwin->w_buffer; | |
6686 } | |
6687 #ifdef FEAT_TEXT_PROP | |
6688 else if (WIN_IS_POPUP(curwin)) | |
6689 // original window was closed and now we're in a popup window: Go | |
6690 // to the first valid window. | |
6691 win_goto(firstwin); | |
6692 #endif | |
6693 } | |
6694 | |
6695 /* | |
6696 * Make "buf" the current buffer. restore_buffer() MUST be called to undo. | |
6697 * No autocommands will be executed. Use aucmd_prepbuf() if there are any. | |
6698 */ | |
6699 void | |
6700 switch_buffer(bufref_T *save_curbuf, buf_T *buf) | |
6701 { | |
6702 block_autocmds(); | |
6703 set_bufref(save_curbuf, curbuf); | |
6704 --curbuf->b_nwindows; | |
6705 curbuf = buf; | |
6706 curwin->w_buffer = buf; | |
6707 ++curbuf->b_nwindows; | |
6708 } | |
6709 | |
6710 /* | |
6711 * Restore the current buffer after using switch_buffer(). | |
6712 */ | |
6713 void | |
6714 restore_buffer(bufref_T *save_curbuf) | |
6715 { | |
6716 unblock_autocmds(); | |
6717 /* Check for valid buffer, just in case. */ | |
6718 if (bufref_valid(save_curbuf)) | |
6719 { | |
6720 --curbuf->b_nwindows; | |
6721 curwin->w_buffer = save_curbuf->br_buf; | |
6722 curbuf = save_curbuf->br_buf; | |
6723 ++curbuf->b_nwindows; | |
6724 } | |
6725 } | |
6726 #endif | |
6727 | |
6728 #if defined(FEAT_GUI) || defined(PROTO) | 6590 #if defined(FEAT_GUI) || defined(PROTO) |
6729 /* | 6591 /* |
6730 * Return TRUE if there is any vertically split window. | 6592 * Return TRUE if there is any vertically split window. |
6731 */ | 6593 */ |
6732 int | 6594 int |
6894 } | 6756 } |
6895 | 6757 |
6896 return NULL; // no error | 6758 return NULL; // no error |
6897 } | 6759 } |
6898 #endif | 6760 #endif |
6899 | |
6900 #if defined(FEAT_EVAL) || defined(PROTO) | |
6901 int | |
6902 win_getid(typval_T *argvars) | |
6903 { | |
6904 int winnr; | |
6905 win_T *wp; | |
6906 | |
6907 if (argvars[0].v_type == VAR_UNKNOWN) | |
6908 return curwin->w_id; | |
6909 winnr = tv_get_number(&argvars[0]); | |
6910 if (winnr > 0) | |
6911 { | |
6912 if (argvars[1].v_type == VAR_UNKNOWN) | |
6913 wp = firstwin; | |
6914 else | |
6915 { | |
6916 tabpage_T *tp; | |
6917 int tabnr = tv_get_number(&argvars[1]); | |
6918 | |
6919 FOR_ALL_TABPAGES(tp) | |
6920 if (--tabnr == 0) | |
6921 break; | |
6922 if (tp == NULL) | |
6923 return -1; | |
6924 if (tp == curtab) | |
6925 wp = firstwin; | |
6926 else | |
6927 wp = tp->tp_firstwin; | |
6928 } | |
6929 for ( ; wp != NULL; wp = wp->w_next) | |
6930 if (--winnr == 0) | |
6931 return wp->w_id; | |
6932 } | |
6933 return 0; | |
6934 } | |
6935 | |
6936 int | |
6937 win_gotoid(typval_T *argvars) | |
6938 { | |
6939 win_T *wp; | |
6940 tabpage_T *tp; | |
6941 int id = tv_get_number(&argvars[0]); | |
6942 | |
6943 FOR_ALL_TAB_WINDOWS(tp, wp) | |
6944 if (wp->w_id == id) | |
6945 { | |
6946 goto_tabpage_win(tp, wp); | |
6947 return 1; | |
6948 } | |
6949 return 0; | |
6950 } | |
6951 | |
6952 void | |
6953 win_id2tabwin(typval_T *argvars, list_T *list) | |
6954 { | |
6955 win_T *wp; | |
6956 tabpage_T *tp; | |
6957 int winnr = 1; | |
6958 int tabnr = 1; | |
6959 int id = tv_get_number(&argvars[0]); | |
6960 | |
6961 FOR_ALL_TABPAGES(tp) | |
6962 { | |
6963 FOR_ALL_WINDOWS_IN_TAB(tp, wp) | |
6964 { | |
6965 if (wp->w_id == id) | |
6966 { | |
6967 list_append_number(list, tabnr); | |
6968 list_append_number(list, winnr); | |
6969 return; | |
6970 } | |
6971 ++winnr; | |
6972 } | |
6973 ++tabnr; | |
6974 winnr = 1; | |
6975 } | |
6976 list_append_number(list, 0); | |
6977 list_append_number(list, 0); | |
6978 } | |
6979 | |
6980 /* | |
6981 * Return the window pointer of window "id". | |
6982 */ | |
6983 win_T * | |
6984 win_id2wp(int id) | |
6985 { | |
6986 return win_id2wp_tp(id, NULL); | |
6987 } | |
6988 | |
6989 /* | |
6990 * Return the window and tab pointer of window "id". | |
6991 */ | |
6992 win_T * | |
6993 win_id2wp_tp(int id, tabpage_T **tpp) | |
6994 { | |
6995 win_T *wp; | |
6996 tabpage_T *tp; | |
6997 | |
6998 FOR_ALL_TAB_WINDOWS(tp, wp) | |
6999 if (wp->w_id == id) | |
7000 { | |
7001 if (tpp != NULL) | |
7002 *tpp = tp; | |
7003 return wp; | |
7004 } | |
7005 #ifdef FEAT_TEXT_PROP | |
7006 // popup windows are in separate lists | |
7007 FOR_ALL_TABPAGES(tp) | |
7008 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next) | |
7009 if (wp->w_id == id) | |
7010 { | |
7011 if (tpp != NULL) | |
7012 *tpp = tp; | |
7013 return wp; | |
7014 } | |
7015 for (wp = first_popupwin; wp != NULL; wp = wp->w_next) | |
7016 if (wp->w_id == id) | |
7017 { | |
7018 if (tpp != NULL) | |
7019 *tpp = tp; | |
7020 return wp; | |
7021 } | |
7022 #endif | |
7023 | |
7024 return NULL; | |
7025 } | |
7026 | |
7027 int | |
7028 win_id2win(typval_T *argvars) | |
7029 { | |
7030 win_T *wp; | |
7031 int nr = 1; | |
7032 int id = tv_get_number(&argvars[0]); | |
7033 | |
7034 FOR_ALL_WINDOWS(wp) | |
7035 { | |
7036 if (wp->w_id == id) | |
7037 return nr; | |
7038 ++nr; | |
7039 } | |
7040 return 0; | |
7041 } | |
7042 | |
7043 void | |
7044 win_findbuf(typval_T *argvars, list_T *list) | |
7045 { | |
7046 win_T *wp; | |
7047 tabpage_T *tp; | |
7048 int bufnr = tv_get_number(&argvars[0]); | |
7049 | |
7050 FOR_ALL_TAB_WINDOWS(tp, wp) | |
7051 if (wp->w_buffer->b_fnum == bufnr) | |
7052 list_append_number(list, wp->w_id); | |
7053 } | |
7054 | |
7055 /* | |
7056 * Find window specified by "vp" in tabpage "tp". | |
7057 */ | |
7058 win_T * | |
7059 find_win_by_nr( | |
7060 typval_T *vp, | |
7061 tabpage_T *tp) // NULL for current tab page | |
7062 { | |
7063 win_T *wp; | |
7064 int nr = (int)tv_get_number_chk(vp, NULL); | |
7065 | |
7066 if (nr < 0) | |
7067 return NULL; | |
7068 if (nr == 0) | |
7069 return curwin; | |
7070 | |
7071 FOR_ALL_WINDOWS_IN_TAB(tp, wp) | |
7072 { | |
7073 if (nr >= LOWEST_WIN_ID) | |
7074 { | |
7075 if (wp->w_id == nr) | |
7076 return wp; | |
7077 } | |
7078 else if (--nr <= 0) | |
7079 break; | |
7080 } | |
7081 if (nr >= LOWEST_WIN_ID) | |
7082 { | |
7083 #ifdef FEAT_TEXT_PROP | |
7084 // check tab-local popup windows | |
7085 for (wp = tp->tp_first_popupwin; wp != NULL; wp = wp->w_next) | |
7086 if (wp->w_id == nr) | |
7087 return wp; | |
7088 // check global popup windows | |
7089 for (wp = first_popupwin; wp != NULL; wp = wp->w_next) | |
7090 if (wp->w_id == nr) | |
7091 return wp; | |
7092 #endif | |
7093 return NULL; | |
7094 } | |
7095 return wp; | |
7096 } | |
7097 | |
7098 /* | |
7099 * Find a window: When using a Window ID in any tab page, when using a number | |
7100 * in the current tab page. | |
7101 */ | |
7102 win_T * | |
7103 find_win_by_nr_or_id(typval_T *vp) | |
7104 { | |
7105 int nr = (int)tv_get_number_chk(vp, NULL); | |
7106 | |
7107 if (nr >= LOWEST_WIN_ID) | |
7108 return win_id2wp(tv_get_number(vp)); | |
7109 return find_win_by_nr(vp, NULL); | |
7110 } | |
7111 | |
7112 /* | |
7113 * Find window specified by "wvp" in tabpage "tvp". | |
7114 * Returns the tab page in 'ptp' | |
7115 */ | |
7116 win_T * | |
7117 find_tabwin( | |
7118 typval_T *wvp, // VAR_UNKNOWN for current window | |
7119 typval_T *tvp, // VAR_UNKNOWN for current tab page | |
7120 tabpage_T **ptp) | |
7121 { | |
7122 win_T *wp = NULL; | |
7123 tabpage_T *tp = NULL; | |
7124 long n; | |
7125 | |
7126 if (wvp->v_type != VAR_UNKNOWN) | |
7127 { | |
7128 if (tvp->v_type != VAR_UNKNOWN) | |
7129 { | |
7130 n = (long)tv_get_number(tvp); | |
7131 if (n >= 0) | |
7132 tp = find_tabpage(n); | |
7133 } | |
7134 else | |
7135 tp = curtab; | |
7136 | |
7137 if (tp != NULL) | |
7138 { | |
7139 wp = find_win_by_nr(wvp, tp); | |
7140 if (wp == NULL && wvp->v_type == VAR_NUMBER | |
7141 && wvp->vval.v_number != -1) | |
7142 // A window with the specified number is not found | |
7143 tp = NULL; | |
7144 } | |
7145 } | |
7146 else | |
7147 { | |
7148 wp = curwin; | |
7149 tp = curtab; | |
7150 } | |
7151 | |
7152 if (ptp != NULL) | |
7153 *ptp = tp; | |
7154 | |
7155 return wp; | |
7156 } | |
7157 | |
7158 /* | |
7159 * Get the layout of the given tab page for winlayout(). | |
7160 */ | |
7161 void | |
7162 get_framelayout(frame_T *fr, list_T *l, int outer) | |
7163 { | |
7164 frame_T *child; | |
7165 list_T *fr_list; | |
7166 list_T *win_list; | |
7167 | |
7168 if (fr == NULL) | |
7169 return; | |
7170 | |
7171 if (outer) | |
7172 // outermost call from f_winlayout() | |
7173 fr_list = l; | |
7174 else | |
7175 { | |
7176 fr_list = list_alloc(); | |
7177 if (fr_list == NULL) | |
7178 return; | |
7179 list_append_list(l, fr_list); | |
7180 } | |
7181 | |
7182 if (fr->fr_layout == FR_LEAF) | |
7183 { | |
7184 if (fr->fr_win != NULL) | |
7185 { | |
7186 list_append_string(fr_list, (char_u *)"leaf", -1); | |
7187 list_append_number(fr_list, fr->fr_win->w_id); | |
7188 } | |
7189 } | |
7190 else | |
7191 { | |
7192 list_append_string(fr_list, | |
7193 fr->fr_layout == FR_ROW ? (char_u *)"row" : (char_u *)"col", -1); | |
7194 | |
7195 win_list = list_alloc(); | |
7196 if (win_list == NULL) | |
7197 return; | |
7198 list_append_list(fr_list, win_list); | |
7199 child = fr->fr_child; | |
7200 while (child != NULL) | |
7201 { | |
7202 get_framelayout(child, win_list, FALSE); | |
7203 child = child->fr_next; | |
7204 } | |
7205 } | |
7206 } | |
7207 #endif |