annotate src/textobject.c @ 20626:38f728a93c07

Added tag v8.2.0866 for changeset 116c7bd5e9809107ea582a3348938c7fd4031f29
author Bram Moolenaar <Bram@vim.org>
date Sun, 31 May 2020 21:30:04 +0200
parents 6ca6a372fef6
children 56c86b167b68
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * textobject.c: functions for text objects
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 #include "vim.h"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 static int cls(void);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 static int skip_chars(int, int);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 * Find the start of the next sentence, searching in the direction specified
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 * by the "dir" argument. The cursor is positioned on the start of the next
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 * sentence when found. If the next sentence is found, return OK. Return FAIL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 * otherwise. See ":h sentence" for the precise definition of a "sentence"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 * text object.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 findsent(int dir, long count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 pos_T pos, tpos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int (*func)(pos_T *);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 int startlnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 int noskip = FALSE; // do not skip blanks
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 int cpo_J;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 int found_dot;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 if (dir == FORWARD)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 func = incl;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 func = decl;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 * if on an empty line, skip up to a non-empty line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 if (gchar_pos(&pos) == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 do
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 if ((*func)(&pos) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 while (gchar_pos(&pos) == NUL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 if (dir == FORWARD)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 goto found;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 * if on the start of a paragraph or a section and searching forward,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 * go to the next line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 else if (dir == FORWARD && pos.col == 0 &&
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 startPS(pos.lnum, NUL, FALSE))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 if (pos.lnum == curbuf->b_ml.ml_line_count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 ++pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 goto found;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 else if (dir == BACKWARD)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 // go back to the previous non-white non-punctuation character
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 found_dot = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 while (c = gchar_pos(&pos), VIM_ISWHITE(c)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 || vim_strchr((char_u *)".!?)]\"'", c) != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 tpos = pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 if (found_dot)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 if (vim_strchr((char_u *) ".!?", c) != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 found_dot = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 if (vim_strchr((char_u *) ")]\"'", c) != NULL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 && vim_strchr((char_u *) ".!?)]\"'", gchar_pos(&tpos)) == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 // remember the line where the search started
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 startlnum = pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 for (;;) // find end of sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 c = gchar_pos(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, FALSE)))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 if (dir == BACKWARD && pos.lnum != startlnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 ++pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 if (c == '.' || c == '!' || c == '?')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 tpos = pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 do
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 if ((c = inc(&tpos)) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 while (vim_strchr((char_u *)")]\"'", c = gchar_pos(&tpos))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 != NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 if (c == -1 || (!cpo_J && (c == ' ' || c == '\t')) || c == NUL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 || (cpo_J && (c == ' ' && inc(&tpos) >= 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 && gchar_pos(&tpos) == ' ')))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 pos = tpos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 if (gchar_pos(&pos) == NUL) // skip NUL at EOL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 inc(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 if ((*func)(&pos) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 if (count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 noskip = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 found:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 // skip white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 while (!noskip && ((c = gchar_pos(&pos)) == ' ' || c == '\t'))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 if (incl(&pos) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 curwin->w_cursor = pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 * Find the next paragraph or section in direction 'dir'.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 * Paragraphs are currently supposed to be separated by empty lines.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 * If 'what' is NUL we go to the next paragraph.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 * If 'what' is '{' or '}' we go to the next section.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 * If 'both' is TRUE also stop at '}'.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 * Return TRUE if the next paragraph or section was found.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 findpar(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 int *pincl, // Return: TRUE if last char is to be included
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 int dir,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 int what,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 int both)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 linenr_T curr;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 int did_skip; // TRUE after separating lines have been skipped
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 int first; // TRUE on first line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 int posix = (vim_strchr(p_cpo, CPO_PARA) != NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 linenr_T fold_first; // first line of a closed fold
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 linenr_T fold_last; // last line of a closed fold
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 int fold_skipped; // TRUE if a closed fold was skipped this
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 // iteration
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 curr = curwin->w_cursor.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 did_skip = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 for (first = TRUE; ; first = FALSE)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 if (*ml_get(curr) != NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 did_skip = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 // skip folded lines
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182 fold_skipped = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 if (first && hasFolding(curr, &fold_first, &fold_last))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185 curr = ((dir > 0) ? fold_last : fold_first) + dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 fold_skipped = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 // POSIX has its own ideas of what a paragraph boundary is and it
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 // doesn't match historical Vi: It also stops at a "{" in the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 // first column and at an empty line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 if (!first && did_skip && (startPS(curr, what, both)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 || (posix && what == NUL && *ml_get(curr) == '{')))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 if (fold_skipped)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 curr -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 if ((curr += dir) < 1 || curr > curbuf->b_ml.ml_line_count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 if (count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 curr -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 if (both && *ml_get(curr) == '}') // include line with '}'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 ++curr;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 curwin->w_cursor.lnum = curr;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 if (curr == curbuf->b_ml.ml_line_count && what != '}')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 char_u *line = ml_get(curr);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 // Put the cursor on the last character in the last line and make the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 // motion inclusive.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 if ((curwin->w_cursor.col = (colnr_T)STRLEN(line)) != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 --curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 curwin->w_cursor.col -=
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 (*mb_head_off)(line, line + curwin->w_cursor.col);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 *pincl = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 curwin->w_cursor.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 * check if the string 's' is a nroff macro that is in option 'opt'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 inmacro(char_u *opt, char_u *s)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 char_u *macro;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 for (macro = opt; macro[0]; ++macro)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 // Accept two characters in the option being equal to two characters
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 // in the line. A space in the option matches with a space in the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 // line or the line having ended.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 if ( (macro[0] == s[0]
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 || (macro[0] == ' '
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 && (s[0] == NUL || s[0] == ' ')))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 && (macro[1] == s[1]
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 || ((macro[1] == NUL || macro[1] == ' ')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 && (s[0] == NUL || s[1] == NUL || s[1] == ' '))))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 ++macro;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 if (macro[0] == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 return (macro[0] != NUL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 * startPS: return TRUE if line 'lnum' is the start of a section or paragraph.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 * If 'para' is '{' or '}' only check for sections.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 * If 'both' is TRUE also stop at '}'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 startPS(linenr_T lnum, int para, int both)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 char_u *s;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 s = ml_get(lnum);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 if (*s == para || *s == '\f' || (both && *s == '}'))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 if (*s == '.' && (inmacro(p_sections, s + 1) ||
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 (!para && inmacro(p_para, s + 1))))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 * The following routines do the word searches performed by the 'w', 'W',
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 * 'b', 'B', 'e', and 'E' commands.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 * To perform these searches, characters are placed into one of three
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 * classes, and transitions between classes determine word boundaries.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 * The classes are:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 * 0 - white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 * 1 - punctuation
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 * 2 or higher - keyword characters (letters, digits and underscore)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 static int cls_bigword; // TRUE for "W", "B" or "E"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 * cls() - returns the class of character at curwin->w_cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 * If a 'W', 'B', or 'E' motion is being done (cls_bigword == TRUE), chars
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 * from class 2 and higher are reported as class 1 since only white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 * boundaries are of interest.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 cls(void)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 c = gchar_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 if (c == ' ' || c == '\t' || c == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 return 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 if (enc_dbcs != 0 && c > 0xFF)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 // If cls_bigword, report multi-byte chars as class 1.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 if (enc_dbcs == DBCS_KOR && cls_bigword)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 // process code leading/trailing bytes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 return dbcs_class(((unsigned)c >> 8), (c & 0xFF));
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 if (enc_utf8)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 c = utf_class(c);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 if (c != 0 && cls_bigword)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 return c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 // If cls_bigword is TRUE, report all non-blanks as class 1.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 if (cls_bigword)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 if (vim_iswordc(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 return 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 * fwd_word(count, type, eol) - move forward one word
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 * Returns FAIL if the cursor was already at the end of the file.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 * If eol is TRUE, last word stops at end of line (for operators).
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 fwd_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 int bigword, // "W", "E" or "B"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 int eol)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 int sclass; // starting class
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 int last_line;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 curwin->w_cursor.coladd = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 // When inside a range of folded lines, move to the last char of the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 // last line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 coladvance((colnr_T)MAXCOL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 * We always move at least one character, unless on the last
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 * character in the buffer.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 if (i == -1 || (i >= 1 && last_line)) // started at last char in file
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 if (i >= 1 && eol && count == 0) // started at last char in line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 * Go one char past end of current word (if any)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 if (sclass != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 while (cls() == sclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 if (i == -1 || (i >= 1 && eol && count == 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 * go to next non-white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 * We'll stop if we land on a blank line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 if (curwin->w_cursor.col == 0 && *ml_get_curline() == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 if (i == -1 || (i >= 1 && eol && count == 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 * bck_word() - move backward 'count' words
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 * If stop is TRUE and we are already on the start of a word, move one less.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 * Returns FAIL if top of the file was reached.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 bck_word(long count, int bigword, int stop)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 int sclass; // starting class
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 curwin->w_cursor.coladd = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 // When inside a range of folded lines, move to the first char of the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 // first line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, NULL))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 curwin->w_cursor.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 if (dec_cursor() == -1) // started at start of file
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 if (!stop || sclass == cls() || sclass == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 * Skip white space before the word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 * Stop on an empty line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 if (curwin->w_cursor.col == 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 && LINEEMPTY(curwin->w_cursor.lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 goto finished;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 if (dec_cursor() == -1) // hit start of file, stop here
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 * Move backward to start of this word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 if (skip_chars(cls(), BACKWARD))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 inc_cursor(); // overshot - forward one
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 finished:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 stop = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 * end_word() - move to the end of the word
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 * There is an apparent bug in the 'e' motion of the real vi. At least on the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 * System V Release 3 version for the 80386. Unlike 'b' and 'w', the 'e'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 * motion crosses blank lines. When the real vi crosses a blank line in an
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 * 'e' motion, the cursor is placed on the FIRST character of the next
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 * non-blank line. The 'E' command, however, works correctly. Since this
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 * appears to be a bug, I have not duplicated it here.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 * Returns FAIL if end of the file was reached.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 * If stop is TRUE and we are already on the end of a word, move one less.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 * If empty is TRUE stop on an empty line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 end_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 int bigword,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 int stop,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 int empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 int sclass; // starting class
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 curwin->w_cursor.coladd = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 // When inside a range of folded lines, move to the last char of the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 // last line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 coladvance((colnr_T)MAXCOL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 if (inc_cursor() == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 * If we're in the middle of a word, we just have to move to the end
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 * of it.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 if (cls() == sclass && sclass != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 * Move forward to end of the current word
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 if (skip_chars(sclass, FORWARD))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 else if (!stop || sclass == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 * We were at the end of a word. Go to the end of the next word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 * First skip white space, if 'empty' is TRUE, stop at empty line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 if (empty && curwin->w_cursor.col == 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 && LINEEMPTY(curwin->w_cursor.lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 goto finished;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 if (inc_cursor() == -1) // hit end of file, stop here
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 * Move forward to the end of this word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 if (skip_chars(cls(), FORWARD))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 dec_cursor(); // overshot - one char backward
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 finished:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 stop = FALSE; // we move only one word less
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 * Move back to the end of the word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 * Returns FAIL if start of the file was reached.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 bckend_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 int bigword, // TRUE for "B"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 int eol) // TRUE: stop at end of line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 int sclass; // starting class
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 curwin->w_cursor.coladd = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 if ((i = dec_cursor()) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 if (eol && i == 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 * Move backward to before the start of this word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 if (sclass != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 while (cls() == sclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if ((i = dec_cursor()) == -1 || (eol && i == 1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 * Move backward to end of the previous word
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 if (curwin->w_cursor.col == 0 && LINEEMPTY(curwin->w_cursor.lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 if ((i = dec_cursor()) == -1 || (eol && i == 1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 * Skip a row of characters of the same class.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 * Return TRUE when end-of-file reached, FALSE otherwise.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 skip_chars(int cclass, int dir)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 while (cls() == cclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 if ((dir == FORWARD ? inc_cursor() : dec_cursor()) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 #if defined(FEAT_TEXTOBJ) || defined(PROTO)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 * Go back to the start of the word or the start of white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 back_in_line(void)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 int sclass; // starting class
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (curwin->w_cursor.col == 0) // stop at start of line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 if (cls() != sclass) // stop at start of word
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 find_first_blank(pos_T *posp)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 while (decl(posp) != -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 c = gchar_pos(posp);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 if (!VIM_ISWHITE(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 incl(posp);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 * Skip count/2 sentences and count/2 separating white spaces.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 findsent_forward(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 int at_start_sent) // cursor is at start of sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 findsent(FORWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 if (at_start_sent)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 find_first_blank(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 if (count == 0 || at_start_sent)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 at_start_sent = !at_start_sent;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 * Find word under cursor, cursor at end.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 * Used while an operator is pending, and in Visual mode.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 current_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 int include, // TRUE: include word and white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 int bigword) // FALSE == word, TRUE == WORD
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 pos_T start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 int inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 int include_white = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 CLEAR_POS(&start_pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 // Correct cursor when 'selection' is exclusive
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 if (VIsual_active && *p_sel == 'e' && LT_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 * When Visual mode is not active, or when the VIsual area is only one
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 * character, select the word and/or white space under the cursor.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 if (!VIsual_active || EQUAL_POS(curwin->w_cursor, VIsual))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 * Go to start of current word or white space.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 start_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 * If the start is on white space, and white space should be included
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 * (" word"), or start is not on white space, and white space should
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 * not be included ("word"), find end of word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 if ((cls() == 0) == include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 if (end_word(1L, bigword, TRUE, TRUE) == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 * If the start is not on white space, and white space should be
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 * included ("word "), or start is on white space and white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 * space should not be included (" "), find start of word.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * If we end up in the first column of the next line (single char
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 * word) back up to end of the line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 fwd_word(1L, bigword, TRUE);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 if (curwin->w_cursor.col == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 oneleft();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 include_white = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 // should do something when inclusive == FALSE !
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 redraw_curbuf_later(INVERTED); // update the inversion
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 oap->start = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 oap->motion_type = MCHAR;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 --count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 * When count is still > 0, extend with more objects.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 while (count > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 if (VIsual_active && LT_POS(curwin->w_cursor, VIsual))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 * In Visual mode, with cursor at start: move cursor back.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 if (decl(&curwin->w_cursor) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 if (include != (cls() != 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 if (bck_word(1L, bigword, TRUE) == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 if (bckend_word(1L, bigword, TRUE) == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 (void)incl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 * Move cursor forward one word and/or white area.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 if (incl(&curwin->w_cursor) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 if (include != (cls() == 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 if (fwd_word(1L, bigword, TRUE) == FAIL && count > 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 * If end is just past a new-line, we don't want to include
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 * the first character on the line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 * Put cursor on last char of white.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 if (oneleft() == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 if (end_word(1L, bigword, TRUE, TRUE) == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 --count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 if (include_white && (cls() != 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 || (curwin->w_cursor.col == 0 && !inclusive)))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 * If we don't include white space at the end, move the start
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 * to include some white space there. This makes "daw" work
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 * better on the last word in a sentence (and "2daw" on last-but-one
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 * word). Also when "2daw" deletes "word." at the end of the line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 * (cursor is at start of next line).
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 * But don't delete white space at start of line (indent).
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 pos = curwin->w_cursor; // save cursor position
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 if (oneleft() == OK)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 if (cls() == 0 && curwin->w_cursor.col > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 VIsual = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812 oap->start = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 curwin->w_cursor = pos; // put cursor back at end
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 if (*p_sel == 'e' && inclusive && LTOREQ_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 if (VIsual_mode == 'V')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 redraw_cmdline = TRUE; // show mode later
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 oap->inclusive = inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 * Find sentence(s) under the cursor, cursor at end.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 * When Visual active, extend it by one or more sentences.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 current_sent(oparg_T *oap, long count, int include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 pos_T start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 int start_blank;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 int at_start_sent;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 long ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 start_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 pos = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 findsent(FORWARD, 1L); // Find start of next sentence.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 * When the Visual area is bigger than one character: Extend it.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 if (VIsual_active && !EQUAL_POS(start_pos, VIsual))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 if (LT_POS(start_pos, VIsual))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 * Cursor at start of Visual area.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 * Find out where we are:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 * - in the white space before a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 * - in a sentence or just after it
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 * - at the start of a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 at_start_sent = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 while (LT_POS(pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 c = gchar_pos(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 if (!VIM_ISWHITE(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 at_start_sent = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 if (!at_start_sent)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 if (EQUAL_POS(curwin->w_cursor, start_pos))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 at_start_sent = TRUE; // exactly at start of sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 // inside a sentence, go to its end (start of next)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 findsent(FORWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 if (include) // "as" gets twice as much as "is"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 if (at_start_sent)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 find_first_blank(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 c = gchar_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 if (!at_start_sent || (!include && !VIM_ISWHITE(c)))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 at_start_sent = !at_start_sent;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 * Cursor at end of Visual area.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 * Find out where we are:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 * - just before a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 * - just before or in the white space before a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 * - in a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 at_start_sent = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 // not just before a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 if (!EQUAL_POS(pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 at_start_sent = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 while (LT_POS(pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 c = gchar_pos(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 if (!VIM_ISWHITE(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 at_start_sent = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 if (at_start_sent) // in the sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 else // in/before white before a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 if (include) // "as" gets twice as much as "is"
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 findsent_forward(count, at_start_sent);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 if (*p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 ++curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 * If the cursor started on a blank, check if it is just before the start
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 * of the next sentence.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 while (c = gchar_pos(&pos), VIM_ISWHITE(c)) // VIM_ISWHITE() is a macro
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 if (EQUAL_POS(pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 start_blank = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 find_first_blank(&start_pos); // go back to first blank
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 start_blank = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 start_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 ncount = count * 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 ncount = count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 if (start_blank)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 --ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 if (ncount > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 findsent_forward(ncount, TRUE);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 * If the blank in front of the sentence is included, exclude the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 * blanks at the end of the sentence, go back to the first blank.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 * If there are no trailing blanks, try to include leading blanks.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 if (start_blank)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 find_first_blank(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 c = gchar_pos(&curwin->w_cursor); // VIM_ISWHITE() is a macro
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 if (VIM_ISWHITE(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 else if (c = gchar_cursor(), !VIM_ISWHITE(c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 find_first_blank(&start_pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 // Avoid getting stuck with "is" on a single space before a sentence.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 if (EQUAL_POS(start_pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 if (*p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 ++curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 redraw_cmdline = TRUE; // show mode later
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 redraw_curbuf_later(INVERTED); // update the inversion
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 // include a newline after the sentence, if there is one
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (incl(&curwin->w_cursor) == -1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 oap->start = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 oap->motion_type = MCHAR;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 * Find block under the cursor, cursor at end.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 * "what" and "other" are two matching parenthesis/brace/etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 current_block(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 int include, // TRUE == include white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 int what, // '(', '{', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 int other) // ')', '}', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 pos_T old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 pos_T *pos = NULL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 pos_T start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 pos_T *end_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 pos_T old_start, old_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 char_u *save_cpo;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 int sol = FALSE; // '{' at start of line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 old_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 old_end = curwin->w_cursor; // remember where we started
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 old_start = old_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 * If we start on '(', '{', ')', '}', etc., use the whole block inclusive.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 if (what == '{') // ignore indent
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 if (inc_cursor() != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if (gchar_cursor() == what)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 // cursor on '(' or '{', move cursor just after it
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 ++curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 else if (LT_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 curwin->w_cursor = VIsual; // cursor at low end of Visual
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 old_end = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 * Search backwards for unclosed '(', '{', etc..
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 * Put this position in start_pos.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 * Ignore quotes here. Keep the "M" flag in 'cpo', as that is what the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 * user wants.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 save_cpo = p_cpo;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 p_cpo = (char_u *)(vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%");
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 while (count-- > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 if ((pos = findmatch(NULL, what)) == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 curwin->w_cursor = *pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 start_pos = *pos; // the findmatch for end_pos will overwrite *pos
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 p_cpo = save_cpo;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 * Search for matching ')', '}', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 * Put this position in curwin->w_cursor.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 if (pos == NULL || (end_pos = findmatch(NULL, other)) == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 curwin->w_cursor = *end_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 * Try to exclude the '(', '{', ')', '}', etc. when "include" is FALSE.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 * If the ending '}', ')' or ']' is only preceded by indent, skip that
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 * indent. But only if the resulting area is not smaller than what we
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 * started with.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 while (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 incl(&start_pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 sol = (curwin->w_cursor.col == 0);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 sol = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 if (decl(&curwin->w_cursor) != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 * In Visual mode, when the resulting area is not bigger than what we
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 * started with, extend it to the next block, and then exclude again.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 if (!LT_POS(start_pos, old_start) && !LT_POS(old_end, curwin->w_cursor)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 && VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 curwin->w_cursor = old_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 decl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 if ((pos = findmatch(NULL, what)) == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 start_pos = *pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 curwin->w_cursor = *pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 if ((end_pos = findmatch(NULL, other)) == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 curwin->w_cursor = *end_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 if (*p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 inc(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 if (sol && gchar_cursor() != NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 inc(&curwin->w_cursor); // include the line break
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 redraw_curbuf_later(INVERTED); // update the inversion
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 oap->start = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 oap->motion_type = MCHAR;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 if (sol)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 incl(&curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 else if (LTOREQ_POS(start_pos, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 // Include the character under the cursor.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 // End is before the start (no text in between <>, [], etc.): don't
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 // operate on any text.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 * Return TRUE if the cursor is on a "<aaa>" tag. Ignore "<aaa/>".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 * When "end_tag" is TRUE return TRUE if the cursor is on "</aaa>".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 in_html_tag(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 int end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 char_u *line = ml_get_curline();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 int lc = NUL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 if (enc_dbcs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 char_u *lp = NULL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 // We search forward until the cursor, because searching backwards is
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 // very slow for DBCS encodings.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 if (*p == '>' || *p == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 lc = *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 lp = p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 if (*p != '<') // check for '<' under cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 if (lc != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 p = lp;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 for (p = line + curwin->w_cursor.col; p > line; )
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 if (*p == '<') // find '<' under/before cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 MB_PTR_BACK(line, p);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 if (*p == '>') // find '>' before cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 if (*p != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209 pos.lnum = curwin->w_cursor.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 pos.col = (colnr_T)(p - line);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 MB_PTR_ADV(p);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 if (end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 // check that there is a '/' after the '<'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 return *p == '/';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 // check that there is no '/' after the '<'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 if (*p == '/')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 // check that the matching '>' is not preceded by '/'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 if (inc(&pos) < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 c = *ml_get_pos(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 if (c == '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 lc = c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 return lc != '/';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 * Find tag block under the cursor, cursor at end.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 current_tagblock(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 long count_arg,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 int include) // TRUE == include white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 long count = count_arg;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 long n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 pos_T old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 pos_T start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 pos_T end_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 pos_T old_start, old_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 char_u *spat, *epat;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 char_u *cp;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 int len;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 int r;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 int do_include = include;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 int save_p_ws = p_ws;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 int retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 int is_inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 p_ws = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 old_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 old_end = curwin->w_cursor; // remember where we started
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 old_start = old_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 if (!VIsual_active || *p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 decl(&old_end); // old_end is inclusive
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 * If we start on "<aaa>" select that block.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 if (!VIsual_active || EQUAL_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 // ignore indent
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 if (inc_cursor() != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 if (in_html_tag(FALSE))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 // cursor on start tag, move to its '>'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 while (*ml_get_cursor() != '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 if (inc_cursor() < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 else if (in_html_tag(TRUE))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 // cursor on end tag, move to just before it
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 while (*ml_get_cursor() != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 if (dec_cursor() < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 old_end = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 else if (LT_POS(VIsual, curwin->w_cursor))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 curwin->w_cursor = VIsual; // cursor at low end of Visual
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 old_end = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 again:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 * Search backwards for unclosed "<aaa>".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 * Put this position in start_pos.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 for (n = 0; n < count; ++n)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 if (do_searchpair((char_u *)"<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)",
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 (char_u *)"",
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 (char_u *)"</[^>]*>", BACKWARD, NULL, 0,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 NULL, (linenr_T)0, 0L) <= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 start_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 * Search for matching "</aaa>". First isolate the "aaa".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 p = ml_get_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 for (cp = p; *cp != NUL && *cp != '>' && !VIM_ISWHITE(*cp); MB_PTR_ADV(cp))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 ;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 len = (int)(cp - p);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 if (len == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 spat = alloc(len + 31);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 epat = alloc(len + 9);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 if (spat == NULL || epat == NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 vim_free(epat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 curwin->w_cursor = old_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 sprintf((char *)spat, "<%.*s\\>\\%%(\\s\\_[^>]\\{-}[^/]>\\|>\\)\\c", len, p);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 sprintf((char *)epat, "</%.*s>\\c", len, p);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 r = do_searchpair(spat, (char_u *)"", epat, FORWARD, NULL,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 0, NULL, (linenr_T)0, 0L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 vim_free(epat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 if (r < 1 || LT_POS(curwin->w_cursor, old_end))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 // Can't find other end or it's before the previous end. Could be a
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 // HTML tag that doesn't have a matching end. Search backwards for
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 // another starting tag.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 count = 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 goto again;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 if (do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 // Include up to the '>'.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 while (*ml_get_cursor() != '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 if (inc_cursor() < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 char_u *c = ml_get_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 // Exclude the '<' of the end tag.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 // If the closing tag is on new line, do not decrement cursor, but
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 // make operation exclusive, so that the linefeed will be selected
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 if (*c == '<' && !VIsual_active && curwin->w_cursor.col == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 // do not decrement cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 is_inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 else if (*c == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 end_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 if (!do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 // Exclude the start tag.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 while (inc_cursor() >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 if (*ml_get_cursor() == '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 start_pos = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 curwin->w_cursor = end_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 // If we are in Visual mode and now have the same text as before set
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 // "do_include" and try again.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 if (VIsual_active && EQUAL_POS(start_pos, old_start)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 && EQUAL_POS(end_pos, old_end))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 do_include = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 curwin->w_cursor = old_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 count = count_arg;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 goto again;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 // If the end is before the start there is no text between tags, select
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 // the char under the cursor.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 if (LT_POS(end_pos, start_pos))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 else if (*p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 redraw_curbuf_later(INVERTED); // update the inversion
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 oap->start = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 oap->motion_type = MCHAR;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 if (LT_POS(end_pos, start_pos))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 // End is before the start: there is no text between tags; operate
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 // on an empty area.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 curwin->w_cursor = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 oap->inclusive = is_inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 theend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 p_ws = save_p_ws;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 current_par(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 int include, // TRUE == include white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 int type) // 'p' for paragraph, 'S' for section
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 linenr_T start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 linenr_T end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 int white_in_front;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 int dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 int start_is_white;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 int prev_start_is_white;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 int retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 int do_white = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 int t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 if (type == 'S') // not implemented yet
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 start_lnum = curwin->w_cursor.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 * When visual area is more than one line: extend it.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 if (VIsual_active && start_lnum != VIsual.lnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 if (start_lnum < VIsual.lnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 dir = BACKWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 dir = FORWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 for (i = count; --i >= 0; )
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 if (start_lnum ==
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 prev_start_is_white = -1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 for (t = 0; t < 2; ++t)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 start_is_white = linewhite(start_lnum);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 if (prev_start_is_white == start_is_white)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 start_lnum -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 if (start_lnum == (dir == BACKWARD
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 ? 1 : curbuf->b_ml.ml_line_count))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 if (start_is_white != linewhite(start_lnum + dir)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 || (!start_is_white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 && startPS(start_lnum + (dir > 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 ? 1 : 0), 0, 0)))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 if (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 if (start_lnum == (dir == BACKWARD
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 ? 1 : curbuf->b_ml.ml_line_count))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 prev_start_is_white = start_is_white;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 curwin->w_cursor.lnum = start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 curwin->w_cursor.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 * First move back to the start_lnum of the paragraph or white lines
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 white_in_front = linewhite(start_lnum);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 while (start_lnum > 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 if (white_in_front) // stop at first white line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 if (!linewhite(start_lnum - 1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 else // stop at first non-white line of start of paragraph
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 if (linewhite(start_lnum - 1) || startPS(start_lnum, 0, 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 * Move past the end of any white lines.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 end_lnum = start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 --end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 i = count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 if (!include && white_in_front)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 --i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 while (i--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 if (end_lnum == curbuf->b_ml.ml_line_count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 if (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 do_white = linewhite(end_lnum + 1);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 if (include || !do_white)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 * skip to end of paragraph
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 while (end_lnum < curbuf->b_ml.ml_line_count
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 && !linewhite(end_lnum + 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 && !startPS(end_lnum + 1, 0, 0))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 if (i == 0 && white_in_front && include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575 * skip to end of white lines after paragraph
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 if (include || do_white)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 while (end_lnum < curbuf->b_ml.ml_line_count
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 && linewhite(end_lnum + 1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 * If there are no empty lines at the end, try to find some empty lines at
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 * the start (unless that has been done already).
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 if (!white_in_front && !linewhite(end_lnum) && include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 while (start_lnum > 1 && linewhite(start_lnum - 1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 // Problem: when doing "Vipipip" nothing happens in a single white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 // line, we get stuck there. Trap this here.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 if (VIsual_mode == 'V' && start_lnum == curwin->w_cursor.lnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 if (VIsual.lnum != start_lnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 VIsual.lnum = start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 VIsual.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 VIsual_mode = 'V';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 redraw_curbuf_later(INVERTED); // update the inversion
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 oap->start.lnum = start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 oap->start.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 oap->motion_type = MLINE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 curwin->w_cursor.lnum = end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 curwin->w_cursor.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 * Search quote char from string line[col].
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 * Quote character escaped by one of the characters in "escape" is not counted
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 * Returns column number of "quotechar" or -1 when not found.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 find_next_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 int col,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 char_u *escape) // escape characters, can be NULL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 c = line[col];
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 if (c == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 return -1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 else if (escape != NULL && vim_strchr(escape, c))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 ++col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 else if (c == quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 if (has_mbyte)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 col += (*mb_ptr2len)(line + col);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 ++col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 return col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 * Search backwards in "line" from column "col_start" to find "quotechar".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 * Quote character escaped by one of the characters in "escape" is not counted
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 * Return the found column or zero.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 find_prev_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 int col_start,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 char_u *escape) // escape characters, can be NULL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 int n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 while (col_start > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 col_start -= (*mb_head_off)(line, line + col_start);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 n = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 if (escape != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 while (col_start - n > 0 && vim_strchr(escape,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 line[col_start - n - 1]) != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 ++n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 if (n & 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 col_start -= n; // uneven number of escape chars, skip it
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 else if (line[col_start] == quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 return col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 * Find quote under the cursor, cursor at end.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 * Returns TRUE if found, else FALSE.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 current_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 int include, // TRUE == include quote char
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 int quotechar) // Quote character
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 char_u *line = ml_get_curline();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 int col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 int col_start = curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 int inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 int vis_empty = TRUE; // Visual selection <= 1 char
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 int vis_bef_curs = FALSE; // Visual starts before cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 int did_exclusive_adj = FALSE; // adjusted pos for 'selection'
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 int inside_quotes = FALSE; // Looks like "i'" done before
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 int selected_quote = FALSE; // Has quote inside selection
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 int restore_vis_bef = FALSE; // restore VIsual on abort
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 // When 'selection' is "exclusive" move the cursor to where it would be
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 // with 'selection' "inclusive", so that the logic is the same for both.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 // The cursor then is moved forward after adjusting the area.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 // this only works within one line
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 if (VIsual.lnum != curwin->w_cursor.lnum)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 vis_bef_curs = LT_POS(VIsual, curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 if (*p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 if (vis_bef_curs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 did_exclusive_adj = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 else if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 dec(&VIsual);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 did_exclusive_adj = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 vis_empty = EQUAL_POS(VIsual, curwin->w_cursor);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 if (!vis_bef_curs && !vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 // VIsual needs to be the start of Visual selection.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 pos_T t = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 curwin->w_cursor = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 VIsual = t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 vis_bef_curs = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 restore_vis_bef = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 // Check if the existing selection exactly spans the text inside
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 // quotes.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 if (vis_bef_curs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 inside_quotes = VIsual.col > 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 && line[VIsual.col - 1] == quotechar
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 && line[curwin->w_cursor.col] != NUL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 && line[curwin->w_cursor.col + 1] == quotechar;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 i = VIsual.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 col_end = curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 inside_quotes = curwin->w_cursor.col > 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 && line[curwin->w_cursor.col - 1] == quotechar
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 && line[VIsual.col] != NUL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 && line[VIsual.col + 1] == quotechar;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 i = curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 col_end = VIsual.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 // Find out if we have a quote in the selection.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 while (i <= col_end)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 if (line[i++] == quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 selected_quote = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 if (!vis_empty && line[col_start] == quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 // Already selecting something and on a quote character. Find the
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 // next quoted string.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 if (vis_bef_curs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 // Assume we are on a closing quote: move to after the next
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 // opening quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 col_start = find_next_quote(line, col_start + 1, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 if (col_start < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 col_end = find_next_quote(line, col_start + 1, quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 curbuf->b_p_qe);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 if (col_end < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 // We were on a starting quote perhaps?
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 col_end = col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 col_start = curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 col_end = find_prev_quote(line, col_start, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 if (line[col_end] != quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 col_start = find_prev_quote(line, col_end, quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 curbuf->b_p_qe);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 if (line[col_start] != quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // We were on an ending quote perhaps?
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 col_start = col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 col_end = curwin->w_cursor.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 if (line[col_start] == quotechar || !vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 int first_col = col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 if (vis_bef_curs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 first_col = find_next_quote(line, col_start, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 first_col = find_prev_quote(line, col_start, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 // The cursor is on a quote, we don't know if it's the opening or
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 // closing quote. Search from the start of the line to find out.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 // Also do this when there is a Visual area, a' may leave the cursor
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 // in between two strings.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 col_start = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 // Find open quote character.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 col_start = find_next_quote(line, col_start, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 if (col_start < 0 || col_start > first_col)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 // Find close quote character.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 col_end = find_next_quote(line, col_start + 1, quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 curbuf->b_p_qe);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 if (col_end < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 // If is cursor between start and end quote character, it is
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 // target text object.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 if (col_start <= first_col && first_col <= col_end)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 col_start = col_end + 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848 // Search backward for a starting quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 col_start = find_prev_quote(line, col_start, quotechar, curbuf->b_p_qe);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 if (line[col_start] != quotechar)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 // No quote before the cursor, look after the cursor.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 col_start = find_next_quote(line, col_start, quotechar, NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 if (col_start < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 // Find close quote character.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 col_end = find_next_quote(line, col_start + 1, quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 curbuf->b_p_qe);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 if (col_end < 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 // When "include" is TRUE, include spaces after closing quote or before
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 // the starting quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 if (VIM_ISWHITE(line[col_end + 1]))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 while (VIM_ISWHITE(line[col_end + 1]))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 ++col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 while (col_start > 0 && VIM_ISWHITE(line[col_start - 1]))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 // Set start position. After vi" another i" must include the ".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 // For v2i" include the quotes.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 if (!include && count < 2 && (vis_empty || !inside_quotes))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 ++col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 curwin->w_cursor.col = col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 // Set the start of the Visual area when the Visual area was empty, we
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 // were just inside quotes or the Visual area didn't start at a quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 // and didn't include a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 if (vis_empty
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 || (vis_bef_curs
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 && !selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 && (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 || (line[VIsual.col] != quotechar
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 && (VIsual.col == 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 || line[VIsual.col - 1] != quotechar)))))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 VIsual = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 redraw_curbuf_later(INVERTED);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 oap->start = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 oap->motion_type = MCHAR;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905 // Set end position.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 curwin->w_cursor.col = col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 if ((include || count > 1 // After vi" another i" must include the ".
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 || (!vis_empty && inside_quotes)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 ) && inc_cursor() == 2)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 if (vis_empty || vis_bef_curs)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 // decrement cursor when 'selection' is not exclusive
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 if (*p_sel != 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 // Cursor is at start of Visual area. Set the end of the Visual
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 // area when it was just inside quotes or it didn't end at a
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 // quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 if (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 || (!selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 && line[VIsual.col] != quotechar
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 && (line[VIsual.col] == NUL
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 || line[VIsual.col + 1] != quotechar)))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 VIsual = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 curwin->w_cursor.col = col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 if (VIsual_mode == 'V')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 redraw_cmdline = TRUE; // show mode later
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 // Set inclusive and other oap's flags.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 oap->inclusive = inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 abort_search:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 if (VIsual_active && *p_sel == 'e')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 if (did_exclusive_adj)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 if (restore_vis_bef)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 pos_T t = curwin->w_cursor;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 curwin->w_cursor = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 VIsual = t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 #endif // FEAT_TEXTOBJ