annotate src/textobject.c @ 29234:96ff6c230a66 v8.2.5136

patch 8.2.5136: debugger test fails when run with valgrind Commit: https://github.com/vim/vim/commit/e366ed4f2c6fa8cb663f1b9599b39d57ddbd8a2a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 19 20:13:56 2022 +0100 patch 8.2.5136: debugger test fails when run with valgrind Problem: Debugger test fails when run with valgrind. Solution: Wait longer when using valgrind.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 Jun 2022 21:15:03 +0200
parents b6c284c1f095
children 89e1d67814a9
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;
20895
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
29 pos_T prev_pos;
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 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
32 int startlnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 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
34 int cpo_J;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 int found_dot;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 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
38 if (dir == FORWARD)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 func = incl;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 func = decl;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 {
20895
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
45 prev_pos = pos;
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
46
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 * 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
49 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 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
51 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 do
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 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
54 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 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
56 if (dir == FORWARD)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 goto found;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 }
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 * 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
61 * 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
62 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 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
64 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
65 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 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
67 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 ++pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 goto found;
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 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
72 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 // 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
75 found_dot = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 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
77 || 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
78 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 tpos = pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 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
81 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 if (found_dot)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 break;
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 found_dot = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 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
89 && 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
90 break;
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 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 // 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
96 startlnum = pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 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
98
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 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
100 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 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
102 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
103 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 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
105 ++pos.lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 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
109 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 tpos = pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 do
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 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
113 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 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
115 != NULL);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 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
117 || (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
118 && gchar_pos(&tpos) == ' ')))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 pos = tpos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 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
122 inc(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123 break;
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 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
127 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 if (count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 noskip = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 found:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 // skip white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 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
137 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
138 break;
20895
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
139
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
140 if (EQUAL_POS(prev_pos, pos))
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
141 {
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
142 // didn't actually move, advance one character and try again
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
143 if ((*func)(&pos) == -1)
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
144 {
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
145 if (count)
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
146 return FAIL;
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
147 break;
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
148 }
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
149 ++count;
56c86b167b68 patch 8.2.0999: moving to next sentence gets stuck on quote
Bram Moolenaar <Bram@vim.org>
parents: 20209
diff changeset
150 }
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 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
155 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157
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 * 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
160 * 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
161 * 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
162 * 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
163 * 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
164 * 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
165 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 findpar(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 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
169 int dir,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 int what,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 int both)
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 linenr_T curr;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 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
176 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
177 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
178 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 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
180 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
181 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
182 // iteration
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 #endif
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 = 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
186
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 did_skip = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 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
191 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 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
193 did_skip = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 // skip folded lines
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 fold_skipped = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 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
199 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 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
201 fold_skipped = TRUE;
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 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 // 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
206 // 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
207 // 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
208 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
209 || (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
210 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 if (fold_skipped)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 curr -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 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
217 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 if (count)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 curr -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 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
227 ++curr;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 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
229 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
230 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 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
232
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 // 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
234 // motion inclusive.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 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
236 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 --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
238 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
239 (*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
240 *pincl = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 }
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 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 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
245 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 * 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
250 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 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
253 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 char_u *macro;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 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
257 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 // 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
259 // 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
260 // 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
261 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
262 || (macro[0] == ' '
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 && (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
264 && (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
265 || ((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
266 && (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
267 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 ++macro;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 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
270 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 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
273 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 * 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
277 * 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
278 * 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
279 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 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
282 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 char_u *s;
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 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
286 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
287 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 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
289 (!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
290 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 }
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 * 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
296 * '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
297 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
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 * 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
301 * 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
302 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 * The classes are:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 * 0 - white space
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 * 1 - punctuation
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 * 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
308 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 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
311
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 * 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
314 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 * 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
316 * 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
317 * 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
318 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 cls(void)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 c = gchar_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 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
326 return 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 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
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, 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
330 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
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 // 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
334 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
335 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 if (enc_utf8)
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 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
339 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
340 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 return c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 // 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
345 if (cls_bigword)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 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
349 return 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 return 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353
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 * 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
356 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 * 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
358 * 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
359 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 fwd_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 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
364 int eol)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 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
367 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 int last_line;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 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
371 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 // 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
376 // last line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 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
378 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
379 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 * 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
384 * 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
385 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 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
387 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 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
389 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 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
391 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392
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 * 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
395 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 if (sclass != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 while (cls() == sclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 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
401 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 }
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 * 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
406 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 while (cls() == 0)
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 * 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
411 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412 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
413 break;
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 i = inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 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
417 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 }
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 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422
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 * 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
425 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 * 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
427 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 * 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
429 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 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
432 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 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
434
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 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
436 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 // 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
441 // first line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 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
443 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
444 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 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
447 return FAIL;
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 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
450 {
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 * 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
453 * 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
454 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 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
458 && 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
459 goto finished;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 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
461 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 * 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
466 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 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
468 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 finished:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 stop = FALSE;
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 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 }
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 * 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
480 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 * 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
482 * 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
483 * 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
484 * '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
485 * 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
486 * 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
487 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 * 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
489 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 * 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
491 * 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
492 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 end_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 int bigword,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 int stop,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 int empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 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
501
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 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
503 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 // 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
508 // last line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 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
510 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
511 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 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
514 return FAIL;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 * 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
518 * of it.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 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
521 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 * 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
524 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 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
526 return FAIL;
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 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
529 {
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 * 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
532 * 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
533 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 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
537 && 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
538 goto finished;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 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
540 return FAIL;
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
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 * 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
545 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 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
547 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 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
550 finished:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551 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
552 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 return OK;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 * 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
558 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 * 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
560 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 bckend_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 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
565 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
566 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 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
568 int i;
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 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
571 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 while (--count >= 0)
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 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 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
576 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 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
578 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 * 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
582 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 if (sclass != 0)
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 while (cls() == sclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 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
587 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 * 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
592 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 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
596 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 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
598 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 }
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 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 }
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 * 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
606 * 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
607 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 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
610 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 while (cls() == cclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 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
613 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 #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
618 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 * 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
620 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 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
623 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 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
625
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 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
630 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 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
633 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 }
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 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 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
642 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 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
646 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 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
648 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
649 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 incl(posp);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 * 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
658 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 findsent_forward(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 findsent(FORWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 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
668 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
669 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
670 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
671 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
672 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674
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 * 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
677 * 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
678 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 current_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 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
684 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
685 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 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
687 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 int inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 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
690
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 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
693
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 // 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
695 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
696 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 * 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
700 * 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
701 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 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
703 {
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 * 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
706 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 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
709
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 * 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
712 * (" 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
713 * 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
714 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 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
716 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 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
718 return FAIL;
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 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 {
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 * 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
724 * 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
725 * 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
726 * 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
727 * 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
728 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 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
730 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
731 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
732 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 oneleft();
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 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 include_white = TRUE;
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 if (VIsual_active)
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 // 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
742 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 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
744 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 else
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 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
748 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
749 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 --count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 }
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 * 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
755 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 while (count > 0)
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 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 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
760 {
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 * 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
763 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 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
765 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 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
767 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 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
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 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
774 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 (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
776 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 * 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
782 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 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
784 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 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
786 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 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
788 return FAIL;
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 * 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
791 * 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
792 * 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
793 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 if (oneleft() == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 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
800 return FAIL;
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 --count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 }
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 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
807 || (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
808 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 * 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
811 * 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
812 * 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
813 * 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
814 * (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
815 * 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
816 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 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
818 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
819 if (oneleft() == OK)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 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
823 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 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
826 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 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
828 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 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
831 }
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 if (VIsual_active)
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 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
836 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 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
838 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 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
841 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 oap->inclusive = inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 return OK;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 * 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
851 * 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
852 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 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
855 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 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
857 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 int start_blank;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 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
861 long ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 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
864 pos = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 * 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
869 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 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
871 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 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
874 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 * 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
877 * 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
878 * - 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
879 * - 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
880 * - 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
881 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 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
883 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 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
885 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 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
887 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
888 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 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
890 break;
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 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 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
895 {
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 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
898 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
899 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900 // 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
901 findsent(FORWARD, 1L);
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 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
904 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 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
908 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
909 c = gchar_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 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
911 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 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
913 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 else
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 * 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
919 * 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
920 * - 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
921 * - 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
922 * - in a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 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
926 // 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
927 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
928 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 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
930 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
931 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 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
933 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
934 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 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
936 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 incl(&pos);
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 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
941 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 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
943 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
944 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 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
947 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 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
949 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
950 ++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
951 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 * 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
957 * 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
958 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 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
960 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 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
962 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 start_blank = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 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
965 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 start_blank = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 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
971 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 ncount = count * 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 ncount = count;
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 --ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 if (ncount > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 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
982 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 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
984
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 if (include)
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 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
989 * 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
990 * 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
991 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 if (start_blank)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 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
995 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
996 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
997 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
998 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 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
1000 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
1001 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 // 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
1006 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
1007 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 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
1009 ++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
1010 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 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
1013 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
1014 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 else
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 // 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
1018 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
1019 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 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
1023 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
1024 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 * 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
1030 * "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
1031 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 current_block(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 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
1037 int what, // '(', '{', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 int other) // ')', '}', etc.
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 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
1041 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
1042 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
1043 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
1044 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
1045 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
1046 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
1047
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 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
1049 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
1050 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
1051
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 * 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
1054 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 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
1056 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 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
1059 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 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
1061 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 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
1063 // 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
1064 ++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
1065 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 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
1067 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 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
1070 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 old_end = VIsual;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 * 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
1076 * 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
1077 * 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
1078 * user wants.
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 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
1081 p_cpo = (char_u *)(vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%");
25437
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1082 if ((pos = findmatch(NULL, what)) != NULL)
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 {
25437
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1084 while (count-- > 0)
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1085 {
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1086 if ((pos = findmatch(NULL, what)) == NULL)
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1087 break;
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1088 curwin->w_cursor = *pos;
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1089 start_pos = *pos; // the findmatch for end_pos will overwrite *pos
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1090 }
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1091 }
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1092 else
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1093 {
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1094 while (count-- > 0)
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1095 {
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1096 if ((pos = findmatchlimit(NULL, what, FM_FORWARD, 0)) == NULL)
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1097 break;
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1098 curwin->w_cursor = *pos;
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1099 start_pos = *pos; // the findmatch for end_pos will overwrite *pos
d4a710f06f02 patch 8.2.3255: ci" finds following string but ci< and others don't
Bram Moolenaar <Bram@vim.org>
parents: 22604
diff changeset
1100 }
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 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
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 * 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
1106 * 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
1107 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 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
1109 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 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
1114
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 * 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
1117 * 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
1118 * 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
1119 * started with.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 while (!include)
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 incl(&start_pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 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
1126 while (inindent(1))
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 sol = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 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
1130 break;
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
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 * 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
1135 * started with, extend it to the next block, and then exclude again.
28980
42e3dfd5b2d6 patch 8.2.5012: cannot select one character inside ()
Bram Moolenaar <Bram@vim.org>
parents: 28802
diff changeset
1136 * Don't try to expand the area if the area is empty.
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 if (!LT_POS(start_pos, old_start) && !LT_POS(old_end, curwin->w_cursor)
28980
42e3dfd5b2d6 patch 8.2.5012: cannot select one character inside ()
Bram Moolenaar <Bram@vim.org>
parents: 28802
diff changeset
1139 && !EQUAL_POS(start_pos, curwin->w_cursor)
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 && VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 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
1143 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
1144 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
1145 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 start_pos = *pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 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
1151 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
1152 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 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
1154 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
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 = *end_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 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 break;
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 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 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
1165 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
1166 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
1167 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
1168 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 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
1171 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 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
1176 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
1177 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 if (sol)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 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
1180 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
1181 // 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
1182 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 // 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
1185 // 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
1186 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
1187 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 * 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
1194 * 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
1195 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 in_html_tag(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 int end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 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
1201 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 int lc = NUL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 if (enc_dbcs)
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 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
1209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 // 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
1211 // 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
1212 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
1213 if (*p == '>' || *p == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 lc = *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 lp = p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 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
1219 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 if (lc != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 p = lp;
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 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
1228 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 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
1230 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 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
1232 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
1233 break;
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 if (*p != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 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
1240 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
1241
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 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
1243 if (end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 // 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
1245 return *p == '/';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 // 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
1248 if (*p == '/')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 // 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
1252 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 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
1255 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 if (c == '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 lc = c;
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 return lc != '/';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 * 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
1266 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 current_tagblock(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 long count_arg,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 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
1272 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 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
1274 long n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 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
1276 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
1277 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
1278 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
1279 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
1280 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 char_u *cp;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 int len;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 int r;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 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
1285 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
1286 int retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 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
1288
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 p_ws = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 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
1292 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
1293 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
1294 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
1295 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
1296
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 * 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
1299 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 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
1301 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 setpcmark();
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 // ignore indent
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 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
1307 break;
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 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
1310 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 // 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
1312 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
1313 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
1314 break;
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 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
1317 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 // 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
1319 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
1320 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
1321 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 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
1324 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 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
1327 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 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
1330 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 old_end = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 again:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 * 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
1337 * 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
1338 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 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
1340 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 (char_u *)"",
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 (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
1344 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
1345 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346 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
1347 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 }
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 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
1351
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 * 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
1354 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 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
1357 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
1358 ;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 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
1360 if (len == 0)
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 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
1363 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 }
22604
3ac0ef0578ef patch 8.2.1850: "vat" does not select tags correctly over line break
Bram Moolenaar <Bram@vim.org>
parents: 20895
diff changeset
1365 spat = alloc(len + 39);
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 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
1367 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
1368 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 vim_free(epat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 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
1372 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 }
22604
3ac0ef0578ef patch 8.2.1850: "vat" does not select tags correctly over line break
Bram Moolenaar <Bram@vim.org>
parents: 20895
diff changeset
1374 sprintf((char *)spat, "<%.*s\\>\\%%(\\_s\\_[^>]\\{-}\\_[^/]>\\|\\_s\\?>\\)\\c", len, p);
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 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
1376
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 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
1378 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
1379
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 vim_free(epat);
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 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
1384 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 // 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
1386 // 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
1387 // another starting tag.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 count = 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 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
1390 goto again;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 if (do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 // 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
1396 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
1397 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
1398 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 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
1403
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 // 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
1405 // 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
1406 // 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
1407 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
1408 // 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
1409 is_inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 else if (*c == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 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
1414
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 if (!do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 // 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
1418 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
1419 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
1420 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
1421 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 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
1424 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 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
1427
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 // 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
1429 // "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
1430 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
1431 && 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
1432 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 do_include = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 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
1435 count = count_arg;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 goto again;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 }
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 // 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
1443 // 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
1444 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
1445 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
1446 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
1447 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 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
1451 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 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
1456 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
1457 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
1458 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 // 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
1460 // 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
1461 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
1462 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 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
1466 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 theend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 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
1471 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 current_par(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 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
1479 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
1480 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 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
1482 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
1483 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
1484 int dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 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
1486 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
1487 int retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 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
1489 int t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 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
1493 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 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
1496
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 * 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
1499 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 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
1501 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 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
1504 dir = BACKWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 dir = FORWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 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
1508 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (start_lnum ==
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 (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
1511 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 break;
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 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
1517 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
1518 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 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
1521 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
1522 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 start_lnum -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 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
1529 ? 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
1530 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 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
1532 || (!start_is_white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 && 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
1534 ? 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
1535 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 if (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 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
1541 ? 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
1542 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 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
1544 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 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
1547 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
1548 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 * 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
1553 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 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
1555 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
1556 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 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
1558 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 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
1560 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 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
1565 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 }
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 * 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
1572 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 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
1574 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
1575 ++end_lnum;
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 --end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 i = count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 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
1580 --i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 while (i--)
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 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
1584 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 if (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 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
1588
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 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
1590 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 ++end_lnum;
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 * 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
1594 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 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
1596 && !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
1597 && !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
1598 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 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
1602 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 * 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
1606 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 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
1608 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
1609 && 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
1610 ++end_lnum;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 * 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
1615 * 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
1616 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 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
1618 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
1619 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 // 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
1624 // 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
1625 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
1626 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 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
1628 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 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
1630 VIsual.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 VIsual_mode = 'V';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633 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
1634 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 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
1639 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
1640 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
1641 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 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
1643 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
1644
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 return OK;
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
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 * 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
1650 * 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
1651 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 * 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
1653 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 find_next_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 int col,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 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
1660 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 int c;
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 for (;;)
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 c = line[col];
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 if (c == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 return -1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 else if (escape != NULL && vim_strchr(escape, c))
28802
1ab5add6f4e8 patch 8.2.4925: trailing backslash may cause reading past end of line
Bram Moolenaar <Bram@vim.org>
parents: 25437
diff changeset
1669 {
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 ++col;
28802
1ab5add6f4e8 patch 8.2.4925: trailing backslash may cause reading past end of line
Bram Moolenaar <Bram@vim.org>
parents: 25437
diff changeset
1671 if (line[col] == NUL)
1ab5add6f4e8 patch 8.2.4925: trailing backslash may cause reading past end of line
Bram Moolenaar <Bram@vim.org>
parents: 25437
diff changeset
1672 return -1;
1ab5add6f4e8 patch 8.2.4925: trailing backslash may cause reading past end of line
Bram Moolenaar <Bram@vim.org>
parents: 25437
diff changeset
1673 }
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 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
1675 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 if (has_mbyte)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 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
1678 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 ++col;
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 return col;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 * 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
1686 * 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
1687 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 * 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
1689 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 find_prev_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 int col_start,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 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
1696 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 int n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 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
1700 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 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
1703 n = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 if (escape != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 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
1706 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
1707 ++n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 if (n & 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 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
1710 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
1711 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 return col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 * 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
1718 * 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
1719 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 current_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 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
1725 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
1726 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 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
1728 int col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 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
1730 int inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 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
1732 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
1733 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
1734 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
1735 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
1736 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 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
1738
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 // 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
1740 // 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
1741 // 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
1742 if (VIsual_active)
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 // 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
1745 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
1746 return FALSE;
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 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
1749 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
1750 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
1751 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 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
1753 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 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
1756 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 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
1758 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 dec(&VIsual);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 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
1761 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 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
1763 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
1764 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 // 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
1766 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
1767
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 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
1769 VIsual = t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 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
1771 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
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 }
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 if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 // 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
1779 // quotes.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 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
1781 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 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
1783 && 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
1784 && 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
1785 && 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
1786 i = VIsual.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 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
1788 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 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
1792 && 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
1793 && 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
1794 && 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
1795 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
1796 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
1797 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 // 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
1800 while (i <= col_end)
29202
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1801 {
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1802 // check for going over the end of the line, which can happen if
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1803 // the line was changed after the Visual area was selected.
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1804 if (line[i] == NUL)
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1805 break;
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 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
1807 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 selected_quote = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 }
29202
b6c284c1f095 patch 8.2.5120: searching for quotes may go over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 28980
diff changeset
1811 }
20209
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 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
1815 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 // 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
1817 // next quoted string.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 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
1819 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 // 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
1821 // opening quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 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
1823 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
1824 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826 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
1827 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
1828 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 // 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
1830 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
1831 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
1832 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 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
1837 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
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 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
1840 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
1841 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
1842 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 // 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
1844 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
1845 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
1846 }
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 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
1852 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 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
1854
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 if (!vis_empty)
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 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
1858 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
1859 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 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
1861 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 // 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
1864 // 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
1865 // 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
1866 // 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
1867 col_start = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 // 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
1871 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
1872 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
1873 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 // 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
1875 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
1876 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
1877 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
1878 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 // 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
1880 // target text object.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 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
1882 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 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
1884 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 // 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
1889 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
1890 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
1891 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 // 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
1893 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
1894 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
1895 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 }
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 // 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
1899 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
1900 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
1901 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
1902 goto abort_search;
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 // 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
1906 // the starting quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 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
1910 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
1911 ++col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 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
1914 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 // 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
1918 // 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
1919 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
1920 ++col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 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
1922 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 // 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
1925 // 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
1926 // 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
1927 if (vis_empty
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 || (vis_bef_curs
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 && !selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 && (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 || (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
1932 && (VIsual.col == 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 || 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
1934 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 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
1936 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
1937 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 else
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 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
1942 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
1943 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 // Set end position.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 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
1947 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
1948 || (!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
1949 ) && inc_cursor() == 2)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 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
1954 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 // 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
1956 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
1957 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 else
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 // 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
1962 // 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
1963 // quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 if (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 || (!selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 && 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
1967 && (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
1968 || 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
1969 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 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
1972 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 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
1974 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 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
1976 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 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
1979 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 // 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
1984 oap->inclusive = inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 abort_search:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 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
1991 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 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
1993 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 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
1995 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 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
1997
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 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
1999 VIsual = t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 #endif // FEAT_TEXTOBJ