comparison src/window.c @ 17472:dfd87ef822aa v8.1.1734

patch 8.1.1734: the evalfunc.c file is too big commit https://github.com/vim/vim/commit/29b7d7a9aac591f920edb89241c8cde27378e50b Author: Bram Moolenaar <Bram@vim.org> Date: Mon Jul 22 23:03:57 2019 +0200 patch 8.1.1734: the evalfunc.c file is too big Problem: The evalfunc.c file is too big. Solution: Move some functions to other files.
author Bram Moolenaar <Bram@vim.org>
date Mon, 22 Jul 2019 23:15:05 +0200
parents 09fa437d33d8
children 984cc7258468
comparison
equal deleted inserted replaced
17471:c7151df86441 17472:dfd87ef822aa
4587 redraw_tabline = TRUE; 4587 redraw_tabline = TRUE;
4588 if (restart_edit) 4588 if (restart_edit)
4589 redraw_later(VALID); /* causes status line redraw */ 4589 redraw_later(VALID); /* causes status line redraw */
4590 4590
4591 /* set window height to desired minimal value */ 4591 /* set window height to desired minimal value */
4592 if (curwin->w_height < p_wh && !curwin->w_p_wfh) 4592 if (curwin->w_height < p_wh && !curwin->w_p_wfh
4593 #ifdef FEAT_TEXT_PROP
4594 && !popup_is_popup(curwin)
4595 #endif
4596 )
4593 win_setheight((int)p_wh); 4597 win_setheight((int)p_wh);
4594 else if (curwin->w_height == 0) 4598 else if (curwin->w_height == 0)
4595 win_setheight(1); 4599 win_setheight(1);
4596 4600
4597 /* set window width to desired minimal value */ 4601 /* set window width to desired minimal value */
6667 6671
6668 return FALSE; 6672 return FALSE;
6669 } 6673 }
6670 #endif 6674 #endif
6671 6675
6672 #if defined(FEAT_SEARCH_EXTRA) || defined(PROTO)
6673 /*
6674 * Add match to the match list of window 'wp'. The pattern 'pat' will be
6675 * highlighted with the group 'grp' with priority 'prio'.
6676 * Optionally, a desired ID 'id' can be specified (greater than or equal to 1).
6677 * If no particular ID is desired, -1 must be specified for 'id'.
6678 * Return ID of added match, -1 on failure.
6679 */
6680 int
6681 match_add(
6682 win_T *wp,
6683 char_u *grp,
6684 char_u *pat,
6685 int prio,
6686 int id,
6687 list_T *pos_list,
6688 char_u *conceal_char UNUSED) /* pointer to conceal replacement char */
6689 {
6690 matchitem_T *cur;
6691 matchitem_T *prev;
6692 matchitem_T *m;
6693 int hlg_id;
6694 regprog_T *regprog = NULL;
6695 int rtype = SOME_VALID;
6696
6697 if (*grp == NUL || (pat != NULL && *pat == NUL))
6698 return -1;
6699 if (id < -1 || id == 0)
6700 {
6701 semsg(_("E799: Invalid ID: %d (must be greater than or equal to 1)"), id);
6702 return -1;
6703 }
6704 if (id != -1)
6705 {
6706 cur = wp->w_match_head;
6707 while (cur != NULL)
6708 {
6709 if (cur->id == id)
6710 {
6711 semsg(_("E801: ID already taken: %d"), id);
6712 return -1;
6713 }
6714 cur = cur->next;
6715 }
6716 }
6717 if ((hlg_id = syn_namen2id(grp, (int)STRLEN(grp))) == 0)
6718 {
6719 semsg(_(e_nogroup), grp);
6720 return -1;
6721 }
6722 if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL)
6723 {
6724 semsg(_(e_invarg2), pat);
6725 return -1;
6726 }
6727
6728 /* Find available match ID. */
6729 while (id == -1)
6730 {
6731 cur = wp->w_match_head;
6732 while (cur != NULL && cur->id != wp->w_next_match_id)
6733 cur = cur->next;
6734 if (cur == NULL)
6735 id = wp->w_next_match_id;
6736 wp->w_next_match_id++;
6737 }
6738
6739 /* Build new match. */
6740 m = ALLOC_CLEAR_ONE(matchitem_T);
6741 m->id = id;
6742 m->priority = prio;
6743 m->pattern = pat == NULL ? NULL : vim_strsave(pat);
6744 m->hlg_id = hlg_id;
6745 m->match.regprog = regprog;
6746 m->match.rmm_ic = FALSE;
6747 m->match.rmm_maxcol = 0;
6748 # if defined(FEAT_CONCEAL)
6749 m->conceal_char = 0;
6750 if (conceal_char != NULL)
6751 m->conceal_char = (*mb_ptr2char)(conceal_char);
6752 # endif
6753
6754 /* Set up position matches */
6755 if (pos_list != NULL)
6756 {
6757 linenr_T toplnum = 0;
6758 linenr_T botlnum = 0;
6759 listitem_T *li;
6760 int i;
6761
6762 for (i = 0, li = pos_list->lv_first; li != NULL && i < MAXPOSMATCH;
6763 i++, li = li->li_next)
6764 {
6765 linenr_T lnum = 0;
6766 colnr_T col = 0;
6767 int len = 1;
6768 list_T *subl;
6769 listitem_T *subli;
6770 int error = FALSE;
6771
6772 if (li->li_tv.v_type == VAR_LIST)
6773 {
6774 subl = li->li_tv.vval.v_list;
6775 if (subl == NULL)
6776 goto fail;
6777 subli = subl->lv_first;
6778 if (subli == NULL)
6779 goto fail;
6780 lnum = tv_get_number_chk(&subli->li_tv, &error);
6781 if (error == TRUE)
6782 goto fail;
6783 if (lnum == 0)
6784 {
6785 --i;
6786 continue;
6787 }
6788 m->pos.pos[i].lnum = lnum;
6789 subli = subli->li_next;
6790 if (subli != NULL)
6791 {
6792 col = tv_get_number_chk(&subli->li_tv, &error);
6793 if (error == TRUE)
6794 goto fail;
6795 subli = subli->li_next;
6796 if (subli != NULL)
6797 {
6798 len = tv_get_number_chk(&subli->li_tv, &error);
6799 if (error == TRUE)
6800 goto fail;
6801 }
6802 }
6803 m->pos.pos[i].col = col;
6804 m->pos.pos[i].len = len;
6805 }
6806 else if (li->li_tv.v_type == VAR_NUMBER)
6807 {
6808 if (li->li_tv.vval.v_number == 0)
6809 {
6810 --i;
6811 continue;
6812 }
6813 m->pos.pos[i].lnum = li->li_tv.vval.v_number;
6814 m->pos.pos[i].col = 0;
6815 m->pos.pos[i].len = 0;
6816 }
6817 else
6818 {
6819 emsg(_("List or number required"));
6820 goto fail;
6821 }
6822 if (toplnum == 0 || lnum < toplnum)
6823 toplnum = lnum;
6824 if (botlnum == 0 || lnum >= botlnum)
6825 botlnum = lnum + 1;
6826 }
6827
6828 /* Calculate top and bottom lines for redrawing area */
6829 if (toplnum != 0)
6830 {
6831 if (wp->w_buffer->b_mod_set)
6832 {
6833 if (wp->w_buffer->b_mod_top > toplnum)
6834 wp->w_buffer->b_mod_top = toplnum;
6835 if (wp->w_buffer->b_mod_bot < botlnum)
6836 wp->w_buffer->b_mod_bot = botlnum;
6837 }
6838 else
6839 {
6840 wp->w_buffer->b_mod_set = TRUE;
6841 wp->w_buffer->b_mod_top = toplnum;
6842 wp->w_buffer->b_mod_bot = botlnum;
6843 wp->w_buffer->b_mod_xlines = 0;
6844 }
6845 m->pos.toplnum = toplnum;
6846 m->pos.botlnum = botlnum;
6847 rtype = VALID;
6848 }
6849 }
6850
6851 /* Insert new match. The match list is in ascending order with regard to
6852 * the match priorities. */
6853 cur = wp->w_match_head;
6854 prev = cur;
6855 while (cur != NULL && prio >= cur->priority)
6856 {
6857 prev = cur;
6858 cur = cur->next;
6859 }
6860 if (cur == prev)
6861 wp->w_match_head = m;
6862 else
6863 prev->next = m;
6864 m->next = cur;
6865
6866 redraw_later(rtype);
6867 return id;
6868
6869 fail:
6870 vim_free(m);
6871 return -1;
6872 }
6873
6874 /*
6875 * Delete match with ID 'id' in the match list of window 'wp'.
6876 * Print error messages if 'perr' is TRUE.
6877 */
6878 int
6879 match_delete(win_T *wp, int id, int perr)
6880 {
6881 matchitem_T *cur = wp->w_match_head;
6882 matchitem_T *prev = cur;
6883 int rtype = SOME_VALID;
6884
6885 if (id < 1)
6886 {
6887 if (perr == TRUE)
6888 semsg(_("E802: Invalid ID: %d (must be greater than or equal to 1)"),
6889 id);
6890 return -1;
6891 }
6892 while (cur != NULL && cur->id != id)
6893 {
6894 prev = cur;
6895 cur = cur->next;
6896 }
6897 if (cur == NULL)
6898 {
6899 if (perr == TRUE)
6900 semsg(_("E803: ID not found: %d"), id);
6901 return -1;
6902 }
6903 if (cur == prev)
6904 wp->w_match_head = cur->next;
6905 else
6906 prev->next = cur->next;
6907 vim_regfree(cur->match.regprog);
6908 vim_free(cur->pattern);
6909 if (cur->pos.toplnum != 0)
6910 {
6911 if (wp->w_buffer->b_mod_set)
6912 {
6913 if (wp->w_buffer->b_mod_top > cur->pos.toplnum)
6914 wp->w_buffer->b_mod_top = cur->pos.toplnum;
6915 if (wp->w_buffer->b_mod_bot < cur->pos.botlnum)
6916 wp->w_buffer->b_mod_bot = cur->pos.botlnum;
6917 }
6918 else
6919 {
6920 wp->w_buffer->b_mod_set = TRUE;
6921 wp->w_buffer->b_mod_top = cur->pos.toplnum;
6922 wp->w_buffer->b_mod_bot = cur->pos.botlnum;
6923 wp->w_buffer->b_mod_xlines = 0;
6924 }
6925 rtype = VALID;
6926 }
6927 vim_free(cur);
6928 redraw_later(rtype);
6929 return 0;
6930 }
6931
6932 /*
6933 * Delete all matches in the match list of window 'wp'.
6934 */
6935 void
6936 clear_matches(win_T *wp)
6937 {
6938 matchitem_T *m;
6939
6940 while (wp->w_match_head != NULL)
6941 {
6942 m = wp->w_match_head->next;
6943 vim_regfree(wp->w_match_head->match.regprog);
6944 vim_free(wp->w_match_head->pattern);
6945 vim_free(wp->w_match_head);
6946 wp->w_match_head = m;
6947 }
6948 redraw_later(SOME_VALID);
6949 }
6950
6951 /*
6952 * Get match from ID 'id' in window 'wp'.
6953 * Return NULL if match not found.
6954 */
6955 matchitem_T *
6956 get_match(win_T *wp, int id)
6957 {
6958 matchitem_T *cur = wp->w_match_head;
6959
6960 while (cur != NULL && cur->id != id)
6961 cur = cur->next;
6962 return cur;
6963 }
6964 #endif
6965
6966 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO) 6676 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
6967 int 6677 int
6968 get_win_number(win_T *wp, win_T *first_win) 6678 get_win_number(win_T *wp, win_T *first_win)
6969 { 6679 {
6970 int i = 1; 6680 int i = 1;