Mercurial > vim
comparison src/search.c @ 17476:d4b2a212fa2f v8.1.1736
patch 8.1.1736: viminfo support is spread out
commit https://github.com/vim/vim/commit/c3328169d5566b97a6a6921067017e4369dd7cd6
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jul 23 22:15:25 2019 +0200
patch 8.1.1736: viminfo support is spread out
Problem: Viminfo support is spread out.
Solution: Move more viminfo code to viminfo.c. (Yegappan Lakshmanan,
closes #4717) Reorder code to make most functions static.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 23 Jul 2019 22:30:07 +0200 |
parents | a32169a40566 |
children | daa1dea1c1b3 |
comparison
equal
deleted
inserted
replaced
17475:8584e1c0e426 | 17476:d4b2a212fa2f |
---|---|
20 static int cls(void); | 20 static int cls(void); |
21 static int skip_chars(int, int); | 21 static int skip_chars(int, int); |
22 #ifdef FEAT_FIND_ID | 22 #ifdef FEAT_FIND_ID |
23 static void show_pat_in_path(char_u *, int, | 23 static void show_pat_in_path(char_u *, int, |
24 int, int, FILE *, linenr_T *, long); | 24 int, int, FILE *, linenr_T *, long); |
25 #endif | |
26 #ifdef FEAT_VIMINFO | |
27 static void wvsp_one(FILE *fp, int idx, char *s, int sc); | |
28 #endif | 25 #endif |
29 static void search_stat(int dirc, pos_T *pos, int show_top_bot_msg, char_u *msgbuf, int recompute); | 26 static void search_stat(int dirc, pos_T *pos, int show_top_bot_msg, char_u *msgbuf, int recompute); |
30 | 27 |
31 /* | 28 /* |
32 * This file contains various searching-related routines. These fall into | 29 * This file contains various searching-related routines. These fall into |
49 * | 46 * |
50 * The actual string matching is done using a heavily modified version of | 47 * The actual string matching is done using a heavily modified version of |
51 * Henry Spencer's regular expression library. See regexp.c. | 48 * Henry Spencer's regular expression library. See regexp.c. |
52 */ | 49 */ |
53 | 50 |
54 /* The offset for a search command is store in a soff struct */ | |
55 /* Note: only spats[0].off is really used */ | |
56 struct soffset | |
57 { | |
58 int dir; /* search direction, '/' or '?' */ | |
59 int line; /* search has line offset */ | |
60 int end; /* search set cursor at end */ | |
61 long off; /* line or char offset */ | |
62 }; | |
63 | |
64 /* A search pattern and its attributes are stored in a spat struct */ | |
65 struct spat | |
66 { | |
67 char_u *pat; /* the pattern (in allocated memory) or NULL */ | |
68 int magic; /* magicness of the pattern */ | |
69 int no_scs; /* no smartcase for this pattern */ | |
70 struct soffset off; | |
71 }; | |
72 | |
73 /* | 51 /* |
74 * Two search patterns are remembered: One for the :substitute command and | 52 * Two search patterns are remembered: One for the :substitute command and |
75 * one for other searches. last_idx points to the one that was used the last | 53 * one for other searches. last_idx points to the one that was used the last |
76 * time. | 54 * time. |
77 */ | 55 */ |
78 static struct spat spats[2] = | 56 static spat_T spats[2] = |
79 { | 57 { |
80 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}, /* last used search pat */ | 58 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}}, /* last used search pat */ |
81 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}} /* last used substitute pat */ | 59 {NULL, TRUE, FALSE, {'/', 0, 0, 0L}} /* last used substitute pat */ |
82 }; | 60 }; |
83 | 61 |
88 static int last_t_cmd = TRUE; /* last search t_cmd */ | 66 static int last_t_cmd = TRUE; /* last search t_cmd */ |
89 static char_u lastc_bytes[MB_MAXBYTES + 1]; | 67 static char_u lastc_bytes[MB_MAXBYTES + 1]; |
90 static int lastc_bytelen = 1; /* >1 for multi-byte char */ | 68 static int lastc_bytelen = 1; /* >1 for multi-byte char */ |
91 | 69 |
92 /* copy of spats[], for keeping the search patterns while executing autocmds */ | 70 /* copy of spats[], for keeping the search patterns while executing autocmds */ |
93 static struct spat saved_spats[2]; | 71 static spat_T saved_spats[2]; |
94 # ifdef FEAT_SEARCH_EXTRA | 72 # ifdef FEAT_SEARCH_EXTRA |
95 static int saved_spats_last_idx = 0; | 73 static int saved_spats_last_idx = 0; |
96 static int saved_spats_no_hlsearch = 0; | 74 static int saved_spats_no_hlsearch = 0; |
97 # endif | 75 # endif |
98 | 76 |
347 #endif | 325 #endif |
348 | 326 |
349 #ifdef FEAT_SEARCH_EXTRA | 327 #ifdef FEAT_SEARCH_EXTRA |
350 // copy of spats[RE_SEARCH], for keeping the search patterns while incremental | 328 // copy of spats[RE_SEARCH], for keeping the search patterns while incremental |
351 // searching | 329 // searching |
352 static struct spat saved_last_search_spat; | 330 static spat_T saved_last_search_spat; |
353 static int did_save_last_search_spat = 0; | 331 static int did_save_last_search_spat = 0; |
354 static int saved_last_idx = 0; | 332 static int saved_last_idx = 0; |
355 static int saved_no_hlsearch = 0; | 333 static int saved_no_hlsearch = 0; |
356 | 334 |
357 /* | 335 /* |
1208 proftime_T *tm, /* timeout limit or NULL */ | 1186 proftime_T *tm, /* timeout limit or NULL */ |
1209 int *timed_out) /* flag set on timeout or NULL */ | 1187 int *timed_out) /* flag set on timeout or NULL */ |
1210 { | 1188 { |
1211 pos_T pos; /* position of the last match */ | 1189 pos_T pos; /* position of the last match */ |
1212 char_u *searchstr; | 1190 char_u *searchstr; |
1213 struct soffset old_off; | 1191 soffset_T old_off; |
1214 int retval; /* Return value */ | 1192 int retval; /* Return value */ |
1215 char_u *p; | 1193 char_u *p; |
1216 long c; | 1194 long c; |
1217 char_u *dircp; | 1195 char_u *dircp; |
1218 char_u *strcopy = NULL; | 1196 char_u *strcopy = NULL; |
5829 } | 5807 } |
5830 } | 5808 } |
5831 #endif | 5809 #endif |
5832 | 5810 |
5833 #ifdef FEAT_VIMINFO | 5811 #ifdef FEAT_VIMINFO |
5812 spat_T * | |
5813 get_spat(int idx) | |
5814 { | |
5815 return &spats[idx]; | |
5816 } | |
5817 | |
5834 int | 5818 int |
5835 read_viminfo_search_pattern(vir_T *virp, int force) | 5819 get_spat_last_idx(void) |
5836 { | 5820 { |
5837 char_u *lp; | 5821 return last_idx; |
5838 int idx = -1; | 5822 } |
5839 int magic = FALSE; | 5823 #endif |
5840 int no_scs = FALSE; | |
5841 int off_line = FALSE; | |
5842 int off_end = 0; | |
5843 long off = 0; | |
5844 int setlast = FALSE; | |
5845 #ifdef FEAT_SEARCH_EXTRA | |
5846 static int hlsearch_on = FALSE; | |
5847 #endif | |
5848 char_u *val; | |
5849 | |
5850 /* | |
5851 * Old line types: | |
5852 * "/pat", "&pat": search/subst. pat | |
5853 * "~/pat", "~&pat": last used search/subst. pat | |
5854 * New line types: | |
5855 * "~h", "~H": hlsearch highlighting off/on | |
5856 * "~<magic><smartcase><line><end><off><last><which>pat" | |
5857 * <magic>: 'm' off, 'M' on | |
5858 * <smartcase>: 's' off, 'S' on | |
5859 * <line>: 'L' line offset, 'l' char offset | |
5860 * <end>: 'E' from end, 'e' from start | |
5861 * <off>: decimal, offset | |
5862 * <last>: '~' last used pattern | |
5863 * <which>: '/' search pat, '&' subst. pat | |
5864 */ | |
5865 lp = virp->vir_line; | |
5866 if (lp[0] == '~' && (lp[1] == 'm' || lp[1] == 'M')) /* new line type */ | |
5867 { | |
5868 if (lp[1] == 'M') /* magic on */ | |
5869 magic = TRUE; | |
5870 if (lp[2] == 's') | |
5871 no_scs = TRUE; | |
5872 if (lp[3] == 'L') | |
5873 off_line = TRUE; | |
5874 if (lp[4] == 'E') | |
5875 off_end = SEARCH_END; | |
5876 lp += 5; | |
5877 off = getdigits(&lp); | |
5878 } | |
5879 if (lp[0] == '~') /* use this pattern for last-used pattern */ | |
5880 { | |
5881 setlast = TRUE; | |
5882 lp++; | |
5883 } | |
5884 if (lp[0] == '/') | |
5885 idx = RE_SEARCH; | |
5886 else if (lp[0] == '&') | |
5887 idx = RE_SUBST; | |
5888 #ifdef FEAT_SEARCH_EXTRA | |
5889 else if (lp[0] == 'h') /* ~h: 'hlsearch' highlighting off */ | |
5890 hlsearch_on = FALSE; | |
5891 else if (lp[0] == 'H') /* ~H: 'hlsearch' highlighting on */ | |
5892 hlsearch_on = TRUE; | |
5893 #endif | |
5894 if (idx >= 0) | |
5895 { | |
5896 if (force || spats[idx].pat == NULL) | |
5897 { | |
5898 val = viminfo_readstring(virp, (int)(lp - virp->vir_line + 1), | |
5899 TRUE); | |
5900 if (val != NULL) | |
5901 { | |
5902 set_last_search_pat(val, idx, magic, setlast); | |
5903 vim_free(val); | |
5904 spats[idx].no_scs = no_scs; | |
5905 spats[idx].off.line = off_line; | |
5906 spats[idx].off.end = off_end; | |
5907 spats[idx].off.off = off; | |
5908 #ifdef FEAT_SEARCH_EXTRA | |
5909 if (setlast) | |
5910 set_no_hlsearch(!hlsearch_on); | |
5911 #endif | |
5912 } | |
5913 } | |
5914 } | |
5915 return viminfo_readline(virp); | |
5916 } | |
5917 | |
5918 void | |
5919 write_viminfo_search_pattern(FILE *fp) | |
5920 { | |
5921 if (get_viminfo_parameter('/') != 0) | |
5922 { | |
5923 #ifdef FEAT_SEARCH_EXTRA | |
5924 fprintf(fp, "\n# hlsearch on (H) or off (h):\n~%c", | |
5925 (no_hlsearch || find_viminfo_parameter('h') != NULL) ? 'h' : 'H'); | |
5926 #endif | |
5927 wvsp_one(fp, RE_SEARCH, "", '/'); | |
5928 wvsp_one(fp, RE_SUBST, _("Substitute "), '&'); | |
5929 } | |
5930 } | |
5931 | |
5932 static void | |
5933 wvsp_one( | |
5934 FILE *fp, /* file to write to */ | |
5935 int idx, /* spats[] index */ | |
5936 char *s, /* search pat */ | |
5937 int sc) /* dir char */ | |
5938 { | |
5939 if (spats[idx].pat != NULL) | |
5940 { | |
5941 fprintf(fp, _("\n# Last %sSearch Pattern:\n~"), s); | |
5942 /* off.dir is not stored, it's reset to forward */ | |
5943 fprintf(fp, "%c%c%c%c%ld%s%c", | |
5944 spats[idx].magic ? 'M' : 'm', /* magic */ | |
5945 spats[idx].no_scs ? 's' : 'S', /* smartcase */ | |
5946 spats[idx].off.line ? 'L' : 'l', /* line offset */ | |
5947 spats[idx].off.end ? 'E' : 'e', /* offset from end */ | |
5948 spats[idx].off.off, /* offset */ | |
5949 last_idx == idx ? "~" : "", /* last used pat */ | |
5950 sc); | |
5951 viminfo_writestring(fp, spats[idx].pat); | |
5952 } | |
5953 } | |
5954 #endif /* FEAT_VIMINFO */ |