annotate src/textobject.c @ 32460:45c426cebfcd v9.0.1561

patch 9.0.1561: display wrong when moving cursor to above the top line Commit: https://github.com/vim/vim/commit/798fa76dbf737f855e47b10bf326453866b429ab Author: Luuk van Baal <luukvbaal@gmail.com> Date: Mon May 15 18:17:43 2023 +0100 patch 9.0.1561: display wrong when moving cursor to above the top line Problem: Display wrong when moving cursor to above the top line and 'smoothscroll' is set. Solution: Call adjust_skipcol() in more places and make it work better. (Luuk van Baal, closes #12395)
author Bram Moolenaar <Bram@vim.org>
date Mon, 15 May 2023 19:30:05 +0200
parents bc6cf208b1b4
children 448aef880252
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 }
32460
45c426cebfcd patch 9.0.1561: display wrong when moving cursor to above the top line
Bram Moolenaar <Bram@vim.org>
parents: 29765
diff changeset
475 adjust_skipcol();
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 * 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
481 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 * 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
483 * 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
484 * 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
485 * '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
486 * 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
487 * 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
488 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 * 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
490 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 * 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
492 * 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
493 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 end_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 int bigword,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 int stop,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 int empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 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
502
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 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
504 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 #ifdef FEAT_FOLDING
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 // 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
509 // last line.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 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
511 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
512 #endif
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 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
515 return FAIL;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 * 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
519 * of it.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 if (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
522 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 * 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
525 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 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
527 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 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
530 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 * 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
533 * 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
534 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 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
538 && 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
539 goto finished;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 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
541 return FAIL;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 * 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
546 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 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
548 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 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
551 finished:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 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
553 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 * 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
559 *
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 * 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
561 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 bckend_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 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
567 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 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
569 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 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
572 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 while (--count >= 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 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
579 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 * 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
583 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 if (sclass != 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 while (cls() == sclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 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
588 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 * 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
593 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 while (cls() == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 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
597 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 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
599 return OK;
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 }
32460
45c426cebfcd patch 9.0.1561: display wrong when moving cursor to above the top line
Bram Moolenaar <Bram@vim.org>
parents: 29765
diff changeset
602 adjust_skipcol();
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 return OK;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 * 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
608 * 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
609 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 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
612 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 while (cls() == cclass)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 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
615 return TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 }
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 * 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
621 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 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
624 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 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
626
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 sclass = cls();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 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
631 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 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
634 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 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
643 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 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
647 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 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
649 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
650 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 incl(posp);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 break;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 * 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
659 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 static void
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 findsent_forward(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 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
664 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 findsent(FORWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 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
669 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
670 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
671 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
672 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
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 * 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
678 * 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
679 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 current_word(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 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
685 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
686 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 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
688 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 int inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 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
691
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 cls_bigword = bigword;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 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
694
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 // 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
696 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
697 dec_cursor();
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 * 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
701 * 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
702 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 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
704 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 * 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
707 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 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
710
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 * 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
713 * (" 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
714 * 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
715 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 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
719 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 * If 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
725 * 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
726 * 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
727 * 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
728 * 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
729 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 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
731 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
732 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
733 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 oneleft();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 include_white = TRUE;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 // 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
743 VIsual = start_pos;
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
744 redraw_curbuf_later(UPD_INVERTED); // update the inversion
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 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
749 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
750 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 --count;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 * 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
756 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 while (count > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 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
761 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 * 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
764 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 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
766 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 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
768 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 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
770 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 (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
777 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 else
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 * 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
783 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 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
785 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 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
787 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 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
789 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 * If 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
792 * 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
793 * 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
794 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 if (oneleft() == FAIL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 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
801 return FAIL;
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 --count;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 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
808 || (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
809 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 * 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
812 * 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
813 * 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
814 * 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
815 * (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
816 * 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
817 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 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
819 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
820 if (oneleft() == OK)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 back_in_line();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 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
824 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 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
827 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 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
829 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 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
832 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 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
837 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 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
839 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 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
842 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 oap->inclusive = inclusive;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 * 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
852 * 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
853 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 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
856 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 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
858 pos_T pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 int start_blank;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 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
862 long ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 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
865 pos = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 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
867
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 * 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
870 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 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
872 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 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
875 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 * 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
878 * 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
879 * - 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
880 * - 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
881 * - 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
882 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 at_start_sent = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 decl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 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
886 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 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
888 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
889 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 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
891 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 if (!at_start_sent)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 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
899 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
900 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 // 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
902 findsent(FORWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 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
905 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 while (count--)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 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
909 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
910 c = gchar_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 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
912 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 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
914 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 else
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 * 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
920 * 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
921 * - 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
922 * - 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
923 * - in a sentence
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 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
927 // 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
928 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
929 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 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
931 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
932 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 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
934 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
935 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 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
937 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 if (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
942 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 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
944 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
945 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 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
948 count *= 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 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
950 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
951 ++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
952 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 * 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
958 * 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
959 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 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
961 incl(&pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 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
963 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 start_blank = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 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
966 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 start_blank = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 findsent(BACKWARD, 1L);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 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
972 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 ncount = count * 2;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 ncount = count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 if (start_blank)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 --ncount;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 if (ncount > 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 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
983 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 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
985
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 if (include)
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 * 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
990 * 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
991 * 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
992 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 if (start_blank)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 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
996 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
997 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
998 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
999 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 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
1001 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
1002 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 // 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
1007 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
1008 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 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
1010 ++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
1011 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 redraw_cmdline = TRUE; // show mode later
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
1014 redraw_curbuf_later(UPD_INVERTED); // update the inversion
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 // 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
1019 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
1020 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 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
1024 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
1025 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 return OK;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 * 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
1031 * "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
1032 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 current_block(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 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
1038 int what, // '(', '{', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 int other) // ')', '}', etc.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 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
1042 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
1043 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
1044 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
1045 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
1046 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
1047 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
1048
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 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
1050 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
1051 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
1052
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 * 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
1055 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 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
1060 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 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
1062 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 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
1064 // 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
1065 ++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
1066 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 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
1071 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 old_end = VIsual;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 * 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
1077 * 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
1078 * 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
1079 * user wants.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 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
1082 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
1083 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
1084 {
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
1085 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
1086 {
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 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
1088 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
1089 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
1090 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
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 }
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 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
1094 {
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 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
1096 {
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 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
1098 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
1099 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
1100 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
1101 }
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 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
1104
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 * 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
1107 * 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
1108 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 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
1110 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 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
1112 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 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
1115
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 * 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
1118 * 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
1119 * 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
1120 * started with.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 while (!include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 incl(&start_pos);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 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
1126 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
1127 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 sol = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 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
1131 break;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 * 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
1136 * 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
1137 * 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
1138 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 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
1140 && !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
1141 && VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 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
1144 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
1145 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
1146 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 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
1148 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 start_pos = *pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 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
1152 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
1153 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 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
1155 return FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 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
1158 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 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
1166 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
1167 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
1168 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
1169 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 VIsual_mode = 'v';
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
1171 redraw_curbuf_later(UPD_INVERTED); // update the inversion
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 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
1178 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 if (sol)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 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
1181 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
1182 // 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
1183 oap->inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 // 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
1186 // 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
1187 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
1188 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 return OK;
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
29765
bc6cf208b1b4 patch 9.0.0222: no good reason why text objects are only in larger builds
Bram Moolenaar <Bram@vim.org>
parents: 29732
diff changeset
1193 #if defined(FEAT_EVAL) || defined(PROTO)
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 * 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
1196 * 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
1197 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 in_html_tag(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 int end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 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
1203 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 int lc = NUL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 pos_T pos;
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 if (enc_dbcs)
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 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
1211
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 // 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
1213 // 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
1214 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
1215 if (*p == '>' || *p == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 lc = *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 lp = p;
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 (*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
1221 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 if (lc != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 p = lp;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 }
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 else
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 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
1230 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 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
1232 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 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
1234 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
1235 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 if (*p != '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 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
1242 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
1243
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 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
1245 if (end_tag)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 // 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
1247 return *p == '/';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 // 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
1250 if (*p == '/')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 // 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
1254 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 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
1259 if (c == '>')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 lc = c;
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 return lc != '/';
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
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 * 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
1268 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 current_tagblock(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 long count_arg,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 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
1274 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 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
1276 long n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 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
1278 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
1279 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
1280 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
1281 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
1282 char_u *p;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 char_u *cp;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 int len;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 int r;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 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
1287 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
1288 int retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 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
1290
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 p_ws = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 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
1294 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
1295 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
1296 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
1297 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
1298
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 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
1301 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 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
1303 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 setpcmark();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 // ignore indent
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 while (inindent(1))
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 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
1309 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 if (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
1312 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 // 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
1314 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
1315 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
1316 break;
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 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
1319 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 // 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
1321 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
1322 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
1323 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 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
1326 }
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 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
1329 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 old_start = VIsual;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 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
1332 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 old_end = VIsual;
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 again:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 * 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
1339 * 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
1340 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343 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
1344 (char_u *)"",
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 (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
1346 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
1347 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 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
1349 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 }
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 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
1353
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 * 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
1356 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 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
1359 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
1360 ;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 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
1362 if (len == 0)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 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
1365 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
22604
3ac0ef0578ef patch 8.2.1850: "vat" does not select tags correctly over line break
Bram Moolenaar <Bram@vim.org>
parents: 20895
diff changeset
1367 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
1368 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
1369 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
1370 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 vim_free(epat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 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
1374 goto theend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 }
22604
3ac0ef0578ef patch 8.2.1850: "vat" does not select tags correctly over line break
Bram Moolenaar <Bram@vim.org>
parents: 20895
diff changeset
1376 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
1377 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
1378
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 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
1380 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
1381
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 vim_free(spat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 vim_free(epat);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 if (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
1386 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 // 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
1388 // 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
1389 // another starting tag.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 count = 1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 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
1392 goto again;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 }
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 if (do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 // 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
1398 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
1399 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
1400 break;
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 else
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 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
1405
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 // 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
1407 // 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
1408 // 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
1409 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
1410 // 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
1411 is_inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 else if (*c == '<')
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 dec_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 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
1416
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 if (!do_include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 // 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
1420 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
1421 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
1422 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
1423 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 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
1426 break;
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 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
1429
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 // 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
1431 // "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
1432 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
1433 && 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
1434 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 do_include = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 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
1437 count = count_arg;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 goto again;
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 }
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 (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 // 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
1445 // 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
1446 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
1447 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
1448 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
1449 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 VIsual = start_pos;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 VIsual_mode = 'v';
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
1452 redraw_curbuf_later(UPD_INVERTED); // update the inversion
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 showmode();
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 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 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
1458 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
1459 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
1460 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 // 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
1462 // 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
1463 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
1464 oap->inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 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
1468 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 theend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 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
1473 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 }
29765
bc6cf208b1b4 patch 9.0.0222: no good reason why text objects are only in larger builds
Bram Moolenaar <Bram@vim.org>
parents: 29732
diff changeset
1475 #endif
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 current_par(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 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
1482 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
1483 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 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
1485 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
1486 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
1487 int dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 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
1489 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
1490 int retval = OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 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
1492 int t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 int i;
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 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
1496 return FAIL;
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 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
1499
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 * 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
1502 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 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
1504 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 extend:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 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
1507 dir = BACKWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 dir = FORWARD;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 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
1511 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 if (start_lnum ==
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 (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
1514 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 retval = FAIL;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 }
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 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
1520 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
1521 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 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
1524 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
1525 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 start_lnum -= dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 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
1532 ? 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
1533 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 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
1535 || (!start_is_white
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 && 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
1537 ? 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
1538 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 start_lnum += dir;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 if (!include)
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 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
1544 ? 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
1545 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 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
1547 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 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
1550 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
1551 return retval;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 * 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
1556 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 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
1558 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
1559 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 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
1561 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 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
1566 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 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
1568 break;
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 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 }
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 * 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
1575 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 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
1577 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
1578 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 --end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 i = count;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 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
1583 --i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 while (i--)
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 (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
1587 return FAIL;
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)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 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
1591
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 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
1593 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 * 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
1597 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 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
1599 && !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
1600 && !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
1601 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 }
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 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
1605 break;
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 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 * 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
1609 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 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
1612 && 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
1613 ++end_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615
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 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
1618 * 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
1619 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 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
1621 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
1622 --start_lnum;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 // 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
1627 // 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
1628 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
1629 goto extend;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 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
1631 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 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
1633 VIsual.col = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 VIsual_mode = 'V';
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
1636 redraw_curbuf_later(UPD_INVERTED); // update the inversion
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 showmode();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 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
1642 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
1643 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
1644 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 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
1646 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
1647
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 return OK;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 * 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
1653 * 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
1654 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 * 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
1656 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 find_next_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 int col,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 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
1663 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 int c;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 c = line[col];
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 if (c == NUL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 return -1;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 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
1672 {
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 ++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
1674 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
1675 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
1676 }
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 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
1678 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 if (has_mbyte)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 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
1681 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 ++col;
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 return col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 /*
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 * 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
1689 * 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
1690 * as a quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 * 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
1692 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 static int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 find_prev_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 char_u *line,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 int col_start,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 int quotechar,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698 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
1699 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 int n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 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
1703 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 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
1706 n = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 if (escape != NULL)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 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
1709 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
1710 ++n;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 if (n & 1)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 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
1713 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
1714 break;
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 return col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718
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 * 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
1721 * 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
1722 */
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 int
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 current_quote(
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 oparg_T *oap,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 long count,
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 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
1728 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
1729 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 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
1731 int col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 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
1733 int inclusive = FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 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
1736 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
1737 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
1738 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
1739 int i;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 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
1741
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 // 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
1743 // 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
1744 // 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
1745 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 // 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
1748 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
1749 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 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
1752 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
1753 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
1754 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 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
1756 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 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
1759 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 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
1761 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 dec(&VIsual);
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 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
1764 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 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
1766 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
1767 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 // 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
1769 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
1770
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771 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
1772 VIsual = t;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 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
1774 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
1775 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 }
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 // 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
1782 // quotes.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 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
1784 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 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
1786 && 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
1787 && 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
1788 && 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
1789 i = VIsual.col;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 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
1791 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 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
1795 && 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
1796 && 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
1797 && 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
1798 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
1799 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
1800 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 // 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
1803 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
1804 {
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 // 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
1806 // 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
1807 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
1808 break;
20209
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 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
1810 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 selected_quote = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 }
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
1814 }
20209
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 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
1818 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 // 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
1820 // next quoted string.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 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
1822 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 // 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
1824 // opening quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 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
1826 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
1827 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 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
1829 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
1830 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
1831 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 // 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
1833 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
1834 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
1835 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 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
1840 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
1841 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 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
1843 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
1844 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
1845 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 // 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
1847 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
1848 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
1849 }
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 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
1855 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 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
1857
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 if (!vis_empty)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 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
1861 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
1862 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 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
1864 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 // 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
1867 // 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
1868 // 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
1869 // 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
1870 col_start = 0;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 for (;;)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 // 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
1874 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
1875 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
1876 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 // 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
1878 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
1879 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
1880 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
1881 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 // 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
1883 // target text object.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 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
1885 break;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 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
1887 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 // 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
1892 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
1893 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
1894 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 // 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
1896 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
1897 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
1898 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 // 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
1902 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
1903 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
1904 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
1905 goto abort_search;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 // 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
1909 // the starting quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 if (include)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 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
1913 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
1914 ++col_end;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 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
1917 --col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 // 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
1921 // 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
1922 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
1923 ++col_start;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 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
1925 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 // 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
1928 // 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
1929 // 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
1930 if (vis_empty
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 || (vis_bef_curs
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 && !selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 && (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 || (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
1935 && (VIsual.col == 0
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 || 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
1937 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 VIsual = curwin->w_cursor;
29732
89e1d67814a9 patch 9.0.0206: redraw flags are not named specifically
Bram Moolenaar <Bram@vim.org>
parents: 29202
diff changeset
1939 redraw_curbuf_later(UPD_INVERTED);
20209
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 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 else
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 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
1945 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
1946 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 // Set end position.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 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
1950 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
1951 || (!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
1952 ) && inc_cursor() == 2)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 inclusive = TRUE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 if (VIsual_active)
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 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
1957 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 // 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
1959 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
1960 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 else
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 // 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
1965 // 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
1966 // quote.
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 if (inside_quotes
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 || (!selected_quote
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 && 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
1970 && (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
1971 || 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
1972 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 dec_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 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
1975 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 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
1977 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 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
1979 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 VIsual_mode = 'v';
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 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
1982 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 }
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 else
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 // 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
1987 oap->inclusive = inclusive;
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
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 return OK;
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 abort_search:
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 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
1994 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 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
1996 inc_cursor();
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 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
1998 {
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 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
2000
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 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
2002 VIsual = t;
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 return FALSE;
6ca6a372fef6 patch 8.2.0660: the search.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 }