annotate src/textobject.c @ 30944:109aa4913cba v9.0.0806

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