annotate src/misc1.c @ 15819:806c95deeb61

Added tag v8.1.0916 for changeset 89486329d9e645c31aed81bf36d6cf0cdf314b69
author Bram Moolenaar <Bram@vim.org>
date Thu, 14 Feb 2019 13:30:15 +0100
parents 99ebf78686a9
children 7fad90423bd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 10002
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * misc1.c: functions that didn't seem to fit elsewhere
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "version.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
14133
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
17 #if defined(FEAT_CMDL_COMPL) && defined(WIN3264)
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
18 # include <lm.h>
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
19 #endif
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
20
7803
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
21 static char_u *vim_version_dir(char_u *vimdir);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
22 static char_u *remove_tail(char_u *p, char_u *pend, char_u *name);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23
15814
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
24 #define URL_SLASH 1 /* path_is_url() has found "://" */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
25 #define URL_BACKSLASH 2 /* path_is_url() has found ":\\" */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
26
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
27 /* All user names (for ~user completion as done by shell). */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
28 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
29 static garray_T ga_users;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
30 #endif
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
31
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 * Count the size (in window cells) of the indent in the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
36 get_indent(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
38 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
39 return get_indent_str_vtab(ml_get_curline(), (int)curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
40 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
41 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
42 return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
43 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 * Count the size (in window cells) of the indent in line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
50 get_indent_lnum(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
52 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
53 return get_indent_str_vtab(ml_get(lnum), (int)curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
54 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
55 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
56 return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
57 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 #if defined(FEAT_FOLDING) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 * Count the size (in window cells) of the indent in line "lnum" of buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 * "buf".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
66 get_indent_buf(buf_T *buf, linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
68 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
69 return get_indent_str_vtab(ml_get_buf(buf, lnum, FALSE),
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
70 (int)curbuf->b_p_ts, buf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
71 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
72 return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
73 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 * count the size (in window cells) of the indent in line "ptr", with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 * 'tabstop' at "ts"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 */
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
81 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
82 get_indent_str(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
83 char_u *ptr,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
84 int ts,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
85 int list) /* if TRUE, count only screen size for tabs */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 for ( ; *ptr; ++ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
91 if (*ptr == TAB)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
92 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
93 if (!list || lcs_tab1) /* count a tab for what it is worth */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
94 count += ts - (count % ts);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
95 else
6174
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
96 /* In list mode, when tab is not set, count screen char width
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
97 * for Tab, displays: ^I */
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
98 count += ptr2cells(ptr);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
99 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 else if (*ptr == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 ++count; /* count a space for one */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 }
164
8b0ee9d57d7f updated for version 7.0050
vimboss
parents: 135
diff changeset
105 return count;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
108 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
109 /*
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
110 * Count the size (in window cells) of the indent in line "ptr", using
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
111 * variable tabstops.
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
112 * if "list" is TRUE, count only screen size for tabs.
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
113 */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
114 int
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
115 get_indent_str_vtab(char_u *ptr, int ts, int *vts, int list)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
116 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
117 int count = 0;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
118
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
119 for ( ; *ptr; ++ptr)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
120 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
121 if (*ptr == TAB) /* count a tab for what it is worth */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
122 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
123 if (!list || lcs_tab1)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
124 count += tabstop_padding(count, ts, vts);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
125 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
126 /* In list mode, when tab is not set, count screen char width
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
127 * for Tab, displays: ^I */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
128 count += ptr2cells(ptr);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
129 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
130 else if (*ptr == ' ')
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
131 ++count; /* count a space for one */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
132 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
133 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
134 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
135 return count;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
136 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
137 #endif
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
138
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 * Set the indent of the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 * Leaves the cursor on the first non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 * Caller must take care of undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 * "flags":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 * SIN_CHANGED: call changed_bytes() if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 * SIN_INSERT: insert the indent in front of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 * SIN_UNDO: save line for undo before changing it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 * Returns TRUE if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
150 set_indent(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
151 int size, /* measured in spaces */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
152 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 char_u *newline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 char_u *oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 int todo;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
159 int ind_len; /* measured in characters */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 int line_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 int doit = FALSE;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
162 int ind_done = 0; /* measured in spaces */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
163 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
164 int ind_col = 0;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
165 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 int tab_pad;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
167 int retval = FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
168 int orig_char_len = -1; /* number of initial whitespace chars when
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
169 'et' and 'pi' are both set */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 * First check if there is anything to do and compute the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 * characters needed for the indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 todo = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 ind_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 p = oldline = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 /* Calculate the buffer size for the new indent, and check to see if it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 * isn't already set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
182 /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
183 * 'preserveindent' are set count the number of characters at the
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
184 * beginning of the line to be copied */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
185 if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 /* count as many characters as we can use */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
194 while (todo > 0 && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
198 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
199 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
200 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
201 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
204 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
221 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
222 /* These diverge from this point. */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
223 ind_col = ind_done;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
224 #endif
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
225 /* Set initial number of whitespace chars to copy if we are
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
226 * preserving indent but expandtab is set */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
227 if (curbuf->b_p_et)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
228 orig_char_len = ind_len;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
229
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 /* Fill to next tabstop with a tab, if possible */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
231 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
232 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
233 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
234 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
236 #endif
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
237 if (todo >= tab_pad && orig_char_len == -1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 /* ind_done += tab_pad; */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
243 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
244 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
245 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 /* count tabs required for indent */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
250 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
251 for (;;)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
252 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
253 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
254 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
255 if (todo < tab_pad)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
256 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
257 if (*p != TAB)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
258 doit = TRUE;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
259 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
260 ++p;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
261 todo -= tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
262 ++ind_len;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
263 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
264 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
265 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 if (*p != TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 /* ind_done += (int)curbuf->b_p_ts; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 }
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
276 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 /* count spaces required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 if (*p != ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 doit = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 ++ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 /* ++ind_done; */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 /* Return if the indent is OK already. */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
291 if (!doit && !VIM_ISWHITE(*p) && !(flags & SIN_INSERT))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 /* Allocate memory for the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 if (flags & SIN_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 line_len = (int)STRLEN(p) + 1;
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
300
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
301 /* If 'preserveindent' and 'expandtab' are both set keep the original
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
302 * characters and allocate accordingly. We will fill the rest with spaces
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
303 * after the if (!curbuf->b_p_et) below. */
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
304 if (orig_char_len != -1)
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
305 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
306 newline = alloc(orig_char_len + size - ind_done + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
307 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
308 return FALSE;
1359
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
309 todo = size - ind_done;
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
310 ind_len = orig_char_len + todo; /* Set total length of indent in
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
311 * characters, which may have been
a66a49322b6b updated for version 7.1-073
vimboss
parents: 1348
diff changeset
312 * undercounted until now */
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
313 p = oldline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
314 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
315 while (orig_char_len > 0)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
316 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
317 *s++ = *p++;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
318 orig_char_len--;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
319 }
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
320
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
321 /* Skip over any additional white space (useful when newindent is less
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
322 * than old) */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
323 while (VIM_ISWHITE(*p))
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
324 ++p;
1348
17a83c0532e8 updated for version 7.1-062
vimboss
parents: 1341
diff changeset
325
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
326 }
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
327 else
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
328 {
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
329 todo = size;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
330 newline = alloc(ind_len + line_len);
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
331 if (newline == NULL)
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
332 return FALSE;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
333 s = newline;
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
334 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 /* Put the characters in the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 /* if 'expandtab' isn't set: use TABs */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 if (!curbuf->b_p_et)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 /* If 'preserveindent' is set then reuse as much as possible of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 * the existing indent structure for the new indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 if (!(flags & SIN_INSERT) && curbuf->b_p_pi)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 p = oldline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 ind_done = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
347 while (todo > 0 && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 if (*p == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
351 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
352 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
353 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
354 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
357 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 /* stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 ind_done += tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 ++ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 *s++ = *p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 /* Fill to next tabstop with a tab, if possible */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
373 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
374 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
375 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
376 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
378 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 if (todo >= tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 todo -= tab_pad;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
383 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
384 ind_done += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
385 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 p = skipwhite(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
391 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
392 for (;;)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
393 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
394 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
395 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
396 if (todo < tab_pad)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
397 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
398 *s++ = TAB;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
399 todo -= tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
400 ind_done += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
401 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
402 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 while (todo >= (int)curbuf->b_p_ts)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 *s++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 todo -= (int)curbuf->b_p_ts;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 }
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
408 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 *s++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 mch_memmove(s, p, (size_t)line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
417 // Replace the line (unless undo fails).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 if (!(flags & SIN_UNDO) || u_savesub(curwin->w_cursor.lnum) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 ml_replace(curwin->w_cursor.lnum, newline, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 if (flags & SIN_CHANGED)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 changed_bytes(curwin->w_cursor.lnum, 0);
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
423
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
424 // Correct saved cursor position if it is in this line.
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
425 if (saved_cursor.lnum == curwin->w_cursor.lnum)
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
426 {
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
427 if (saved_cursor.col >= (colnr_T)(p - oldline))
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
428 // cursor was after the indent, adjust for the number of
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
429 // bytes added/removed
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
430 saved_cursor.col += ind_len - (colnr_T)(p - oldline);
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
431 else if (saved_cursor.col >= (colnr_T)(s - newline))
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
432 // cursor was in the indent, and is now after it, put it back
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
433 // at the start of the indent (replacing spaces with TAB)
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
434 saved_cursor.col = (colnr_T)(s - newline);
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
435 }
15398
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
436 #ifdef FEAT_TEXT_PROP
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
437 adjust_prop_columns(curwin->w_cursor.lnum, (colnr_T)(p - oldline),
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
438 ind_len - (colnr_T)(p - oldline));
3e02464faaac patch 8.1.0707: text property columns are not adjusted for changed indent
Bram Moolenaar <Bram@vim.org>
parents: 15347
diff changeset
439 #endif
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
440 retval = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 vim_free(newline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 curwin->w_cursor.col = ind_len;
217
89114a6baf3c updated for version 7.0061
vimboss
parents: 196
diff changeset
446 return retval;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 * Copy the indent from ptr to the current line (and fill to size)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 * Leaves the cursor on the first non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 * Returns TRUE if the line was changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
455 copy_indent(int size, char_u *src)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 char_u *p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 char_u *line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 int todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 int ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 int line_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 int tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 int ind_done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 int round;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
466 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
467 int ind_col;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
468 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 /* Round 1: compute the number of characters needed for the indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 * Round 2: copy the characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 for (round = 1; round <= 2; ++round)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 todo = size;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 ind_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 ind_done = 0;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
477 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
478 ind_col = 0;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
479 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 s = src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 /* Count/copy the usable portion of the source line */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
483 while (todo > 0 && VIM_ISWHITE(*s))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 if (*s == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 {
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
487 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
488 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
489 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
490 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 tab_pad = (int)curbuf->b_p_ts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
493 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 /* Stop if this tab will overshoot the target */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 if (todo < tab_pad)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 ind_done += tab_pad;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
499 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
500 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
501 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 ++ind_done;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
507 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
508 ++ind_col;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
509 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
512 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 *p++ = *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 ++s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 /* Fill to next tabstop with a tab, if possible */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
518 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
519 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
520 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
521 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
523 #endif
3058
4a7097153089 updated for version 7.3.301
Bram Moolenaar <bram@vim.org>
parents: 2984
diff changeset
524 if (todo >= tab_pad && !curbuf->b_p_et)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 todo -= tab_pad;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 ++ind_len;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
528 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
529 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
530 #endif
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
531 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 *p++ = TAB;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 /* Add tabs required for indent */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
536 if (!curbuf->b_p_et)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
537 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
538 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
539 for (;;)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
540 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
541 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
542 curbuf->b_p_vts_array);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
543 if (todo < tab_pad)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
544 break;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
545 todo -= tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
546 ++ind_len;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
547 ind_col += tab_pad;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
548 if (p != NULL)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
549 *p++ = TAB;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
550 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
551 #else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
552 while (todo >= (int)curbuf->b_p_ts)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
553 {
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
554 todo -= (int)curbuf->b_p_ts;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
555 ++ind_len;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
556 if (p != NULL)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
557 *p++ = TAB;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
558 }
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
559 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 /* Count/add spaces required for indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 while (todo > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 --todo;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 ++ind_len;
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
567 if (p != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 *p++ = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570
840
2c885fab04e3 updated for version 7.0e06
vimboss
parents: 838
diff changeset
571 if (p == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 /* Allocate memory for the result: the copied indent, new indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 * and the rest of the line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 line_len = (int)STRLEN(ml_get_curline()) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 line = alloc(ind_len + line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 if (line == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 p = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 /* Append the original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 mch_memmove(p, ml_get_curline(), (size_t)line_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 /* Replace the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 ml_replace(curwin->w_cursor.lnum, line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 /* Put the cursor after the indent. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 curwin->w_cursor.col = ind_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 * Return the indent of the current line after a number. Return -1 if no
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 * number was found. Used for 'n' in 'formatoptions': numbered list.
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
597 * Since a pattern is used it can actually handle more than numbers.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
600 get_number_indent(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
605 regmatch_T regmatch;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
606 int lead_len = 0; /* length of comment leader */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
607
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 if (lnum > curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 return -1;
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
610 pos.lnum = 0;
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
611
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
612 #ifdef FEAT_COMMENTS
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
613 /* In format_lines() (i.e. not insert mode), fo+=q is needed too... */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
614 if ((State & INSERT) || has_format_option(FO_Q_COMS))
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
615 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
3632
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
616 #endif
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
617 regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
618 if (regmatch.regprog != NULL)
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
619 {
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
620 regmatch.rm_ic = FALSE;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
621
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
622 /* vim_regexec() expects a pointer to a line. This lets us
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
623 * start matching for the flp beyond any comment leader... */
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
624 if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
625 {
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
626 pos.lnum = lnum;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
627 pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
628 pos.coladd = 0;
7e3fedfc3d08 updated for version 7.3.576
Bram Moolenaar <bram@vim.org>
parents: 3608
diff changeset
629 }
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
630 vim_regfree(regmatch.regprog);
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
631 }
41
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
632
f529edb9bab3 updated for version 7.0025
vimboss
parents: 39
diff changeset
633 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 return -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 getvcol(curwin, &pos, &col, NULL, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 return (int)col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
639 #if defined(FEAT_LINEBREAK) || defined(PROTO)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
640 /*
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
641 * Return appropriate space number for breakindent, taking influencing
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
642 * parameters into account. Window must be specified, since it is not
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
643 * necessarily always the current one.
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
644 */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
645 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
646 get_breakindent_win(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
647 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
648 char_u *line) /* start of the line */
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
649 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
650 static int prev_indent = 0; /* cached indent value */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
651 static long prev_ts = 0L; /* cached tabstop value */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
652 static char_u *prev_line = NULL; /* cached pointer to line */
10889
5780bd3a5a7e patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents: 10807
diff changeset
653 static varnumber_T prev_tick = 0; /* changedtick of cached value */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
654 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
655 static int *prev_vts = NULL; /* cached vartabs values */
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
656 #endif
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
657 int bri = 0;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
658 /* window width minus window margin space, i.e. what rests for text */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
659 const int eff_wwidth = wp->w_width
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
660 - ((wp->w_p_nu || wp->w_p_rnu)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
661 && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
662 ? number_width(wp) + 1 : 0);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
663
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
664 /* used cached indent, unless pointer or 'tabstop' changed */
6010
ea2c5dfee1b0 updated for version 7.4.345
Bram Moolenaar <bram@vim.org>
parents: 5995
diff changeset
665 if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
666 || prev_tick != CHANGEDTICK(wp->w_buffer)
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
667 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
668 || prev_vts != wp->w_buffer->b_p_vts_array
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
669 #endif
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
670 )
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
671 {
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
672 prev_line = line;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
673 prev_ts = wp->w_buffer->b_p_ts;
10952
835604f3c37a patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents: 10932
diff changeset
674 prev_tick = CHANGEDTICK(wp->w_buffer);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
675 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
676 prev_vts = wp->w_buffer->b_p_vts_array;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
677 prev_indent = get_indent_str_vtab(line,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
678 (int)wp->w_buffer->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
679 wp->w_buffer->b_p_vts_array, wp->w_p_list);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
680 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
681 prev_indent = get_indent_str(line,
6012
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
682 (int)wp->w_buffer->b_p_ts, wp->w_p_list);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
683 #endif
6012
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
684 }
3248c6e40aee updated for version 7.4.346
Bram Moolenaar <bram@vim.org>
parents: 6010
diff changeset
685 bri = prev_indent + wp->w_p_brishift;
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
686
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
687 /* indent minus the length of the showbreak string */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
688 if (wp->w_p_brisbr)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
689 bri -= vim_strsize(p_sbr);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
690
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
691 /* Add offset for number column, if 'n' is in 'cpoptions' */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
692 bri += win_col_off2(wp);
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
693
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
694 /* never indent past left window margin */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
695 if (bri < 0)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
696 bri = 0;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
697 /* always leave at least bri_min characters on the left,
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
698 * if text width is sufficient */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
699 else if (bri > eff_wwidth - wp->w_p_brimin)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
700 bri = (eff_wwidth - wp->w_p_brimin < 0)
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
701 ? 0 : eff_wwidth - wp->w_p_brimin;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
702
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
703 return bri;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
704 }
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
705 #endif
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
706
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
707
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 * open_line: Add a new line below or above the current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 * For VREPLACE mode, we only add a new line when we get to the end of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 * file, otherwise we just start replacing the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 * Caller must take care of undo. Since VREPLACE may affect any number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 * lines however, it may call u_save_cursor() again when starting to change a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 * new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 * "flags": OPENLINE_DELSPACES delete spaces after cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 * OPENLINE_DO_COM format comments
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 * OPENLINE_KEEPTRAIL keep trailing spaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 * OPENLINE_MARKFIX adjust mark positions after the line break
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
721 * OPENLINE_COM_LIST format comments with list or 2nd line indent
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
722 *
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
723 * "second_line_indent": indent for after ^^D in Insert mode or if flag
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
724 * OPENLINE_COM_LIST
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 *
13772
cc21507ee4b1 patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents: 13768
diff changeset
726 * Return OK for success, FAIL for failure
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
729 open_line(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
730 int dir, /* FORWARD or BACKWARD */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
731 int flags,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
732 int second_line_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 char_u *saved_line; /* copy of the original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 char_u *next_line = NULL; /* copy of the next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 char_u *p_extra = NULL; /* what goes to next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 int less_cols = 0; /* less columns for mark in new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 int less_cols_off = 0; /* columns to skip for mark adjust */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 pos_T old_cursor; /* old cursor position */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 int newcol = 0; /* new cursor column */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 int newindent = 0; /* auto-indent of the new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 int trunc_line = FALSE; /* truncate current line afterwards */
13772
cc21507ee4b1 patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents: 13768
diff changeset
744 int retval = FAIL; /* return value */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 int extra_len = 0; /* length of p_extra string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 int lead_len; /* length of comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 char_u *lead_flags; /* position in 'comments' for comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 char_u *leader = NULL; /* copy of comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 char_u *allocated = NULL; /* allocated memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 int saved_char = NUL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 #if defined(FEAT_SMARTINDENT) || defined(FEAT_COMMENTS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 pos_T *pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 int do_si = (!p_paste && curbuf->b_p_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 && !curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 # endif
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 11678
diff changeset
762 # ifdef FEAT_EVAL
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 11678
diff changeset
763 && *curbuf->b_p_inde == NUL
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 11678
diff changeset
764 # endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 );
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 int no_si = FALSE; /* reset did_si afterwards */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 int first_char = NUL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 #endif
14424
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
769 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 int vreplace_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 int did_append; /* appended a new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 int saved_pi = curbuf->b_p_pi; /* copy of preserveindent setting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 * make a copy of the current line so we can mess with it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 saved_line = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 if (saved_line == NULL) /* out of memory! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 * With VREPLACE we make a copy of the next line, which we will be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 * starting to replace. First make the new line empty and let vim play
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 * with the indenting and comment leader to its heart's content. Then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 * we grab what it ended up putting on the new line, put back the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 * original line, and call ins_char() to put each new character onto
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 * the line, replacing what was there before and pushing the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 * stuff onto the replace stack. -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 if (curwin->w_cursor.lnum < orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 next_line = vim_strsave(ml_get(curwin->w_cursor.lnum + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 next_line = vim_strsave((char_u *)"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 if (next_line == NULL) /* out of memory! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 * In VREPLACE mode, a NL replaces the rest of the line, and starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 * replacing the next line, so push all of the characters left on the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 * line onto the replace stack. We'll push any other characters that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 * might be replaced at the start of the next line (due to autoindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 * etc) a bit later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 replace_push(NUL); /* Call twice because BS over NL expects it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 p = saved_line + curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 while (*p != NUL)
1470
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
811 {
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
812 if (has_mbyte)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
813 p += replace_push_mb(p);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
814 else
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
815 replace_push(*p++);
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
816 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
817 saved_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 }
14424
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
819
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
820 if ((State & INSERT) && !(State & VREPLACE_FLAG))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 p_extra = saved_line + curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 if (do_si) /* need first char after new line break */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 p = skipwhite(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 first_char = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
830 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
831 extra_len = (int)STRLEN(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 saved_char = *p_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 *p_extra = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 u_clearline(); /* cannot do "U" command when adding lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 ai_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 * If we just did an auto-indent, then we didn't type anything on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 * the prior line, and it should be truncated. Do this even if 'ai' is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 * set because automatically inserting a comment leader also sets did_ai.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 if (dir == FORWARD && did_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 trunc_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 * If 'autoindent' and/or 'smartindent' is set, try to figure out what
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 * indent to use for the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 if (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 * count white space on current line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
864 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
865 newindent = get_indent_str_vtab(saved_line, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
866 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
867 #else
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
868 newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, FALSE);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
869 #endif
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
870 if (newindent == 0 && !(flags & OPENLINE_COM_LIST))
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
871 newindent = second_line_indent; /* for ^^D command in insert mode */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 * Do smart indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 * In insert/replace mode (only when dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 * we may move some text to the next line. If it starts with '{'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 * don't add an indent. Fixes inserting a NL before '{' in line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 * "if (condition) {"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 if (!trunc_line && do_si && *saved_line != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 && (p_extra == NULL || first_char != '{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 char_u last_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 ptr = saved_line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 if (flags & OPENLINE_DO_COM)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
891 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 * Skip preprocessor directives, unless they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 * recognised as comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 lead_len == 0 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 ptr[0] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 while (ptr[0] == '#' && curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 ptr = ml_get(--curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 if (flags & OPENLINE_DO_COM)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
913 lead_len = get_leader_len(ptr, NULL, FALSE, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 * This case gets the following right:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 * \*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 * * A comment (read '\' as '/').
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 * *\
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 * #define IN_THE_WAY
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 * This should line up here;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 p = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 if (p[0] == '/' && p[1] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 p++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
929 if (p[0] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 for (p++; *p; p++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933 if (p[0] == '/' && p[-1] == '*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 * End of C comment, indent should line up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 * with the line containing the start of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 * the comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 curwin->w_cursor.col = (colnr_T)(p - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941 if ((pos = findmatch(NULL, NUL)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 else /* Not a comment line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 /* Find last non-blank in line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
954 p = ptr + STRLEN(ptr) - 1;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
955 while (p > ptr && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 last_char = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960 * find the character just before the '{' or ';'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 if (last_char == '{' || last_char == ';')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 if (p > ptr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 --p;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
966 while (p > ptr && VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 * Try to catch lines that are split over multiple
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 * lines. eg:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 * if (condition &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 * condition) {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 * Should line up here!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
975 * }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 if (*p == ')')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 curwin->w_cursor.col = (colnr_T)(p - ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 if ((pos = findmatch(NULL, '(')) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 ptr = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
985 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
987 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
988 * If last character is '{' do indent, without
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
989 * checking for "if" and the like.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
990 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
991 if (last_char == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
993 did_si = TRUE; /* do indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
994 no_si = TRUE; /* don't delete it when '{' typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 * Look for "if" and the like, use 'cinwords'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 * Don't do this if the previous line ended in ';' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999 * '}'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 else if (last_char != ';' && last_char != '}'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 && cin_is_cinword(ptr))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 did_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 else /* dir == BACKWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 * Skip preprocessor directives, unless they are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 * recognised as comments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 if (
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 lead_len == 0 &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 ptr[0] == '#')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1017 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018 int was_backslashed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1019
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1020 while ((ptr[0] == '#' || was_backslashed) &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1021 curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1022 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1023 if (*ptr && ptr[STRLEN(ptr) - 1] == '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1024 was_backslashed = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1025 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1026 was_backslashed = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1027 ptr = ml_get(++curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1028 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1029 if (was_backslashed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 newindent = 0; /* Got to end of file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 p = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 if (*p == '}') /* if line starts with '}': do indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036 did_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 else /* can delete indent when '{' typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 can_si_back = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 if (do_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 can_si = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 #endif /* FEAT_SMARTINDENT */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 did_ai = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1049 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1050 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1051 * Find out if the current line starts with a comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1052 * This may then be inserted in front of the new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1053 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1054 end_comment_pending = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 if (flags & OPENLINE_DO_COM)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1056 lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1059 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 char_u *lead_repl = NULL; /* replaces comment leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 int lead_repl_len = 0; /* length of *lead_repl */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 char_u lead_middle[COM_MAX_LEN]; /* middle-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 char_u lead_end[COM_MAX_LEN]; /* end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 char_u *comment_end = NULL; /* where lead_end has been found */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 int extra_space = FALSE; /* append extra space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 int current_flag;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 int require_blank = FALSE; /* requires blank after middle */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 char_u *p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 * If the comment leader has the start, middle or end flag, it may not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 * be used or may be replaced with the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 for (p = lead_flags; *p && *p != ':'; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 if (*p == COM_BLANK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 require_blank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 if (*p == COM_START || *p == COM_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 current_flag = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 if (*p == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 * Doing "O" on a start of comment does not insert leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 /* find start of middle part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 require_blank = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 * Isolate the strings of the middle and end leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 while (*p && p[-1] != ':') /* find end of middle flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 if (*p == COM_BLANK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107 require_blank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 while (*p && p[-1] != ':') /* find end of end flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 /* Check whether we allow automatic ending of comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 if (*p == COM_AUTO_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 end_comment_pending = -1; /* means we want to set it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119 n = copy_option_part(&p, lead_end, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 if (end_comment_pending == -1) /* we can set it now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 end_comment_pending = lead_end[n - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125 * If the end of the comment is in the same line, don't use
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 * the comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 for (p = saved_line + lead_len; *p; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 if (STRNCMP(p, lead_end, n) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 comment_end = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1136 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1139 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1140 * Doing "o" on a start of comment inserts the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1142 if (lead_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 if (current_flag == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 lead_repl = lead_middle;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 lead_repl_len = (int)STRLEN(lead_middle);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 * If we have hit RETURN immediately after the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 * comment leader, then put a space after the middle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 * comment leader on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1155 if (!VIM_ISWHITE(saved_line[lead_len - 1])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 && ((p_extra != NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 && (int)curwin->w_cursor.col == lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 || (p_extra == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 && saved_line[lead_len] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160 || require_blank))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1161 extra_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 if (*p == COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1167 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1168 * Doing "o" on the end of a comment does not insert leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1169 * Remember where the end is, might want to use it to find the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 * start (for C-comments).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1171 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1172 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1173 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 comment_end = skipwhite(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 * Doing "O" on the end of a comment inserts the middle leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 * Find the string for the middle leader, searching backwards.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 while (p > curbuf->b_p_com && *p != ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 --p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 for (lead_repl = p; lead_repl > curbuf->b_p_com
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 && lead_repl[-1] != ':'; --lead_repl)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 lead_repl_len = (int)(p - lead_repl);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 /* We can probably always add an extra space when doing "O" on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 * the comment-end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 extra_space = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 /* Check whether we allow automatic ending of comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 for (p2 = p; *p2 && *p2 != ':'; p2++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 if (*p2 == COM_AUTO_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 end_comment_pending = -1; /* means we want to set it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 if (end_comment_pending == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 /* Find last character in end-comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 while (*p2 && *p2 != ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 p2++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 end_comment_pending = p2[-1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 if (*p == COM_FIRST)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 * Comment leader for first line only: Don't repeat leader
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 * when using "O", blank out leader when using "o".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 lead_repl = (char_u *)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 lead_repl_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 if (lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 {
3596
34724dc5172b updated for version 7.3.558
Bram Moolenaar <bram@vim.org>
parents: 3592
diff changeset
1227 /* allocate buffer (may concatenate p_extra later) */
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1228 leader = alloc(lead_len + lead_repl_len + extra_space + extra_len
3596
34724dc5172b updated for version 7.3.558
Bram Moolenaar <bram@vim.org>
parents: 3592
diff changeset
1229 + (second_line_indent > 0 ? second_line_indent : 0) + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 allocated = leader; /* remember to free it later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232 if (leader == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 lead_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 410
diff changeset
1236 vim_strncpy(leader, saved_line, lead_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 * Replace leader with lead_repl, right or left adjusted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1241 if (lead_repl != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 int c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 int off = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1246 for (p = lead_flags; *p != NUL && *p != ':'; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 if (*p == COM_RIGHT || *p == COM_LEFT)
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1249 c = *p++;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 else if (VIM_ISDIGIT(*p) || *p == '-')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 off = getdigits(&p);
1996
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1252 else
077c15286de8 updated for version 7.2-293
vimboss
parents: 1987
diff changeset
1253 ++p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 if (c == COM_RIGHT) /* right adjusted leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 /* find last non-white in the leader to line up with */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258 for (p = leader + lead_len - 1; p > leader
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1259 && VIM_ISWHITE(*p); --p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 ++p;
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1262
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1263 /* Compute the length of the replaced characters in
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1264 * screen characters, not bytes. */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1265 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1266 int repl_size = vim_strnsize(lead_repl,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1267 lead_repl_len);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1268 int old_size = 0;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1269 char_u *endp = p;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1270 int l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1271
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1272 while (old_size < repl_size && p > leader)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1273 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
1274 MB_PTR_BACK(leader, p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1275 old_size += ptr2cells(p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1276 }
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
1277 l = lead_repl_len - (int)(endp - p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1278 if (l != 0)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1279 mch_memmove(endp + l, endp,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1280 (size_t)((leader + lead_len) - endp));
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1281 lead_len += l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1282 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 mch_memmove(p, lead_repl, (size_t)lead_repl_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284 if (p + lead_repl_len > leader + lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 p[lead_repl_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 /* blank-out any other chars from the old leader. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 while (--p >= leader)
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1289 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1290 int l = mb_head_off(leader, p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1291
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1292 if (l > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1293 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1294 p -= l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1295 if (ptr2cells(p) > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1296 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1297 p[1] = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1298 --l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1299 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1300 mch_memmove(p + 1, p + l + 1,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1301 (size_t)((leader + lead_len) - (p + l + 1)));
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1302 lead_len -= l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1303 *p = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1304 }
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1305 else if (!VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 *p = ' ';
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1307 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 else /* left adjusted leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 p = skipwhite(leader);
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1312
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1313 /* Compute the length of the replaced characters in
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1314 * screen characters, not bytes. Move the part that is
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1315 * not to be overwritten. */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1316 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1317 int repl_size = vim_strnsize(lead_repl,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1318 lead_repl_len);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1319 int i;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1320 int l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1321
8989
e600e696c0a1 commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents: 8724
diff changeset
1322 for (i = 0; i < lead_len && p[i] != NUL; i += l)
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1323 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
1324 l = (*mb_ptr2len)(p + i);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1325 if (vim_strnsize(p, i + l) > repl_size)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1326 break;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1327 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1328 if (i != lead_repl_len)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1329 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1330 mch_memmove(p + lead_repl_len, p + i,
2002
071166147fc5 updated for version 7.2-299
vimboss
parents: 1996
diff changeset
1331 (size_t)(lead_len - i - (p - leader)));
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1332 lead_len += lead_repl_len - i;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1333 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1334 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 mch_memmove(p, lead_repl, (size_t)lead_repl_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 /* Replace any remaining non-white chars in the old
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 * leader by spaces. Keep Tabs, the indent must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 * remain the same. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 for (p += lead_repl_len; p < leader + lead_len; ++p)
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1341 if (!VIM_ISWHITE(*p))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 /* Don't put a space before a TAB. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 if (p + 1 < leader + lead_len && p[1] == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 mch_memmove(p, p + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 (leader + lead_len) - p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 else
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1351 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
1352 int l = (*mb_ptr2len)(p);
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1353
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1354 if (l > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1355 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1356 if (ptr2cells(p) > 1)
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1357 {
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1358 /* Replace a double-wide char with
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1359 * two spaces */
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1360 --l;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1361 *p++ = ' ';
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1362 }
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1363 mch_memmove(p + 1, p + l,
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1364 (leader + lead_len) - p);
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1365 lead_len -= l - 1;
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1366 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367 *p = ' ';
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
1368 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1373 /* Recompute the indent, it may have changed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1374 if (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1375 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1376 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1377 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378 )
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1379 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1380 newindent = get_indent_str_vtab(leader, curbuf->b_p_ts,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1381 curbuf->b_p_vts_array, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1382 #else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1383 newindent = get_indent_str(leader,
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1384 (int)curbuf->b_p_ts, FALSE);
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14133
diff changeset
1385 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 /* Add the indent offset */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 if (newindent + off < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 off = -newindent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 newindent = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1394 newindent += off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 /* Correct trailing spaces for the shift, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 * alignment remains equal. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398 while (off > 0 && lead_len > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 && leader[lead_len - 1] == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1401 /* Don't do it when there is a tab before the space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 if (vim_strchr(skipwhite(leader), '\t') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1405 --off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1406 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1408 /* If the leader ends in white space, don't add an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1409 * extra space */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1410 if (lead_len > 0 && VIM_ISWHITE(leader[lead_len - 1]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1411 extra_space = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1412 leader[lead_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 if (extra_space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 leader[lead_len++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 leader[lead_len] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 newcol = lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 * if a new indent will be set below, remove the indent that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 * is in the comment leader
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 if (newindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 || did_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 {
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1433 while (lead_len && VIM_ISWHITE(*leader))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 --lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 --newcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 ++leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1443 did_si = can_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1444 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 else if (comment_end != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 * We have finished a comment, so we don't use the leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 * If this was a C-comment and 'ai' or 'si' is set do a normal
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 * indent to align with the line containing the start of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 * comment.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 if (comment_end[0] == '*' && comment_end[1] == '/' &&
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 (curbuf->b_p_ai
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 || do_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 curwin->w_cursor.col = (colnr_T)(comment_end - saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 if ((pos = findmatch(NULL, NUL)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 curwin->w_cursor.lnum = pos->lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 newindent = get_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1472 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 /* (State == INSERT || State == REPLACE), only when dir == FORWARD */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 if (p_extra != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 *p_extra = saved_char; /* restore char that NUL replaced */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 * When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 * non-blank.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 * When in REPLACE mode, put the deleted blanks on the replace stack,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 * preceded by a NUL, so they can be put back when a BS is entered.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1487 replace_push(NUL); /* end of extra blanks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 while ((*p_extra == ' ' || *p_extra == '\t')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1491 && (!enc_utf8
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1492 || !utf_iscomposing(utf_ptr2char(p_extra + 1))))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1494 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495 replace_push(*p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 ++p_extra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 ++less_cols_off;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 if (*p_extra != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 did_ai = FALSE; /* append some text, don't truncate now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 /* columns for marks adjusted for removed columns */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 less_cols = (int)(p_extra - saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 if (p_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 p_extra = (char_u *)""; /* append empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 /* concatenate leader and p_extra, if there is a leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 if (lead_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 {
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1514 if (flags & OPENLINE_COM_LIST && second_line_indent > 0)
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1515 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1516 int i;
3592
b8924014a039 updated for version 7.3.556
Bram Moolenaar <bram@vim.org>
parents: 3584
diff changeset
1517 int padding = second_line_indent
b8924014a039 updated for version 7.3.556
Bram Moolenaar <bram@vim.org>
parents: 3584
diff changeset
1518 - (newindent + (int)STRLEN(leader));
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1519
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1520 /* Here whitespace is inserted after the comment char.
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1521 * Below, set_indent(newindent, SIN_INSERT) will insert the
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1522 * whitespace needed before the comment char. */
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1523 for (i = 0; i < padding; i++)
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1524 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1525 STRCAT(leader, " ");
3705
2b4b6185054f updated for version 7.3.612
Bram Moolenaar <bram@vim.org>
parents: 3658
diff changeset
1526 less_cols--;
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1527 newcol++;
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1528 }
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
1529 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 STRCAT(leader, p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 p_extra = leader;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 did_ai = TRUE; /* So truncating blanks works with comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 less_cols -= lead_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 end_comment_pending = NUL; /* turns out there was no leader */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 old_cursor = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 if (dir == BACKWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 --curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, FALSE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 /* Postpone calling changed_lines(), because it would mess up folding
9225
b0b2bd8e5217 commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents: 8989
diff changeset
1548 * with markers.
b0b2bd8e5217 commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents: 8989
diff changeset
1549 * Skip mark_adjust when adding a line after the last one, there can't
11065
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1550 * be marks there. But still needed in diff mode. */
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1551 if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1552 #ifdef FEAT_DIFF
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1553 || curwin->w_p_diff
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1554 #endif
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
1555 )
9225
b0b2bd8e5217 commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents: 8989
diff changeset
1556 mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557 did_append = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1559 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 * In VREPLACE mode we are starting to replace the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 curwin->w_cursor.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1566 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567 /* In case we NL to a new line, BS to the previous one, and NL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1568 * again, we don't want to save the new line for undo twice.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1570 (void)u_save_cursor(); /* errors are ignored! */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1571 vr_lines_changed++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1573 ml_replace(curwin->w_cursor.lnum, p_extra, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1574 changed_bytes(curwin->w_cursor.lnum, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1575 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1576 did_append = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1577 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1578
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 if (newindent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 || did_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1584 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1585 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1586 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587 if (did_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1588 {
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
1589 int sw = (int)get_sw_value(curbuf);
3740
7de7ef01288d updated for version 7.3.629
Bram Moolenaar <bram@vim.org>
parents: 3705
diff changeset
1590
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1591 if (p_sr)
3740
7de7ef01288d updated for version 7.3.629
Bram Moolenaar <bram@vim.org>
parents: 3705
diff changeset
1592 newindent -= newindent % sw;
7de7ef01288d updated for version 7.3.629
Bram Moolenaar <bram@vim.org>
parents: 3705
diff changeset
1593 newindent += sw;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1594 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1595 #endif
1324
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
1596 /* Copy the indent */
60d21d224d25 updated for version 7.1-038
vimboss
parents: 1224
diff changeset
1597 if (curbuf->b_p_ci)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1598 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1599 (void)copy_indent(newindent, saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1600
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1601 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1602 * Set the 'preserveindent' option so that any further screwing
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1603 * with the line doesn't entirely destroy our efforts to preserve
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1604 * it. It gets restored at the function end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1605 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1606 curbuf->b_p_pi = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1608 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1609 (void)set_indent(newindent, SIN_INSERT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1610 less_cols -= curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1611
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1612 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1613
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1614 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1615 * In REPLACE mode, for each character in the new indent, there must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1616 * be a NUL on the replace stack, for when it is deleted with BS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1618 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1619 for (n = 0; n < (int)curwin->w_cursor.col; ++n)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1620 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1621 newcol += curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1622 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1623 if (no_si)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1624 did_si = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1625 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1627
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1628 #ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1629 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1630 * In REPLACE mode, for each character in the extra leader, there must be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 * a NUL on the replace stack, for when it is deleted with BS.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1633 if (REPLACE_NORMAL(State))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 while (lead_len-- > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 curwin->w_cursor = old_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 if (dir == FORWARD)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 if (trunc_line || (State & INSERT))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 /* truncate current line at cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 saved_line[curwin->w_cursor.col] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 /* Remove trailing white space, unless OPENLINE_KEEPTRAIL used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 if (trunc_line && !(flags & OPENLINE_KEEPTRAIL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 truncate_spaces(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 ml_replace(curwin->w_cursor.lnum, saved_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 saved_line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 if (did_append)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1653 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 curwin->w_cursor.lnum + 1, 1L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1655 did_append = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1657 /* Move marks after the line break to the new line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1658 if (flags & OPENLINE_MARKFIX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1659 mark_col_adjust(curwin->w_cursor.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1660 curwin->w_cursor.col + less_cols_off,
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15308
diff changeset
1661 1L, (long)-less_cols, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1662 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1663 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 * Put the cursor on the new line. Careful: the scrollup() above may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 * have moved w_cursor, we must use old_cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 curwin->w_cursor.lnum = old_cursor.lnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673 if (did_append)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 curwin->w_cursor.col = newcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678
14424
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
1679 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681 * In VREPLACE mode, we are handling the replace stack ourselves, so stop
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 * fixthisline() from doing it (via change_indent()) by telling it we're in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 * normal INSERT mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 vreplace_mode = State; /* So we know to put things right later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 State = INSERT;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 vreplace_mode = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 #ifdef FEAT_LISP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 * May do lisp indenting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 if (!p_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 # ifdef FEAT_COMMENTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 && leader == NULL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 && curbuf->b_p_lisp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 && curbuf->b_p_ai)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 fixthisline(get_lisp_indent);
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 12293
diff changeset
1705 ai_col = (colnr_T)getwhitecols_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 #ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 * May do indenting after opening a new line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 if (!p_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 && (curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 # ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 || *curbuf->b_p_inde != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 && in_cinkeys(dir == FORWARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 ? KEY_OPEN_FORW
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 : KEY_OPEN_BACK, ' ', linewhite(curwin->w_cursor.lnum)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 do_c_expr_indent();
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 12293
diff changeset
1723 ai_col = (colnr_T)getwhitecols_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 #endif
14424
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
1726 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 if (vreplace_mode != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 State = vreplace_mode;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 * Finally, VREPLACE gets the stuff on the new line, then puts back the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 * original line, and inserts the new stuff char by char, pushing old stuff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 * onto the replace stack (via ins_char()).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 /* Put new line in p_extra */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1739 p_extra = vim_strsave(ml_get_curline());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 if (p_extra == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 goto theend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 /* Put back original line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 ml_replace(curwin->w_cursor.lnum, next_line, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 /* Insert new stuff into line again */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 ins_bytes(p_extra); /* will call changed_bytes() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 vim_free(p_extra);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751 next_line = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753
13772
cc21507ee4b1 patch 8.0.1758: open_line() returns TRUE/FALSE for success/failure
Christian Brabandt <cb@256bit.org>
parents: 13768
diff changeset
1754 retval = OK; /* success! */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1755 theend:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 curbuf->b_p_pi = saved_pi;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1757 vim_free(saved_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 vim_free(next_line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 vim_free(allocated);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 #if defined(FEAT_COMMENTS) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1764 /*
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
1765 * get_leader_len() returns the length in bytes of the prefix of the given
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
1766 * string which introduces a comment. If this string is not a comment then
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5338
diff changeset
1767 * 0 is returned.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1768 * When "flags" is not NULL, it is set to point to the flags of the recognized
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1769 * comment leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1770 * "backward" must be true for the "O" command.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1771 * If "include_space" is set, include trailing whitespace while calculating the
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1772 * length.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1773 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1775 get_leader_len(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1776 char_u *line,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1777 char_u **flags,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1778 int backward,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1779 int include_space)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 int i, j;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1782 int result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 int got_com = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 int found_one;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 char_u *string; /* pointer to comment string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 char_u *list;
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1788 int middle_match_len = 0;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1789 char_u *prev_list;
2813
21346361ce6c updated for version 7.3.182
Bram Moolenaar <bram@vim.org>
parents: 2809
diff changeset
1790 char_u *saved_flags = NULL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1792 result = i = 0;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1793 while (VIM_ISWHITE(line[i])) /* leading white space is ignored */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 * Repeat to match several nested comment strings.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 */
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1799 while (line[i] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 * scan through the 'comments' option for a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 found_one = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 for (list = curbuf->b_p_com; *list; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 {
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1807 /* Get one option part into part_buf[]. Advance "list" to next
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1808 * one. Put "string" at start of string. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1809 if (!got_com && flags != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1810 *flags = list; /* remember where flags started */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1811 prev_list = list;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 string = vim_strchr(part_buf, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 if (string == NULL) /* missing ':', ignore this part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816 *string++ = NUL; /* isolate flags from string */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1818 /* If we found a middle match previously, use that match when this
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1819 * is not a middle or end. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1820 if (middle_match_len != 0
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1821 && vim_strchr(part_buf, COM_MIDDLE) == NULL
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1822 && vim_strchr(part_buf, COM_END) == NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1823 break;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1824
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1825 /* When we already found a nested comment, only accept further
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1826 * nested comments. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1830 /* When 'O' flag present and using "O" command skip this one. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1832 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1833
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1834 /* Line contents and string must match.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 * When string starts with white space, must have some white space
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1836 * (but the amount does not need to match, there might be a mix of
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1837 * TABs and spaces). */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1838 if (VIM_ISWHITE(string[0]))
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1839 {
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1840 if (i == 0 || !VIM_ISWHITE(line[i - 1]))
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4342
diff changeset
1841 continue; /* missing white space */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1842 while (VIM_ISWHITE(string[0]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 ++string;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1846 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1847 if (string[j] != NUL)
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1848 continue; /* string doesn't match */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1849
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1850 /* When 'b' flag used, there must be white space or an
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1851 * end-of-line after the string in the line. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1852 if (vim_strchr(part_buf, COM_BLANK) != NULL
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1853 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1854 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1855
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1856 /* We have found a match, stop searching unless this is a middle
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1857 * comment. The middle comment can be a substring of the end
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1858 * comment in which case it's better to return the length of the
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1859 * end comment and its flags. Thus we keep searching with middle
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1860 * and end matches and use an end match if it matches better. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1861 if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1862 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1863 if (middle_match_len == 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1864 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1865 middle_match_len = j;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1866 saved_flags = prev_list;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1867 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1868 continue;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1869 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1870 if (middle_match_len != 0 && j > middle_match_len)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1871 /* Use this match instead of the middle match, since it's a
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1872 * longer thus better match. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1873 middle_match_len = 0;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1874
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1875 if (middle_match_len == 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1876 i += j;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1877 found_one = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1878 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1879 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1880
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1881 if (middle_match_len != 0)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1882 {
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1883 /* Use the previously found middle match after failing to find a
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1884 * match with an end. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1885 if (!got_com && flags != NULL)
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1886 *flags = saved_flags;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1887 i += middle_match_len;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1888 found_one = TRUE;
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1889 }
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1890
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1891 /* No match found, stop scanning. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1892 if (!found_one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1893 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1894
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1895 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1896
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1897 /* Include any trailing white space. */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1898 while (VIM_ISWHITE(line[i]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1899 ++i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1900
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1901 if (include_space)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1902 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1903
2809
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1904 /* If this comment doesn't nest, stop here. */
ed47d18b39c6 updated for version 7.3.180
Bram Moolenaar <bram@vim.org>
parents: 2807
diff changeset
1905 got_com = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1906 if (vim_strchr(part_buf, COM_NEST) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1907 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1908 }
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1909 return result;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1910 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1911
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1912 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1913 * Return the offset at which the last comment in line starts. If there is no
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1914 * comment in the whole line, -1 is returned.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1915 *
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1916 * When "flags" is not null, it is set to point to the flags describing the
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1917 * recognized comment leader.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1918 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1919 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
1920 get_last_leader_offset(char_u *line, char_u **flags)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1921 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1922 int result = -1;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1923 int i, j;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1924 int lower_check_bound = 0;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1925 char_u *string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1926 char_u *com_leader;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1927 char_u *com_flags;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1928 char_u *list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1929 int found_one;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1930 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1931
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1932 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1933 * Repeat to match several nested comment strings.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1934 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1935 i = (int)STRLEN(line);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1936 while (--i >= lower_check_bound)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1937 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1938 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1939 * scan through the 'comments' option for a match
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1940 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1941 found_one = FALSE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1942 for (list = curbuf->b_p_com; *list; )
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1943 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1944 char_u *flags_save = list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1945
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1946 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1947 * Get one option part into part_buf[]. Advance list to next one.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1948 * put string at start of string.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1949 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1950 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1951 string = vim_strchr(part_buf, ':');
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1952 if (string == NULL) /* If everything is fine, this cannot actually
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1953 * happen. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1954 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1955 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1956 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1957 *string++ = NUL; /* Isolate flags from string. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1958 com_leader = string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1959
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1960 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1961 * Line contents and string must match.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1962 * When string starts with white space, must have some white space
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1963 * (but the amount does not need to match, there might be a mix of
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1964 * TABs and spaces).
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1965 */
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1966 if (VIM_ISWHITE(string[0]))
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1967 {
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1968 if (i == 0 || !VIM_ISWHITE(line[i - 1]))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1969 continue;
15119
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1970 while (VIM_ISWHITE(*string))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1971 ++string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1972 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1973 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1974 /* do nothing */;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1975 if (string[j] != NUL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1976 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1977
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1978 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1979 * When 'b' flag used, there must be white space or an
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1980 * end-of-line after the string in the line.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1981 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1982 if (vim_strchr(part_buf, COM_BLANK) != NULL
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
1983 && !VIM_ISWHITE(line[i + j]) && line[i + j] != NUL)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1984 continue;
15119
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1985
15127
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1986 if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1987 {
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1988 // For a middlepart comment, only consider it to match if
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1989 // everything before the current position in the line is
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1990 // whitespace. Otherwise we would think we are inside a
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1991 // comment if the middle part appears somewhere in the middle
31a0127813cb patch 8.1.0574: 'commentstring' not used when adding fold marker in C
Bram Moolenaar <Bram@vim.org>
parents: 15119
diff changeset
1992 // of the line. E.g. for C the "*" appears often.
15119
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1993 for (j = 0; VIM_ISWHITE(line[j]) && j <= i; j++)
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1994 ;
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1995 if (j < i)
6e9f37bf987b patch 8.1.0570: 'commentstring' not used when adding fold marker
Bram Moolenaar <Bram@vim.org>
parents: 15046
diff changeset
1996 continue;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1997 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1998
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
1999 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2000 * We have found a match, stop searching.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2001 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2002 found_one = TRUE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2003
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2004 if (flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2005 *flags = flags_save;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2006 com_flags = flags_save;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2007
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2008 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2009 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2010
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2011 if (found_one)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2012 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2013 char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2014 int len1, len2, off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2015
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2016 result = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2017 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2018 * If this comment nests, continue searching.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2019 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2020 if (vim_strchr(part_buf, COM_NEST) != NULL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2021 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2022
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2023 lower_check_bound = i;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2024
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2025 /* Let's verify whether the comment leader found is a substring
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2026 * of other comment leaders. If it is, let's adjust the
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2027 * lower_check_bound so that we make sure that we have determined
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2028 * the comment leader correctly.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2029 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2030
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2031 while (VIM_ISWHITE(*com_leader))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2032 ++com_leader;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2033 len1 = (int)STRLEN(com_leader);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2034
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2035 for (list = curbuf->b_p_com; *list; )
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2036 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2037 char_u *flags_save = list;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2038
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2039 (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ",");
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2040 if (flags_save == com_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2041 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2042 string = vim_strchr(part_buf2, ':');
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2043 ++string;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2044 while (VIM_ISWHITE(*string))
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2045 ++string;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2046 len2 = (int)STRLEN(string);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2047 if (len2 == 0)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2048 continue;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2049
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2050 /* Now we have to verify whether string ends with a substring
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2051 * beginning the com_leader. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2052 for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2053 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2054 --off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2055 if (!STRNCMP(string + off, com_leader, len2 - off))
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2056 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2057 if (i - off < lower_check_bound)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2058 lower_check_bound = i - off;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2059 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2060 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2061 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2062 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2063 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3549
diff changeset
2064 return result;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2065 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2066 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2067
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2068 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2069 * Return the number of window lines occupied by buffer line "lnum".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2070 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2071 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2072 plines(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2073 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2074 return plines_win(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2075 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2077 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2078 plines_win(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2079 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2080 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2081 int winheight) /* when TRUE limit to window height */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2083 #if defined(FEAT_DIFF) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2084 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2085 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2086 return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2088
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2089 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2090 plines_nofill(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2091 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2092 return plines_win_nofill(curwin, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2093 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2095 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2096 plines_win_nofill(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2097 win_T *wp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2098 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2099 int winheight) /* when TRUE limit to window height */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2100 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2101 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2102 int lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2104 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2105 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2106
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2107 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2108 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2110 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2111 /* A folded lines is handled just like an empty line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2112 /* NOTE: Caller must handle lines that are MAYBE folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2113 if (lineFolded(wp, lnum) == TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2114 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2115 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2116
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2117 lines = plines_win_nofold(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2118 if (winheight > 0 && lines > wp->w_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2119 return (int)wp->w_height;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2120 return lines;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2121 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2122
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2123 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2124 * Return number of window lines physical line "lnum" will occupy in window
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2125 * "wp". Does not care about folding, 'wrap' or 'diff'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2126 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2127 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2128 plines_win_nofold(win_T *wp, linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2130 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2131 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2132 int width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2133
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2134 s = ml_get_buf(wp->w_buffer, lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2135 if (*s == NUL) /* empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2136 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2137 col = win_linetabsize(wp, s, (colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2138
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2140 * If list mode is on, then the '$' at the end of the line may take up one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2141 * extra column.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2142 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143 if (wp->w_p_list && lcs_eol != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2144 col += 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2146 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
2147 * Add column offset for 'number', 'relativenumber' and 'foldcolumn'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
2149 width = wp->w_width - win_col_off(wp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 if (width <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 return 32000;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2152 if (col <= width)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 return 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 col -= width;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 width += win_col_off2(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 return (col + (width - 1)) / width + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 * Like plines_win(), but only reports the number of physical screen lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 * used from the start of the line to the given column number.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2162 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2164 plines_win_col(win_T *wp, linenr_T lnum, long column)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2166 long col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2167 char_u *s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 int lines = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 int width;
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
2170 char_u *line;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2173 /* Check for filler lines above this buffer line. When folded the result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 * is one line anyway. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 lines = diff_check_fill(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2177
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 if (!wp->w_p_wrap)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 if (wp->w_width == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 return lines + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
2184 line = s = ml_get_buf(wp->w_buffer, lnum, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 while (*s != NUL && --column >= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
2189 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL);
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2190 MB_PTR_ADV(s);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2191 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 * If *s is a TAB, and the TAB is not displayed as ^I, and we're not in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 * INSERT mode, then col must be adjusted so that it represents the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 * screen position of the TAB. This only fixes an error when the TAB wraps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197 * from one screen line to the next (when 'columns' is not a multiple of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 * 'ts') -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200 if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1))
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5911
diff changeset
2201 col += win_lbr_chartabsize(wp, line, s, (colnr_T)col, NULL) - 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 /*
2178
c6f1aa1e9f32 Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
2204 * Add column offset for 'number', 'relativenumber', 'foldcolumn', etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 */
12515
972ea22c946f patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents: 12477
diff changeset
2206 width = wp->w_width - win_col_off(wp);
1023
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2207 if (width <= 0)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2208 return 9999;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2209
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2210 lines += 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2211 if (col > width)
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2212 lines += (col - width) / (width + win_col_off2(wp)) + 1;
cb7043482eca updated for version 7.0-149
vimboss
parents: 1010
diff changeset
2213 return lines;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2217 plines_m_win(win_T *wp, linenr_T first, linenr_T last)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 int count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 while (first <= last)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 int x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 /* Check if there are any really folded lines, but also included lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 * that are maybe folded. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 x = foldedCount(wp, first, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 if (x > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 ++count; /* count 1 for "+-- folded" line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 first += x;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 #ifdef FEAT_DIFF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 if (first == wp->w_topline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 count += plines_win(wp, first, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 ++first;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 return (count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 * Insert string "p" at the cursor position. Stops at a NUL byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 * Handles Replace mode and multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2254 ins_bytes(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 ins_bytes_len(p, (int)STRLEN(p));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 }
14424
0a69e6e708f9 patch 8.1.0226: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 14393
diff changeset
2258
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2259 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2260 * Insert string "p" with length "len" at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 * Handles Replace mode and multi-byte characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2264 ins_bytes_len(char_u *p, int len)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268
1617
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2269 if (has_mbyte)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2270 for (i = 0; i < len; i += n)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2271 {
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2272 if (enc_utf8)
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2273 // avoid reading past p[len]
1617
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2274 n = utfc_ptr2len_len(p + i, len - i);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2275 else
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2276 n = (*mb_ptr2len)(p + i);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2277 ins_char_bytes(p + i, n);
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2278 }
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2279 else
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2280 for (i = 0; i < len; ++i)
5f0c7aae4da2 updated for version 7.1-330
vimboss
parents: 1550
diff changeset
2281 ins_char(p[i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 * Insert or replace a single character at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 * When in REPLACE or VREPLACE mode, replace any existing character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 * For multi-byte characters we get the whole character, the caller must
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 * convert bytes to a character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2292 ins_char(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 {
10642
c10f367d0dfc patch 8.0.0211: cannot build without the multi-byte feature
Christian Brabandt <cb@256bit.org>
parents: 10571
diff changeset
2294 char_u buf[MB_MAXBYTES + 1];
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
2295 int n = (*mb_char2bytes)(c, buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 /* When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 * Happens for CTRL-Vu9900. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 if (buf[0] == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 buf[0] = '\n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 ins_char_bytes(buf, n);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2306 ins_char_bytes(char_u *buf, int charlen)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 int c = buf[0];
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2309 int newlen; // nr of bytes inserted
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2310 int oldlen; // nr of bytes deleted (0 when not replacing)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 char_u *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 char_u *oldp;
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2314 int linelen; // length of old line including NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 /* Break tabs if needed. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 linelen = (int)STRLEN(oldp) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 /* The lengths default to the values for when not replacing. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 oldlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 newlen = charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 if (State & REPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 if (State & VREPLACE_FLAG)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2334 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2335 colnr_T new_vcol = 0; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2336 colnr_T vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 int old_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2340 * Disable 'list' temporarily, unless 'cpo' contains the 'L' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 * Returns the old value of list, so when finished,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2342 * curwin->w_p_list should be set back to this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2343 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2344 old_list = curwin->w_p_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2345 if (old_list && vim_strchr(p_cpo, CPO_LISTWM) == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2346 curwin->w_p_list = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2347
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2348 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2349 * In virtual replace mode each character may replace one or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2350 * characters (zero if it's a TAB). Count the number of bytes to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2351 * be deleted to make room for the new character, counting screen
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2352 * cells. May result in adding spaces to fill a gap.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2353 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2354 getvcol(curwin, &curwin->w_cursor, NULL, &vcol, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2355 new_vcol = vcol + chartabsize(buf, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2356 while (oldp[col + oldlen] != NUL && vcol < new_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2357 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2358 vcol += chartabsize(oldp + col + oldlen, vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2359 /* Don't need to remove a TAB that takes us to the right
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2360 * position. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2361 if (vcol > new_vcol && oldp[col + oldlen] == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2362 break;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2363 oldlen += (*mb_ptr2len)(oldp + col + oldlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2364 /* Deleted a bit too much, insert spaces. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2365 if (vcol > new_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2366 newlen += vcol - new_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2367 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2368 curwin->w_p_list = old_list;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2369 }
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2370 else if (oldp[col] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2371 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2372 /* normal replace */
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2373 oldlen = (*mb_ptr2len)(oldp + col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2374 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2377 /* Push the replaced bytes onto the replace stack, so that they can be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2378 * put back when BS is used. The bytes of a multi-byte character are
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2379 * done the other way around, so that the first byte is popped off
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2380 * first (it tells the byte length of the character). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2381 replace_push(NUL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2382 for (i = 0; i < oldlen; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2383 {
1470
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2384 if (has_mbyte)
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2385 i += replace_push_mb(oldp + col + i) - 1;
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2386 else
48b22e2eb1ed updated for version 7.1-185
vimboss
parents: 1408
diff changeset
2387 replace_push(oldp[col + i]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 newp = alloc_check((unsigned)(linelen + newlen - oldlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2394
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2395 /* Copy bytes before the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2396 if (col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 /* Copy bytes after the changed character(s). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 p = newp + col;
12690
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2401 if (linelen > col + oldlen)
fad36581f788 patch 8.0.1223: crash when using autocomplete and tab pages
Christian Brabandt <cb@256bit.org>
parents: 12515
diff changeset
2402 mch_memmove(p + newlen, oldp + col + oldlen,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 (size_t)(linelen - col - oldlen));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 /* Insert or overwrite the new character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 mch_memmove(p, buf, charlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 i = charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2409 /* Fill with spaces when necessary. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 while (i < newlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2411 p[i++] = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2412
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2413 // Replace the line in the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2416 // mark the buffer as changed and prepare for displaying
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2417 inserted_bytes(lnum, col, newlen - oldlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 * If we're in Insert or Replace mode and 'showmatch' is set, then briefly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 * show the match for right parens and braces.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 if (p_sm && (State & INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 && msg_silent == 0
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2425 #ifdef FEAT_INS_EXPAND
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2426 && !ins_compl_active()
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 673
diff changeset
2427 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 )
4029
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2429 {
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2430 if (has_mbyte)
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2431 showmatch(mb_ptr2char(buf));
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2432 else
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2433 showmatch(c);
d179a8eff9d7 updated for version 7.3.769
Bram Moolenaar <bram@vim.org>
parents: 3744
diff changeset
2434 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2437 if (!p_ri || (State & REPLACE_FLAG))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 /* Normal insert: move cursor right */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2441 curwin->w_cursor.col += charlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 * TODO: should try to update w_row here, to avoid recomputing it later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 * Insert a string at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 * Note: Does NOT handle Replace mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2454 ins_str(char_u *s)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 char_u *oldp, *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 int newlen = (int)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 int oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 if (virtual_active() && curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 oldlen = (int)STRLEN(oldp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 newp = alloc_check((unsigned)(oldlen + newlen + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 if (col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2473 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 mch_memmove(newp + col, s, (size_t)newlen);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 mch_memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 ml_replace(lnum, newp, FALSE);
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2477 inserted_bytes(lnum, col, newlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 curwin->w_cursor.col += newlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482 * Delete one character under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2489 del_char(int fixpos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 /* Make sure the cursor is at the start of a character. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 mb_adjust_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 if (*ml_get_cursor() == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 return del_chars(1L, fixpos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2499 return del_bytes(1L, fixpos, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2501
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2502 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2503 * Like del_bytes(), but delete characters instead of bytes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2504 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2505 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2506 del_chars(long count, int fixpos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2507 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2508 long bytes = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2509 long i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2511 int l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2513 p = ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2514 for (i = 0; i < count && *p != NUL; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2515 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2516 l = (*mb_ptr2len)(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2517 bytes += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2518 p += l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2519 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2520 return del_bytes(bytes, fixpos, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2523 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2524 * Delete "count" bytes under the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2525 * If "fixpos" is TRUE, don't leave the cursor on the NUL after the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2526 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2527 *
13188
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2528 * Return FAIL for failure, OK otherwise.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2529 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2531 del_bytes(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2532 long count,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2533 int fixpos_arg,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2534 int use_delcombine UNUSED) /* 'delcombine' option applies */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 char_u *oldp, *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 colnr_T oldlen;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2538 colnr_T newlen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2540 colnr_T col = curwin->w_cursor.col;
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2541 int alloc_newp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542 long movelen;
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2543 int fixpos = fixpos_arg;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 oldlen = (int)STRLEN(oldp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547
13188
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2548 /* Can't do anything when the cursor is on the NUL after the line. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 if (col >= oldlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551
13188
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2552 /* If "count" is zero there is nothing to do. */
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2553 if (count == 0)
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2554 return OK;
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2555
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2556 /* If "count" is negative the caller must be doing something wrong. */
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2557 if (count < 1)
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2558 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
2559 siemsg("E950: Invalid count for del_bytes(): %ld", count);
13188
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2560 return FAIL;
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2561 }
a49a5419a83f patch 8.0.1468: illegal memory access in del_bytes()
Christian Brabandt <cb@256bit.org>
parents: 13180
diff changeset
2562
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 /* If 'delcombine' is set and deleting (less than) one character, only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 * delete the last combining character. */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2565 if (p_deco && use_delcombine && enc_utf8
cd3689efd90a updated for version 7.0173
vimboss
parents: 594
diff changeset
2566 && utfc_ptr2len(oldp + col) >= count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2567 {
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2568 int cc[MAX_MCO];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2571 (void)utfc_ptr2char(oldp + col, cc);
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
2572 if (cc[0] != NUL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 /* Find the last composing char, there can be several. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 n = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 do
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 col = n;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
2579 count = utf_ptr2len(oldp + n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 n += count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 } while (UTF_COMPOSINGLIKE(oldp + col, oldp + n));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 fixpos = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2587 * When count is too big, reduce it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 movelen = (long)oldlen - (long)col - count + 1; /* includes trailing NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 if (movelen <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 * If we just took off the last character of a non-blank line, and
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2594 * fixpos is TRUE, we don't want to end up positioned at the NUL,
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2595 * unless "restart_edit" is set or 'virtualedit' contains "onemore".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 */
777
f664cc974a7a updated for version 7.0227
vimboss
parents: 768
diff changeset
2597 if (col > 0 && fixpos && restart_edit == 0
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
2598 && (ve_flags & VE_ONEMORE) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2600 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2601 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2602 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2603 curwin->w_cursor.col -=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2604 (*mb_head_off)(oldp, oldp + curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2605 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2606 count = oldlen - col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2607 movelen = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2608 }
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2609 newlen = oldlen - count;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2611 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2612 * If the old line has been allocated the deletion can be done in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 * existing line. Otherwise a new line has to be allocated
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2614 * Can't do this when using Netbeans, because we would need to invoke
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2615 * netbeans_removed(), which deallocates the line. Let ml_replace() take
2460
b8eb7c0f74c2 Remove unused variable and STRLEN(). (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents: 2435
diff changeset
2616 * care of notifying Netbeans.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 #ifdef FEAT_NETBEANS_INTG
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2178
diff changeset
2619 if (netbeans_active())
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2620 alloc_newp = TRUE;
1532
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2621 else
87b9f21264a7 updated for version 7.1-247
vimboss
parents: 1521
diff changeset
2622 #endif
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2623 alloc_newp = !ml_line_alloced(); // check if oldp was allocated
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2624 if (!alloc_newp)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2625 newp = oldp; // use same allocated memory
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 else
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2627 { // need to allocate a new line
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2628 newp = alloc((unsigned)(newlen + 1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 mch_memmove(newp, oldp, (size_t)col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 mch_memmove(newp + col, oldp + col + count, (size_t)movelen);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2634 if (alloc_newp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2635 ml_replace(lnum, newp, FALSE);
15138
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2636 #ifdef FEAT_TEXT_PROP
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2637 else
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2638 {
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2639 // Also move any following text properties.
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2640 if (oldlen + 1 < curbuf->b_ml.ml_line_len)
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2641 mch_memmove(newp + newlen + 1, oldp + oldlen + 1,
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2642 (size_t)curbuf->b_ml.ml_line_len - oldlen - 1);
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2643 curbuf->b_ml.ml_line_len -= count;
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2644 }
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2645 #endif
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2646
9df130fd5e0d patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents: 15127
diff changeset
2647 // mark the buffer as changed and prepare for displaying
15347
f6b522596993 patch 8.1.0681: text properties as not adjusted for deleted text
Bram Moolenaar <Bram@vim.org>
parents: 15341
diff changeset
2648 inserted_bytes(lnum, curwin->w_cursor.col, -count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 * Delete from cursor to end of line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 * Caller must have prepared for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2657 * return FAIL for failure, OK otherwise
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2658 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2659 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2660 truncate_line(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2661 int fixpos) /* if TRUE fix the cursor position when done */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 char_u *newp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 linenr_T lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665 colnr_T col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 if (col == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2668 newp = vim_strsave((char_u *)"");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 newp = vim_strnsave(ml_get(lnum), col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 /* mark the buffer as changed and prepare for displaying */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 changed_bytes(lnum, curwin->w_cursor.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681 * If "fixpos" is TRUE we don't want to end up positioned at the NUL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 if (fixpos && curwin->w_cursor.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 * Delete "nlines" lines at the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 * Saves the lines for undo first if "undo" is TRUE.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2692 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2694 del_lines(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2695 long nlines, /* number of lines to delete */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2696 int undo) /* if TRUE, prepare for undo */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 long n;
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2699 linenr_T first = curwin->w_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 if (nlines <= 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 /* save the deleted lines for undo */
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2705 if (undo && u_savedel(first, nlines) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 for (n = 0; n < nlines; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2709 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2712
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2713 ml_delete(first, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 /* If we delete the last line in the file, stop */
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2717 if (first > curbuf->b_ml.ml_line_count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 }
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2720
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2721 /* Correct the cursor position before calling deleted_lines_mark(), it may
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2722 * trigger a callback to display the cursor. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724 check_cursor_lnum();
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2725
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2726 /* adjust marks, mark the buffer as changed and prepare for displaying */
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2727 deleted_lines_mark(first, n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2731 gchar_pos(pos_T *pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 {
13082
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2733 char_u *ptr;
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2734
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2735 /* When searching columns is sometimes put at the end of a line. */
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2736 if (pos->col == MAXCOL)
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2737 return NUL;
a80082fd1a1d patch 8.0.1416: crash when searching for a sentence
Christian Brabandt <cb@256bit.org>
parents: 12865
diff changeset
2738 ptr = ml_get_pos(pos);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 return (*mb_ptr2char)(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2741 return (int)*ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2742 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2743
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2744 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2745 gchar_cursor(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 return (*mb_ptr2char)(ml_get_cursor());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 return (int)*ml_get_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 * Write a character at the current cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754 * It is directly written into the block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2757 pchar_cursor(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 *(ml_get_buf(curbuf, curwin->w_cursor.lnum, TRUE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 + curwin->w_cursor.col) = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 * When extra == 0: Return TRUE if the cursor is before or on the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 * non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766 * When extra == 1: Return TRUE if the cursor is before the first non-blank in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 * the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2770 inindent(int extra)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2773 colnr_T col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2775 for (col = 0, ptr = ml_get_curline(); VIM_ISWHITE(*ptr); ++col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 ++ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 if (col >= curwin->w_cursor.col + extra)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 * Skip to next part of an option argument: Skip space and comma.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2786 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2787 skip_to_option_part(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 if (*p == ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 while (*p == ' ')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 /*
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
2797 * Call this function when something in the current buffer is changed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 * Most often called through changed_bytes() and changed_lines(), which also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 * mark the area of the display to be redrawn.
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
2801 *
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
2802 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2805 changed(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
12293
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2808 if (p_imst == IM_ON_THE_SPOT)
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2809 {
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2810 /* The text of the preediting area is inserted, but this doesn't
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2811 * mean a change of the buffer yet. That is delayed until the
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2812 * text is committed. (this means preedit becomes empty) */
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2813 if (im_is_preediting() && !xim_changed_while_preediting)
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2814 return;
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2815 xim_changed_while_preediting = FALSE;
1ff5e5dfa9b0 patch 8.0.1026: GTK on-the-spot input has problems
Christian Brabandt <cb@256bit.org>
parents: 12269
diff changeset
2816 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 if (!curbuf->b_changed)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 int save_msg_scroll = msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2823 /* Give a warning about changing a read-only file. This may also
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2824 * check-out the file, thus change "curbuf"! */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 change_warning(0);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
2826
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 /* Create a swap file if that is wanted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 * Don't do this for "nofile" and "nowrite" buffer types. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 if (curbuf->b_may_swap
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 #ifdef FEAT_QUICKFIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 && !bt_dontwrite(curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 {
7582
e0acbccdf1fc commit https://github.com/vim/vim/commit/b01f357791f88c7083e58cf2b36509dd83f21ea2
Christian Brabandt <cb@256bit.org>
parents: 7408
diff changeset
2835 int save_need_wait_return = need_wait_return;
e0acbccdf1fc commit https://github.com/vim/vim/commit/b01f357791f88c7083e58cf2b36509dd83f21ea2
Christian Brabandt <cb@256bit.org>
parents: 7408
diff changeset
2836
e0acbccdf1fc commit https://github.com/vim/vim/commit/b01f357791f88c7083e58cf2b36509dd83f21ea2
Christian Brabandt <cb@256bit.org>
parents: 7408
diff changeset
2837 need_wait_return = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 ml_open_file(curbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 /* The ml_open_file() can cause an ATTENTION message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 * Wait two seconds, to make sure the user reads this unexpected
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 * message. Since we could be anywhere, call wait_return() now,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 * and don't let the emsg() set msg_scroll. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 if (need_wait_return && emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 ui_delay(2000L, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 wait_return(TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 msg_scroll = save_msg_scroll;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 }
7582
e0acbccdf1fc commit https://github.com/vim/vim/commit/b01f357791f88c7083e58cf2b36509dd83f21ea2
Christian Brabandt <cb@256bit.org>
parents: 7408
diff changeset
2851 else
e0acbccdf1fc commit https://github.com/vim/vim/commit/b01f357791f88c7083e58cf2b36509dd83f21ea2
Christian Brabandt <cb@256bit.org>
parents: 7408
diff changeset
2852 need_wait_return = save_need_wait_return;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 }
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2854 changed_int();
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2855 }
10952
835604f3c37a patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents: 10932
diff changeset
2856 ++CHANGEDTICK(curbuf);
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2857 }
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2858
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2859 /*
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2860 * Internal part of changed(), no user interaction.
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2861 */
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2862 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2863 changed_int(void)
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2864 {
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2865 curbuf->b_changed = TRUE;
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2866 ml_setflags(curbuf);
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2867 check_status(curbuf);
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2868 redraw_tabline = TRUE;
2165
733f0dc510c3 Undo changes that are meant for the Vim 7.3 branch.
Bram Moolenaar <bram@vim.org>
parents: 2162
diff changeset
2869 #ifdef FEAT_TITLE
2162
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2870 need_maketitle = TRUE; /* set window title later */
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2871 #endif
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2872 }
0527eb0f6918 After recovery check if the text changed. If it did mark the buffer as
Bram Moolenaar <bram@vim.org>
parents: 2129
diff changeset
2873
7803
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
2874 static void changedOneline(buf_T *buf, linenr_T lnum);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
2875 static void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
2876 static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2878 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2879 * Changed bytes within a single line for the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2880 * - marks the windows on this buffer to be redisplayed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2881 * - marks the buffer changed by calling changed()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2882 * - invalidates cached values
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
2883 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2884 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2885 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2886 changed_bytes(linenr_T lnum, colnr_T col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2887 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2888 changedOneline(curbuf, lnum);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2889 changed_common(lnum, col, lnum + 1, 0L);
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2890
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2891 #ifdef FEAT_DIFF
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2892 /* Diff highlighting in other diff windows may need to be updated too. */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2893 if (curwin->w_p_diff)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2894 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2895 win_T *wp;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2896 linenr_T wlnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2897
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
2898 FOR_ALL_WINDOWS(wp)
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2899 if (wp->w_p_diff && wp != curwin)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2900 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2901 redraw_win_later(wp, VALID);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2902 wlnum = diff_lnum_win(lnum, wp);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2903 if (wlnum > 0)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2904 changedOneline(wp->w_buffer, wlnum);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2905 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2906 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2907 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2908 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2909
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2910 /*
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2911 * Like changed_bytes() but also adjust text properties for "added" bytes.
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2912 * When "added" is negative text was deleted.
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2913 */
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2914 void
15420
9171193ae720 patch 8.1.0718: a couple compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 15398
diff changeset
2915 inserted_bytes(linenr_T lnum, colnr_T col, int added UNUSED)
15341
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2916 {
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2917 changed_bytes(lnum, col);
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2918
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2919 #ifdef FEAT_TEXT_PROP
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2920 if (curbuf->b_has_textprop && added != 0)
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2921 adjust_prop_columns(lnum, col, added);
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2922 #endif
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2923 }
03a7a9fdb792 patch 8.1.0678: text properties as not adjusted for inserted text
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
2924
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2926 changedOneline(buf_T *buf, linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2928 if (buf->b_mod_set)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 /* find the maximum area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2931 if (lnum < buf->b_mod_top)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2932 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2933 else if (lnum >= buf->b_mod_bot)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2934 buf->b_mod_bot = lnum + 1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 /* set the area that must be redisplayed to one line */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2939 buf->b_mod_set = TRUE;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2940 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2941 buf->b_mod_bot = lnum + 1;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
2942 buf->b_mod_xlines = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2943 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2944 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2945
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2946 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2947 * Appended "count" lines below line "lnum" in the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2949 * Takes care of marking the buffer to be redrawn and sets the changed flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2950 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2951 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2952 appended_lines(linenr_T lnum, long count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2954 changed_lines(lnum + 1, 0, lnum + 1, count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 * Like appended_lines(), but adjust marks first.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2961 appended_lines_mark(linenr_T lnum, long count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 {
9225
b0b2bd8e5217 commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents: 8989
diff changeset
2963 /* Skip mark_adjust when adding a line after the last one, there can't
11065
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2964 * be marks there. But it's still needed in diff mode. */
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2965 if (lnum + count < curbuf->b_ml.ml_line_count
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2966 #ifdef FEAT_DIFF
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2967 || curwin->w_p_diff
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2968 #endif
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10952
diff changeset
2969 )
9225
b0b2bd8e5217 commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents: 8989
diff changeset
2970 mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 changed_lines(lnum + 1, 0, lnum + 1, count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2974 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2975 * Deleted "count" lines at line "lnum" in the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2976 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 * Takes care of marking the buffer to be redrawn and sets the changed flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2978 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2979 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2980 deleted_lines(linenr_T lnum, long count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 changed_lines(lnum, 0, lnum + count, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 * Like deleted_lines(), but adjust marks first.
1929
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2987 * Make sure the cursor is on a valid line before calling, a GUI callback may
9230c45fdde6 updated for version 7.2-226
vimboss
parents: 1914
diff changeset
2988 * be triggered to display the cursor.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
2991 deleted_lines_mark(linenr_T lnum, long count)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2994 changed_lines(lnum, 0, lnum + count, -count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2997 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2998 * Changed lines for the current buffer.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2999 * Must be called AFTER the change and after mark_adjust().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3000 * - mark the buffer changed by calling changed()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3001 * - mark the windows on this buffer to be redisplayed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3002 * - invalidate cached values
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3003 * "lnum" is the first line that needs displaying, "lnume" the first line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 * below the changed lines (BEFORE the change).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3005 * When only inserting lines, "lnum" and "lnume" are equal.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 * Takes care of calling changed() and updating b_mod_*.
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3007 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3010 changed_lines(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3011 linenr_T lnum, /* first line with change */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3012 colnr_T col, /* column in first line with change */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3013 linenr_T lnume, /* line below last changed line */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3014 long xtra) /* number of extra lines (negative when deleting) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 {
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3016 changed_lines_buf(curbuf, lnum, lnume, xtra);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3017
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3018 #ifdef FEAT_DIFF
14764
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3019 if (xtra == 0 && curwin->w_p_diff && !diff_internal())
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3020 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3021 /* When the number of lines doesn't change then mark_adjust() isn't
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3022 * called and other diff buffers still need to be marked for
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3023 * displaying. */
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3024 win_T *wp;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3025 linenr_T wlnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3026
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
3027 FOR_ALL_WINDOWS(wp)
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3028 if (wp->w_p_diff && wp != curwin)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3029 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3030 redraw_win_later(wp, VALID);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3031 wlnum = diff_lnum_win(lnum, wp);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3032 if (wlnum > 0)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3033 changed_lines_buf(wp->w_buffer, wlnum,
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3034 lnume - lnum + wlnum, 0L);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3035 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3036 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3037 #endif
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3038
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3039 changed_common(lnum, col, lnume, xtra);
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3040 }
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3041
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3042 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3043 changed_lines_buf(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3044 buf_T *buf,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3045 linenr_T lnum, /* first line with change */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3046 linenr_T lnume, /* line below last changed line */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3047 long xtra) /* number of extra lines (negative when deleting) */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3048 {
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3049 if (buf->b_mod_set)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3050 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3051 /* find the maximum area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3052 if (lnum < buf->b_mod_top)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3053 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3054 if (lnum < buf->b_mod_bot)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 /* adjust old bot position for xtra lines */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3057 buf->b_mod_bot += xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3058 if (buf->b_mod_bot < lnum)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3059 buf->b_mod_bot = lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3060 }
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3061 if (lnume + xtra > buf->b_mod_bot)
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3062 buf->b_mod_bot = lnume + xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3063 buf->b_mod_xlines += xtra;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3064 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3065 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 /* set the area that must be redisplayed */
265
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3068 buf->b_mod_set = TRUE;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3069 buf->b_mod_top = lnum;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3070 buf->b_mod_bot = lnume + xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3071 buf->b_mod_xlines = xtra;
8e2cc4452728 updated for version 7.0071
vimboss
parents: 217
diff changeset
3072 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3075 /*
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3076 * Common code for when a change is was made.
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3077 * See changed_lines() for the arguments.
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3078 * Careful: may trigger autocommands that reload the buffer.
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3079 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3081 changed_common(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3082 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3083 colnr_T col,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3084 linenr_T lnume,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3085 long xtra)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3087 win_T *wp;
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
3088 tabpage_T *tp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3091 int cols;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3092 pos_T *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3093 int add;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 /* mark the buffer as modified */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 changed();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098
14764
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3099 #ifdef FEAT_DIFF
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3100 if (curwin->w_p_diff && diff_internal())
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3101 curtab->tp_diff_update = TRUE;
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3102 #endif
f562b9fbd0d3 patch 8.1.0394: diffs are not always updated correctly
Christian Brabandt <cb@256bit.org>
parents: 14698
diff changeset
3103
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3104 /* set the '. mark */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3105 if (!cmdmod.keepjumps)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 curbuf->b_last_change.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 curbuf->b_last_change.col = col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 #ifdef FEAT_JUMPLIST
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 /* Create a new entry if a new undo-able change was started or we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 * don't have an entry yet. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113 if (curbuf->b_new_change || curbuf->b_changelistlen == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3114 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3115 if (curbuf->b_changelistlen == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 add = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3119 /* Don't create a new entry when the line number is the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3120 * as the last one and the column is not too far away. Avoids
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3121 * creating many entries for typing "xxxxx". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3122 p = &curbuf->b_changelist[curbuf->b_changelistlen - 1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 if (p->lnum != lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3124 add = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3125 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3126 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3127 cols = comp_textwidth(FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3128 if (cols == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 cols = 79;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 add = (p->col + cols < col || col + cols < p->col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3132 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 if (add)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 /* This is the first of a new sequence of undo-able changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3136 * and it's at some distance of the last change. Use a new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3137 * position in the changelist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3138 curbuf->b_new_change = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3139
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3140 if (curbuf->b_changelistlen == JUMPLISTSIZE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3141 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 /* changelist is full: remove oldest entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 curbuf->b_changelistlen = JUMPLISTSIZE - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3144 mch_memmove(curbuf->b_changelist, curbuf->b_changelist + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3145 sizeof(pos_T) * (JUMPLISTSIZE - 1));
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
3146 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3147 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 /* Correct position in changelist for other windows on
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149 * this buffer. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3150 if (wp->w_buffer == curbuf && wp->w_changelistidx > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3151 --wp->w_changelistidx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3152 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153 }
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
3154 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3156 /* For other windows, if the position in the changelist is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 * at the end it stays at the end. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3158 if (wp->w_buffer == curbuf
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3159 && wp->w_changelistidx == curbuf->b_changelistlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3160 ++wp->w_changelistidx;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3161 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3162 ++curbuf->b_changelistlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3163 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3165 curbuf->b_changelist[curbuf->b_changelistlen - 1] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3166 curbuf->b_last_change;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3167 /* The current window is always after the last change, so that "g,"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3168 * takes you back to it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3169 curwin->w_changelistidx = curbuf->b_changelistlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3170 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3171 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3172
1863
63369d73b551 updated for version 7.2-161
vimboss
parents: 1848
diff changeset
3173 FOR_ALL_TAB_WINDOWS(tp, wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3175 if (wp->w_buffer == curbuf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3177 /* Mark this window to be redrawn later. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3178 if (wp->w_redr_type < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3179 wp->w_redr_type = VALID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3181 /* Check if a change in the buffer has invalidated the cached
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3182 * values for the cursor. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3183 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3184 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3185 * Update the folds for this window. Can't postpone this, because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3186 * a following operator might work on the whole fold: ">>dd".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3187 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3188 foldUpdate(wp, lnum, lnume + xtra - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 /* The change may cause lines above or below the change to become
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3191 * included in a fold. Set lnum/lnume to the first/last line that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3192 * might be displayed differently.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3193 * Set w_cline_folded here as an efficient way to update it when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3194 * inserting lines just above a closed fold. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3195 i = hasFoldingWin(wp, lnum, &lnum, NULL, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3196 if (wp->w_cursor.lnum == lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3197 wp->w_cline_folded = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3198 i = hasFoldingWin(wp, lnume, NULL, &lnume, FALSE, NULL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3199 if (wp->w_cursor.lnum == lnume)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3200 wp->w_cline_folded = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3202 /* If the changed line is in a range of previously folded lines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3203 * compare with the first line in that range. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3204 if (wp->w_cursor.lnum <= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3206 i = find_wl_entry(wp, lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3207 if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3208 changed_line_abv_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3209 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3210 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3212 if (wp->w_cursor.lnum > lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3213 changed_line_abv_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3214 else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3215 changed_cline_bef_curs_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3216 if (wp->w_botline >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3218 /* Assume that botline doesn't change (inserted lines make
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3219 * other lines scroll down below botline). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3220 approximate_botline_win(wp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3221 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3222
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3223 /* Check if any w_lines[] entries have become invalid.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3224 * For entries below the change: Correct the lnums for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3225 * inserted/deleted lines. Makes it possible to stop displaying
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3226 * after the change. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3227 for (i = 0; i < wp->w_lines_valid; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3228 if (wp->w_lines[i].wl_valid)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3229 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3230 if (wp->w_lines[i].wl_lnum >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3231 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3232 if (wp->w_lines[i].wl_lnum < lnume)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3233 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3234 /* line included in change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3235 wp->w_lines[i].wl_valid = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3236 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3237 else if (xtra != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3238 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3239 /* line below change */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3240 wp->w_lines[i].wl_lnum += xtra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3241 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3242 wp->w_lines[i].wl_lastlnum += xtra;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3243 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3244 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3246 #ifdef FEAT_FOLDING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3247 else if (wp->w_lines[i].wl_lastlnum >= lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 /* change somewhere inside this range of folded lines,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3250 * may need to be redrawn */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 wp->w_lines[i].wl_valid = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3253 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3254 }
1987
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3255
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3256 #ifdef FEAT_FOLDING
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3257 /* Take care of side effects for setting w_topline when folds have
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3258 * changed. Esp. when the buffer was changed in another window. */
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3259 if (hasAnyFolding(wp))
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3260 set_topline(wp, wp->w_topline);
613517f0b72a updated for version 7.2-284
vimboss
parents: 1938
diff changeset
3261 #endif
5885
5cb1828fd005 updated for version 7.4.285
Bram Moolenaar <bram@vim.org>
parents: 5873
diff changeset
3262 /* relative numbering may require updating more */
5cb1828fd005 updated for version 7.4.285
Bram Moolenaar <bram@vim.org>
parents: 5873
diff changeset
3263 if (wp->w_p_rnu)
5cb1828fd005 updated for version 7.4.285
Bram Moolenaar <bram@vim.org>
parents: 5873
diff changeset
3264 redraw_win_later(wp, SOME_VALID);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3265 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3266 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3267
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3268 /* Call update_screen() later, which checks out what needs to be redrawn,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3269 * since it notices b_mod_set and then uses b_mod_*. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3270 if (must_redraw < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3271 must_redraw = VALID;
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
3272
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
3273 /* when the cursor line is changed always trigger CursorMoved */
1010
ba32a005373a updated for version 7.0-136
vimboss
parents: 983
diff changeset
3274 if (lnum <= curwin->w_cursor.lnum
ba32a005373a updated for version 7.0-136
vimboss
parents: 983
diff changeset
3275 && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum)
694
07d199fe02ed updated for version 7.0209
vimboss
parents: 681
diff changeset
3276 last_cursormoved.lnum = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3277 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3278
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3279 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3280 * unchanged() is called when the changed flag must be reset for buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3281 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3282 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3283 unchanged(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3284 buf_T *buf,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3285 int ff) /* also reset 'fileformat' */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3286 {
2685
862d920800b1 updated for version 7.3.103
Bram Moolenaar <bram@vim.org>
parents: 2672
diff changeset
3287 if (buf->b_changed || (ff && file_ff_differs(buf, FALSE)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3288 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3289 buf->b_changed = 0;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
3290 ml_setflags(buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3291 if (ff)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3292 save_file_ff(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3293 check_status(buf);
673
513866ffe6af updated for version 7.0200
vimboss
parents: 671
diff changeset
3294 redraw_tabline = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3295 #ifdef FEAT_TITLE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3296 need_maketitle = TRUE; /* set window title later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3297 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3298 }
10952
835604f3c37a patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents: 10932
diff changeset
3299 ++CHANGEDTICK(buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3300 #ifdef FEAT_NETBEANS_INTG
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3301 netbeans_unmodified(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3302 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3303 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3305 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3306 * check_status: called when the status bars for the buffer 'buf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3307 * need to be updated
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3308 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3309 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3310 check_status(buf_T *buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3311 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3312 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3313
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
3314 FOR_ALL_WINDOWS(wp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3315 if (wp->w_buffer == buf && wp->w_status_height)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3317 wp->w_redr_status = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3318 if (must_redraw < VALID)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3319 must_redraw = VALID;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3320 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3323 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3324 * If the file is readonly, give a warning message with the first change.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3325 * Don't do this for autocommands.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3326 * Don't use emsg(), because it flushes the macro buffer.
548
f43150a669dc updated for version 7.0155
vimboss
parents: 474
diff changeset
3327 * If we have undone all changes b_changed will be FALSE, but "b_did_warn"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3328 * will be TRUE.
2189
cb94c42c0e1a updated for version 7.2.445
Bram Moolenaar <bram@vim.org>
parents: 2165
diff changeset
3329 * Careful: may trigger autocommands that reload the buffer.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3330 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3331 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3332 change_warning(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3333 int col) /* column for message; non-zero when in insert
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3334 mode and 'showmode' is on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3335 {
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3336 static char *w_readonly = N_("W10: Warning: Changing a readonly file");
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3337
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3338 if (curbuf->b_did_warn == FALSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3339 && curbufIsChanged() == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3340 && !autocmd_busy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3341 && curbuf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3342 {
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
3343 ++curbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3344 apply_autocmds(EVENT_FILECHANGEDRO, NULL, NULL, FALSE, curbuf);
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
3345 --curbuf_lock;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3346 if (!curbuf->b_p_ro)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3347 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3348 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3349 * Do what msg() does, but with a column offset if the warning should
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3350 * be after the mode message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3351 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3352 msg_start();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3353 if (msg_row == Rows - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3354 msg_col = col;
11158
501f46f7644c patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
3355 msg_source(HL_ATTR(HLF_W));
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3356 msg_puts_attr(_(w_readonly), HL_ATTR(HLF_W) | MSG_HIST);
1848
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3357 #ifdef FEAT_EVAL
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3358 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_readonly), -1);
cfcc1421f5e4 updated for version 7.2-146
vimboss
parents: 1752
diff changeset
3359 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3360 msg_clr_eos();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3361 (void)msg_end();
10807
82c43bca568e patch 8.0.0293: some tests have a one or three second wait
Christian Brabandt <cb@256bit.org>
parents: 10781
diff changeset
3362 if (msg_silent == 0 && !silent_mode
82c43bca568e patch 8.0.0293: some tests have a one or three second wait
Christian Brabandt <cb@256bit.org>
parents: 10781
diff changeset
3363 #ifdef FEAT_EVAL
82c43bca568e patch 8.0.0293: some tests have a one or three second wait
Christian Brabandt <cb@256bit.org>
parents: 10781
diff changeset
3364 && time_for_testing != 1
82c43bca568e patch 8.0.0293: some tests have a one or three second wait
Christian Brabandt <cb@256bit.org>
parents: 10781
diff changeset
3365 #endif
82c43bca568e patch 8.0.0293: some tests have a one or three second wait
Christian Brabandt <cb@256bit.org>
parents: 10781
diff changeset
3366 )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3367 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3368 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3369 ui_delay(1000L, TRUE); /* give the user time to think about it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3371 curbuf->b_did_warn = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3372 redraw_cmdline = FALSE; /* don't redraw and erase the message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3373 if (msg_row < Rows - 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3374 showmode();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3375 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3376 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3377
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3378 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3379 * Ask for a reply from the user, a 'y' or a 'n'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3380 * No other characters are accepted, the message is repeated until a valid
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3381 * reply is entered or CTRL-C is hit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3382 * If direct is TRUE, don't use vgetc() but ui_inchar(), don't get characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3383 * from any buffers but directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3384 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3385 * return the 'y' or 'n'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3386 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3387 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3388 ask_yesno(char_u *str, int direct)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3389 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3390 int r = ' ';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3391 int save_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3393 if (exiting) /* put terminal in raw mode for this question */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3394 settmode(TMODE_RAW);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3395 ++no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3396 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3397 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3398 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3399 State = CONFIRM; /* mouse behaves like with :confirm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3400 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3401 setmouse(); /* disables mouse for xterm */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3402 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3403 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3404 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3405
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3406 while (r != 'y' && r != 'n')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3407 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3408 /* same highlighting as for wait_return */
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
3409 smsg_attr(HL_ATTR(HLF_R), "%s (y/n)?", str);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3410 if (direct)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3411 r = get_keystroke();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3412 else
1474
276244befa5b updated for version 7.1-189
vimboss
parents: 1470
diff changeset
3413 r = plain_vgetc();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414 if (r == Ctrl_C || r == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 r = 'n';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416 msg_putchar(r); /* show what you typed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 --no_wait_return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 State = save_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 #ifdef FEAT_MOUSE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 setmouse();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 return r;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3430 #if defined(FEAT_MOUSE) || defined(PROTO)
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3431 /*
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3432 * Return TRUE if "c" is a mouse key.
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3433 */
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3434 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3435 is_mouse_key(int c)
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3436 {
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3437 return c == K_LEFTMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3438 || c == K_LEFTMOUSE_NM
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3439 || c == K_LEFTDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3440 || c == K_LEFTRELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3441 || c == K_LEFTRELEASE_NM
12865
ebb4f6c93598 patch 8.0.1309: cannot use 'balloonexpr' in a terminal
Christian Brabandt <cb@256bit.org>
parents: 12716
diff changeset
3442 || c == K_MOUSEMOVE
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3443 || c == K_MIDDLEMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3444 || c == K_MIDDLEDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3445 || c == K_MIDDLERELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3446 || c == K_RIGHTMOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3447 || c == K_RIGHTDRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3448 || c == K_RIGHTRELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3449 || c == K_MOUSEDOWN
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3450 || c == K_MOUSEUP
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3451 || c == K_MOUSELEFT
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3452 || c == K_MOUSERIGHT
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3453 || c == K_X1MOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3454 || c == K_X1DRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3455 || c == K_X1RELEASE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3456 || c == K_X2MOUSE
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3457 || c == K_X2DRAG
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3458 || c == K_X2RELEASE;
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3459 }
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3460 #endif
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3461
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 * Get a key stroke directly from the user.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 * Ignores mouse clicks and scrollbar events, except a click for the left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 * button (used at the more prompt).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 * Doesn't use vgetc(), because it syncs undo and eats mapped characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 * Disadvantage: typeahead is ignored.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468 * Translates the interrupt character for unix to ESC.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3471 get_keystroke(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 {
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3473 char_u *buf = NULL;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3474 int buflen = 150;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3475 int maxlen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3476 int len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3477 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3478 int save_mapped_ctrl_c = mapped_ctrl_c;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3479 int waited = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3480
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3481 mapped_ctrl_c = FALSE; /* mappings are not used here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3482 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3484 cursor_on();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3485 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3486
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3487 /* Leave some room for check_termcode() to insert a key code into (max
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3488 * 5 chars plus NUL). And fix_input_buffer() can triple the number of
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3489 * bytes. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3490 maxlen = (buflen - 6 - len) / 3;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3491 if (buf == NULL)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3492 buf = alloc(buflen);
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3493 else if (maxlen < 10)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3494 {
6596
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
3495 char_u *t_buf = buf;
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
3496
3596
34724dc5172b updated for version 7.3.558
Bram Moolenaar <bram@vim.org>
parents: 3592
diff changeset
3497 /* Need some more space. This might happen when receiving a long
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3498 * escape sequence. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3499 buflen += 100;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3500 buf = vim_realloc(buf, buflen);
6596
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
3501 if (buf == NULL)
f8f2a61e538d updated for version 7.4.624
Bram Moolenaar <bram@vim.org>
parents: 6174
diff changeset
3502 vim_free(t_buf);
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3503 maxlen = (buflen - 6 - len) / 3;
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3504 }
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3505 if (buf == NULL)
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3506 {
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3507 do_outofmem_msg((long_u)buflen);
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3508 return ESC; /* panic! */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3509 }
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3510
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3511 /* First time: blocking wait. Second time: wait up to 100ms for a
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3512 * terminal code to complete. */
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3513 n = ui_inchar(buf + len, maxlen, len == 0 ? -1L : 100L, 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3514 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3515 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 /* Replace zero and CSI by a special key code. */
9896
7b39615c0db1 commit https://github.com/vim/vim/commit/6bff02eb530aa29aafa2cb5627399837be7a5dd5
Christian Brabandt <cb@256bit.org>
parents: 9649
diff changeset
3517 n = fix_input_buffer(buf + len, n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 len += n;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3519 waited = 0;
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3520 }
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3521 else if (len > 0)
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3522 ++waited; /* keep track of the waiting time */
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3523
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3524 /* Incomplete termcode and not timed out yet: get more characters */
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3525 if ((n = check_termcode(1, buf, buflen, &len)) < 0
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3526 && (!p_ttimeout || waited * 100L < (p_ttm < 0 ? p_tm : p_ttm)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 continue;
964
e905716f6a3a updated for version 7.0-090
vimboss
parents: 957
diff changeset
3528
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
3529 if (n == KEYLEN_REMOVED) /* key code removed */
2721
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3530 {
2723
2e72d84e8965 updated for version 7.3.139
Bram Moolenaar <bram@vim.org>
parents: 2721
diff changeset
3531 if (must_redraw != 0 && !need_wait_return && (State & CMDLINE) == 0)
2721
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3532 {
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3533 /* Redrawing was postponed, do it now. */
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3534 update_screen(0);
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3535 setcursor(); /* put cursor back where it belongs */
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3536 }
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
3537 continue;
2721
417c04135ca2 updated for version 7.3.137
Bram Moolenaar <bram@vim.org>
parents: 2685
diff changeset
3538 }
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
3539 if (n > 0) /* found a termcode: adjust length */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 len = n;
2672
6a2e4860134b updated for version 7.3.091
Bram Moolenaar <bram@vim.org>
parents: 2652
diff changeset
3541 if (len == 0) /* nothing typed yet */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3543
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3544 /* Handle modifier and/or special key code. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3545 n = buf[0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3546 if (n == K_SPECIAL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3547 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3548 n = TO_SPECIAL(buf[1], buf[2]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3549 if (buf[1] == KS_MODIFIER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 || n == K_IGNORE
4225
a82ef37d38c0 updated for version 7.3.864
Bram Moolenaar <bram@vim.org>
parents: 4221
diff changeset
3551 #ifdef FEAT_MOUSE
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3552 || (is_mouse_key(n) && n != K_LEFTMOUSE)
4225
a82ef37d38c0 updated for version 7.3.864
Bram Moolenaar <bram@vim.org>
parents: 4221
diff changeset
3553 #endif
4221
dd4f3ceb5d86 updated for version 7.3.862
Bram Moolenaar <bram@vim.org>
parents: 4207
diff changeset
3554 #ifdef FEAT_GUI
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555 || n == K_VER_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3556 || n == K_HOR_SCROLLBAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 if (buf[1] == KS_MODIFIER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 mod_mask = buf[2];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 len -= 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563 if (len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 mch_memmove(buf, buf + 3, (size_t)len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 }
828
01583c79d5f4 updated for version 7.0d03
vimboss
parents: 827
diff changeset
3567 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3568 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3569 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571 if (MB_BYTE2LEN(n) > len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 continue; /* more bytes to get */
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3573 buf[len >= buflen ? buflen - 1 : len] = NUL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 n = (*mb_ptr2char)(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3577 if (n == intr_char)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3578 n = ESC;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3580 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3581 }
3328
a27fac494e70 updated for version 7.3.431
Bram Moolenaar <bram@vim.org>
parents: 3261
diff changeset
3582 vim_free(buf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 mapped_ctrl_c = save_mapped_ctrl_c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 /*
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3589 * Get a number from the user.
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3590 * When "mouse_used" is not NULL allow using the mouse.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3593 get_number(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3594 int colon, /* allow colon to abort */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3595 int *mouse_used)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3596 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3597 int n = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 int c;
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3599 int typed = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3600
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3601 if (mouse_used != NULL)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3602 *mouse_used = FALSE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3603
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3604 /* When not printing messages, the user won't know what to type, return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3605 * zero (as if CR was hit). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 if (msg_silent != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3607 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 #ifdef USE_ON_FLY_SCROLL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 dont_scroll = TRUE; /* disallow scrolling here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612 ++no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 ++allow_keys; /* no mapping here, but recognize keys */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 windgoto(msg_row, msg_col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 c = safe_vgetc();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3618 if (VIM_ISDIGIT(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3619 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3620 n = n * 10 + c - '0';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3621 msg_putchar(c);
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3622 ++typed;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 else if (c == K_DEL || c == K_KDEL || c == K_BS || c == Ctrl_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 {
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3626 if (typed > 0)
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3627 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3628 msg_puts("\b \b");
810
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3629 --typed;
9f345c48220b updated for version 7.0c
vimboss
parents: 777
diff changeset
3630 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 n /= 10;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 }
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3633 #ifdef FEAT_MOUSE
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3634 else if (mouse_used != NULL && c == K_LEFTMOUSE)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3635 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3636 *mouse_used = TRUE;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3637 n = mouse_row + 1;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3638 break;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3639 }
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3640 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 else if (n == 0 && c == ':' && colon)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 stuffcharReadbuff(':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 if (!exmode_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645 cmdline_row = msg_row;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 skip_redraw = TRUE; /* skip redraw once */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 do_redraw = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3648 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3649 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3650 else if (c == CAR || c == NL || c == Ctrl_C || c == ESC)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3651 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3652 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3653 --no_mapping;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3654 --allow_keys;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3655 return n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3658 /*
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3659 * Ask the user to enter a number.
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3660 * When "mouse_used" is not NULL allow using the mouse and in that case return
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3661 * the line number.
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3662 */
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3663 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3664 prompt_for_number(int *mouse_used)
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3665 {
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3666 int i;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3667 int save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3668 int save_State;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3669
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3670 /* When using ":silent" assume that <CR> was entered. */
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
3671 if (mouse_used != NULL)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3672 msg_puts(_("Type number and <Enter> or click with mouse (empty cancels): "));
375
f14cbd913415 updated for version 7.0097
vimboss
parents: 374
diff changeset
3673 else
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3674 msg_puts(_("Type number and <Enter> (empty cancels): "));
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3675
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3676 // Set the state such that text can be selected/copied/pasted and we still
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3677 // get mouse events. redraw_after_callback() will not redraw if cmdline_row
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3678 // is zero.
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3679 save_cmdline_row = cmdline_row;
957
3dc6072e0a25 updated for version 7.0-083
vimboss
parents: 927
diff changeset
3680 cmdline_row = 0;
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3681 save_State = State;
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3682 State = CMDLINE;
13768
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3683 #ifdef FEAT_MOUSE
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3684 // May show different mouse shape.
13768
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3685 setmouse();
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3686 #endif
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3687
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3688 i = get_number(TRUE, mouse_used);
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3689 if (KeyTyped)
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3690 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3691 /* don't call wait_return() now */
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
3692 /* msg_putchar('\n'); */
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3693 cmdline_row = msg_row - 1;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3694 need_wait_return = FALSE;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3695 msg_didany = FALSE;
1938
5ed9395c1864 updated for version 7.2-235
vimboss
parents: 1937
diff changeset
3696 msg_didout = FALSE;
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3697 }
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3698 else
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3699 cmdline_row = save_cmdline_row;
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3700 State = save_State;
13768
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3701 #ifdef FEAT_MOUSE
14629
100a44722322 patch 8.1.0328: inputlist() doesn't work with a timer
Christian Brabandt <cb@256bit.org>
parents: 14585
diff changeset
3702 // May need to restore mouse shape.
13768
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3703 setmouse();
bcef80912112 patch 8.0.1756: GUI: after prompting for a number the mouse shape is wrong
Christian Brabandt <cb@256bit.org>
parents: 13380
diff changeset
3704 #endif
344
7033303ea0c0 updated for version 7.0089
vimboss
parents: 323
diff changeset
3705
323
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3706 return i;
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3707 }
03b3684919e3 updated for version 7.0084
vimboss
parents: 274
diff changeset
3708
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3710 msgmore(long n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712 long pn;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 if (global_busy /* no messages now, wait until global is finished */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715 || !messaging()) /* 'lazyredraw' set, don't do messages now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3716 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3717
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3718 /* We don't want to overwrite another important message, but do overwrite
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3719 * a previous "more lines" or "fewer lines" message, so that "5dd" and
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3720 * then "put" reports the last action. */
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3721 if (keep_msg != NULL && !keep_msg_more)
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3722 return;
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3723
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3724 if (n > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3725 pn = n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3726 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3727 pn = -n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3729 if (pn > p_report)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3730 {
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
3731 if (n > 0)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3732 vim_snprintf(msg_buf, MSG_BUF_LEN,
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
3733 NGETTEXT("%ld more line", "%ld more lines", pn), pn);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 else
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3735 vim_snprintf(msg_buf, MSG_BUF_LEN,
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
3736 NGETTEXT("%ld line less", "%ld fewer lines", pn), pn);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 if (got_int)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3738 vim_strcat((char_u *)msg_buf, (char_u *)_(" (Interrupted)"),
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3739 MSG_BUF_LEN);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3740 if (msg(msg_buf))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3741 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3742 set_keep_msg((char_u *)msg_buf, 0);
135
b5fc81a825a1 updated for version 7.0044
vimboss
parents: 115
diff changeset
3743 keep_msg_more = TRUE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3748 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3749 * flush map and typeahead buffers and give a warning for an error
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3752 beep_flush(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3753 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3754 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755 {
14909
c97b4b537572 patch 8.1.0466: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
3756 flush_buffers(FLUSH_MINIMAL);
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3757 vim_beep(BO_ERROR);
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3758 }
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3759 }
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3760
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3761 /*
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3762 * Give a warning for an error.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3763 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3764 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3765 vim_beep(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3766 unsigned val) /* one of the BO_ values, e.g., BO_OPER */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3767 {
13272
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3768 #ifdef FEAT_EVAL
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3769 called_vim_beep = TRUE;
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3770 #endif
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3771
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3772 if (emsg_silent == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3773 {
6949
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3774 if (!((bo_flags & val) || (bo_flags & BO_ALL)))
1e621b31948b patch 7.4.793
Bram Moolenaar <bram@vim.org>
parents: 6803
diff changeset
3775 {
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3776 #ifdef ELAPSED_FUNC
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3777 static int did_init = FALSE;
15525
3ef31ce9d9f9 patch 8.1.0770: inconsistent use of ELAPSED_FUNC
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3778 static elapsed_T start_tv;
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3779
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3780 /* Only beep once per half a second, otherwise a sequence of beeps
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3781 * would freeze Vim. */
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3782 if (!did_init || ELAPSED_FUNC(start_tv) > 500)
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3783 {
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3784 did_init = TRUE;
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3785 ELAPSED_INIT(start_tv);
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3786 #endif
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3787 if (p_vb
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3788 #ifdef FEAT_GUI
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3789 /* While the GUI is starting up the termcap is set for
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3790 * the GUI but the output still goes to a terminal. */
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3791 && !(gui.in_use && gui.starting)
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3792 #endif
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3793 )
13314
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3794 {
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3795 out_str_cf(T_VB);
13314
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3796 #ifdef FEAT_VTP
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3797 /* No restore color information, refresh the screen. */
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3798 if (has_vtp_working() != 0
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3799 # ifdef FEAT_TERMGUICOLORS
13823
d0d8125ba692 patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13772
diff changeset
3800 && (p_tgc || (!p_tgc && t_colors >= 256))
13314
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3801 # endif
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3802 )
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3803 {
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3804 redraw_later(CLEAR);
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3805 update_screen(0);
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3806 redrawcmd();
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3807 }
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3808 #endif
65c3e8259124 patch 8.0.1531: cannot use 24 bit colors in MS-Windows console
Christian Brabandt <cb@256bit.org>
parents: 13272
diff changeset
3809 }
11601
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3810 else
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3811 out_char(BELL);
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3812 #ifdef ELAPSED_FUNC
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3813 }
0a5d405e2520 patch 8.0.0683: visual bell flashes too quickly
Christian Brabandt <cb@256bit.org>
parents: 11384
diff changeset
3814 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3815 }
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3816
13272
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3817 /* When 'debug' contains "beep" produce a message. If we are sourcing
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3818 * a script or executing a function give the user a hint where the beep
abaebba89fd4 patch 8.0.1510: cannot test if a command causes a beep
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3819 * comes from. */
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3820 if (vim_strchr(p_debug, 'e') != NULL)
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3821 {
11158
501f46f7644c patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
3822 msg_source(HL_ATTR(HLF_W));
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15525
diff changeset
3823 msg_attr(_("Beep!"), HL_ATTR(HLF_W));
169
0e902b8f511f updated for version 7.0051
vimboss
parents: 164
diff changeset
3824 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3826 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3828 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3829 * To get the "real" home directory:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3830 * - get value of $HOME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3831 * For Unix:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3832 * - go to that directory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3833 * - do mch_dirname() to get the real name of that directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3834 * This also works with mounts and links.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3835 * Don't do this for MS-DOS, it will change the "current dir" for a drive.
15046
c1be7c8bb602 patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents: 14909
diff changeset
3836 * For Windows:
c1be7c8bb602 patch 8.1.0534: MS-Windows installer uses different $HOME than Vim
Bram Moolenaar <Bram@vim.org>
parents: 14909
diff changeset
3837 * This code is duplicated in init_homedir() in dosinst.c. Keep in sync!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3838 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3839 static char_u *homedir = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3840
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3841 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3842 init_homedir(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3844 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3845
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3846 /* In case we are called a second time (when 'encoding' changes). */
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
3847 VIM_CLEAR(homedir);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3848
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3850 var = mch_getenv((char_u *)"SYS$LOGIN");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3851 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3852 var = mch_getenv((char_u *)"HOME");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3853 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3854
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3855 #ifdef WIN3264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3856 /*
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3857 * Typically, $HOME is not defined on Windows, unless the user has
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3858 * specifically defined it for Vim's sake. However, on Windows NT
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3859 * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3860 * each user. Try constructing $HOME from these.
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3861 */
12269
d2373927d76d patch 8.0.1014: old compiler doesn't know uint32_t
Christian Brabandt <cb@256bit.org>
parents: 12265
diff changeset
3862 if (var == NULL || *var == NUL)
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3863 {
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3864 char_u *homedrive, *homepath;
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3865
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3866 homedrive = mch_getenv((char_u *)"HOMEDRIVE");
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3867 homepath = mch_getenv((char_u *)"HOMEPATH");
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3868 if (homepath == NULL || *homepath == NUL)
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3869 homepath = (char_u *)"\\";
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3870 if (homedrive != NULL
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3871 && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL)
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3872 {
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3873 sprintf((char *)NameBuff, "%s%s", homedrive, homepath);
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3874 if (NameBuff[0] != NUL)
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3875 var = NameBuff;
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3876 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3877 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3878
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3879 if (var == NULL)
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3880 var = mch_getenv((char_u *)"USERPROFILE");
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3881
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3882 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3883 * Weird but true: $HOME may contain an indirect reference to another
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3884 * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3885 * when $HOME is being set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3886 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3887 if (var != NULL && *var == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3888 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3889 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3890 char_u *exp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3891
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3892 p = vim_strchr(var + 1, '%');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3893 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3894 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 410
diff changeset
3895 vim_strncpy(NameBuff, var + 1, p - (var + 1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3896 exp = mch_getenv(NameBuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3897 if (exp != NULL && *exp != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3898 && STRLEN(exp) + STRLEN(p) < MAXPATHL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3899 {
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 265
diff changeset
3900 vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3901 var = NameBuff;
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3902 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3903 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3904 }
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3905
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3906 if (var != NULL && *var == NUL) /* empty is same as not set */
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3907 var = NULL;
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3908
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3909 if (enc_utf8 && var != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3910 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3911 int len;
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
3912 char_u *pp = NULL;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3913
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3914 /* Convert from active codepage to UTF-8. Other conversions are
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3915 * not done, because they would fail for non-ASCII characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
3916 acp_to_enc(var, (int)STRLEN(var), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3917 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3918 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3919 homedir = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3920 return;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3921 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
3922 }
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3923
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3924 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3925 * Default home dir is C:/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3926 * Best assumption we can make in such a situation.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3927 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3928 if (var == NULL)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
3929 var = (char_u *)"C:/";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3930 #endif
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
3931
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3932 if (var != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3933 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3934 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3935 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3936 * Change to the directory and get the actual path. This resolves
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3937 * links. Don't do it when we can't return.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3938 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3939 if (mch_dirname(NameBuff, MAXPATHL) == OK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3940 && mch_chdir((char *)NameBuff) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3942 if (!mch_chdir((char *)var) && mch_dirname(IObuff, IOSIZE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3943 var = IObuff;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3944 if (mch_chdir((char *)NameBuff) != 0)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
3945 emsg(_(e_prev_dir));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3946 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3947 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3948 homedir = vim_strsave(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3949 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3951
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3952 #if defined(EXITFREE) || defined(PROTO)
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3953 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3954 free_homedir(void)
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3955 {
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3956 vim_free(homedir);
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3957 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3958
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3959 # ifdef FEAT_CMDL_COMPL
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3960 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3961 free_users(void)
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3962 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3963 ga_clear_strings(&ga_users);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3964 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
3965 # endif
359
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3966 #endif
6c62b9b939bd updated for version 7.0093
vimboss
parents: 344
diff changeset
3967
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3968 /*
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3969 * Call expand_env() and store the result in an allocated string.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3970 * This is not very memory efficient, this expects the result to be freed
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3971 * again soon.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3972 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3973 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3974 expand_env_save(char_u *src)
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3975 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3976 return expand_env_save_opt(src, FALSE);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3977 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3978
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3979 /*
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3980 * Idem, but when "one" is TRUE handle the string as one file name, only
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3981 * expand "~" at the start.
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3982 */
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3983 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
3984 expand_env_save_opt(char_u *src, int one)
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3985 {
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3986 char_u *p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3987
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3988 p = alloc(MAXPATHL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3989 if (p != NULL)
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3990 expand_env_esc(src, p, MAXPATHL, FALSE, one, NULL);
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3991 return p;
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3992 }
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3993
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3994 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3995 * Expand environment variable with path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3996 * "~/" is also expanded, using $HOME. For Unix "~user/" is expanded.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
3997 * Skips over "\ ", "\~" and "\$" (not for Win32 though).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3998 * If anything fails no expansion is done and dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3999 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4000 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4001 expand_env(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4002 char_u *src, /* input string e.g. "$HOME/vim.hlp" */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4003 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4004 int dstlen) /* maximum length of the result */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4005 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
4006 expand_env_esc(src, dst, dstlen, FALSE, FALSE, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4007 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4009 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4010 expand_env_esc(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4011 char_u *srcp, /* input string e.g. "$HOME/vim.hlp" */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4012 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4013 int dstlen, /* maximum length of the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4014 int esc, /* escape spaces in expanded variables */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4015 int one, /* "srcp" is one file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4016 char_u *startstr) /* start again after this (can be NULL) */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4017 {
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4018 char_u *src;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4019 char_u *tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4020 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4021 char_u *var;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4022 int copy_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4023 int mustfree; /* var was allocated, need to free it later */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4024 int at_start = TRUE; /* at start of a name */
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4025 int startstr_len = 0;
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4026
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4027 if (startstr != NULL)
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
4028 startstr_len = (int)STRLEN(startstr);
374
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4029
575dacb554d8 updated for version 7.0096
vimboss
parents: 359
diff changeset
4030 src = skipwhite(srcp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4031 --dstlen; /* leave one char space for "\," */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4032 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4033 {
7038
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4034 #ifdef FEAT_EVAL
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4035 /* Skip over `=expr`. */
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4036 if (src[0] == '`' && src[1] == '=')
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4037 {
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4038 size_t len;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4039
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4040 var = src;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4041 src += 2;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4042 (void)skip_expr(&src);
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4043 if (*src == '`')
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4044 ++src;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4045 len = src - var;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4046 if (len > (size_t)dstlen)
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4047 len = dstlen;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4048 vim_strncpy(dst, var, len);
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4049 dst += len;
7066
094c8ccdc279 commit https://github.com/vim/vim/commit/5df1ed2de3fa9dcace996b9a0a4c9b3cea79cf1e
Christian Brabandt <cb@256bit.org>
parents: 7038
diff changeset
4050 dstlen -= (int)len;
7038
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4051 continue;
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4052 }
76042a56ab85 commit https://github.com/vim/vim/commit/be83b73ddb2ee8297037166d243f72e3423a3ce3
Christian Brabandt <cb@256bit.org>
parents: 7036
diff changeset
4053 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4054 copy_char = TRUE;
22
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
4055 if ((*src == '$'
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
4056 #ifdef VMS
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
4057 && at_start
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
4058 #endif
cc049b00ee70 updated for version 7.0014
vimboss
parents: 17
diff changeset
4059 )
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
4060 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4061 || *src == '%'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4062 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4063 || (*src == '~' && at_start))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4064 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4065 mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4067 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4068 * The variable name is copied into dst temporarily, because it may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4069 * be a string in read-only memory and a NUL needs to be appended.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4070 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4071 if (*src != '~') /* environment var */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4072 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4073 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4074 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4075 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4076
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4077 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4078 /* Unix has ${var-name} type environment vars */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4079 if (*tail == '{' && !vim_isIDc('{'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4081 tail++; /* ignore '{' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4082 while (c-- > 0 && *tail && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4083 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4084 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4085 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4086 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4087 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4088 while (c-- > 0 && *tail != NUL && ((vim_isIDc(*tail))
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
4089 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4090 || (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4091 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4092 ))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4093 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4094 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4096 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4097
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
4098 #if defined(MSWIN) || defined(UNIX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4099 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4100 if (src[1] == '{' && *tail != '}')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4101 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4102 if (*src == '%' && *tail != '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4103 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4104 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4105 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4106 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4107 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4108 if (src[1] == '{')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4109 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4110 if (*src == '%')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4111 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4112 ++tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4113 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4114 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4115 var = vim_getenv(dst, &mustfree);
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
4116 #if defined(MSWIN) || defined(UNIX)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4117 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4118 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4120 /* home directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4121 else if ( src[1] == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4122 || vim_ispathsep(src[1])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4123 || vim_strchr((char_u *)" ,\t\n", src[1]) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4124 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4125 var = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4126 tail = src + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4127 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4128 else /* user directory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4129 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4130 #if defined(UNIX) || (defined(VMS) && defined(USER_HOME))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4131 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4132 * Copy ~user to dst[], so we can put a NUL after it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4133 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4134 tail = src;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4135 var = dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4136 c = dstlen - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4137 while ( c-- > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4138 && *tail
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4139 && vim_isfilec(*tail)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4140 && !vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4141 *var++ = *tail++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4142 *var = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4143 # ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4144 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4145 * If the system supports getpwnam(), use it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4146 * Otherwise, or if getpwnam() fails, the shell is used to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4147 * expand ~user. This is slower and may fail if the shell
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4148 * does not support ~user (old versions of /bin/sh).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4150 # if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4151 {
626
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4152 /* Note: memory allocated by getpwnam() is never freed.
732c7ae5743e updated for version 7.0180
vimboss
parents: 625
diff changeset
4153 * Calling endpwent() apparently doesn't help. */
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
4154 struct passwd *pw = (*dst == NUL)
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
4155 ? NULL : getpwnam((char *)dst + 1);
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
4156
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
4157 var = (pw == NULL) ? NULL : (char_u *)pw->pw_dir;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4158 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4159 if (var == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4160 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4161 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4162 expand_T xpc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4163
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4164 ExpandInit(&xpc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4165 xpc.xp_context = EXPAND_FILES;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4166 var = ExpandOne(&xpc, dst, NULL,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4167 WILD_ADD_SLASH|WILD_SILENT, WILD_EXPAND_FREE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4168 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4169 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4170
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4171 # else /* !UNIX, thus VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4172 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4173 * USER_HOME is a comma-separated list of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4174 * directories to search for the user account in.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4175 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4177 char_u test[MAXPATHL], paths[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4178 char_u *path, *next_path, *ptr;
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
4179 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4180
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4181 STRCPY(paths, USER_HOME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4182 next_path = paths;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4183 while (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4184 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4185 for (path = next_path; *next_path && *next_path != ',';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4186 next_path++);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4187 if (*next_path)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4188 *next_path++ = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4189 STRCPY(test, path);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4190 STRCAT(test, "/");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4191 STRCAT(test, dst + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4192 if (mch_stat(test, &st) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4194 var = alloc(STRLEN(test) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4195 STRCPY(var, test);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4196 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4197 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4198 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4199 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4200 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4201 # endif /* UNIX */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4202 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4203 /* cannot expand user's home directory, so don't try */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4204 var = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4205 tail = (char_u *)""; /* for gcc */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4206 #endif /* UNIX || VMS */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4209 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4210 /* If 'shellslash' is set change backslashes to forward slashes.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4211 * Can't use slash_adjust(), p_ssl may be set temporarily. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4212 if (p_ssl && var != NULL && vim_strchr(var, '\\') != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4213 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4214 char_u *p = vim_strsave(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4216 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4218 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4219 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4220 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4221 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4222 forward_slash(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4225 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4227 /* If "var" contains white space, escape it with a backslash.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4228 * Required for ":e ~/tt" when $HOME includes a space. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4229 if (esc && var != NULL && vim_strpbrk(var, (char_u *)" \t") != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4231 char_u *p = vim_strsave_escaped(var, (char_u *)" \t");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4233 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4234 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4235 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4236 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4237 var = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4238 mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4241
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4242 if (var != NULL && *var != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4243 && (STRLEN(var) + STRLEN(tail) + 1 < (unsigned)dstlen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4245 STRCPY(dst, var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4246 dstlen -= (int)STRLEN(var);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
4247 c = (int)STRLEN(var);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4248 /* if var[] ends in a path separator and tail[] starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4249 * with it, skip a character */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4250 if (*var != NUL && after_pathsep(dst, dst + c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4251 #if defined(BACKSLASH_IN_FILENAME) || defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4252 && dst[-1] != ':'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4253 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4254 && vim_ispathsep(*tail))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4255 ++tail;
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4256 dst += c;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4257 src = tail;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4258 copy_char = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4259 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4260 if (mustfree)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4261 vim_free(var);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4262 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4264 if (copy_char) /* copy at least one char */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4265 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4266 /*
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
4267 * Recognize the start of a new name, for '~'.
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
4268 * Don't do this when "one" is TRUE, to avoid expanding "~" in
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
4269 * ":edit foo ~ foo".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4270 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4271 at_start = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4272 if (src[0] == '\\' && src[1] != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4273 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4274 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4275 --dstlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4276 }
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
4277 else if ((src[0] == ' ' || src[0] == ',') && !one)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4278 at_start = TRUE;
12005
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4279 if (dstlen > 0)
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4280 {
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4281 *dst++ = *src++;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4282 --dstlen;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4283
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4284 if (startstr != NULL && src - startstr_len >= srcp
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4285 && STRNCMP(src - startstr_len, startstr,
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4286 startstr_len) == 0)
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4287 at_start = TRUE;
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4288 }
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4289 }
0496ea4c5c2e patch 8.0.0883: invalid memory access with nonsensical script
Christian Brabandt <cb@256bit.org>
parents: 11989
diff changeset
4290
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4291 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4292 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4296 * Vim's version of getenv().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4297 * Special handling of $HOME, $VIM and $VIMRUNTIME.
196
991a7623a1fe updated for version 7.0058
vimboss
parents: 191
diff changeset
4298 * Also does ACP to 'enc' conversion for Win32.
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
4299 * "mustfree" is set to TRUE when returned is allocated, it must be
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
4300 * initialized to FALSE by the caller.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4301 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4302 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4303 vim_getenv(char_u *name, int *mustfree)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4305 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4306 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4307 int vimruntime;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4308
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
4309 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4310 /* use "C:/" when $HOME is not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4311 if (STRCMP(name, "HOME") == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4312 return homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4313 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4315 p = mch_getenv(name);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4316 if (p != NULL && *p == NUL) /* empty is the same as not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4317 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4319 if (p != NULL)
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4320 {
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
4321 #if defined(WIN3264)
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4322 if (enc_utf8)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4323 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4324 int len;
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
4325 char_u *pp = NULL;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4326
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4327 /* Convert from active codepage to UTF-8. Other conversions are
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4328 * not done, because they would fail for non-ASCII characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
4329 acp_to_enc(p, (int)STRLEN(p), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4330 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4331 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4332 p = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4333 *mustfree = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4334 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4335 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4336 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4337 return p;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4338 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4340 vimruntime = (STRCMP(name, "VIMRUNTIME") == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4341 if (!vimruntime && STRCMP(name, "VIM") != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4342 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4344 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4345 * When expanding $VIMRUNTIME fails, try using $VIM/vim<version> or $VIM.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4346 * Don't do this when default_vimruntime_dir is non-empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4347 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4348 if (vimruntime
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4349 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4350 && *default_vimruntime_dir == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4351 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4352 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4353 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4354 p = mch_getenv((char_u *)"VIM");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4355 if (p != NULL && *p == NUL) /* empty is the same as not set */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4356 p = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4357 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4358 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4359 p = vim_version_dir(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4360 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4361 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4362 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4363 p = mch_getenv((char_u *)"VIM");
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4364
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
4365 #if defined(WIN3264)
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4366 if (enc_utf8)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4367 {
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4368 int len;
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
4369 char_u *pp = NULL;
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4370
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4371 /* Convert from active codepage to UTF-8. Other conversions
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4372 * are not done, because they would fail for non-ASCII
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4373 * characters. */
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 834
diff changeset
4374 acp_to_enc(p, (int)STRLEN(p), &pp, &len);
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4375 if (pp != NULL)
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4376 {
2786
5f45bacf31ef updated for version 7.3.169
Bram Moolenaar <bram@vim.org>
parents: 2776
diff changeset
4377 if (*mustfree)
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4378 vim_free(p);
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4379 p = pp;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4380 *mustfree = TRUE;
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4381 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4382 }
8c60f65311fa updated for version 7.0052
vimboss
parents: 169
diff changeset
4383 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4384 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4385 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4387 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4388 * When expanding $VIM or $VIMRUNTIME fails, try using:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4389 * - the directory name from 'helpfile' (unless it contains '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4390 * - the executable name from argv[0]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4391 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4392 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4393 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4394 if (p_hf != NULL && vim_strchr(p_hf, '$') == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4395 p = p_hf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4396 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4397 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4398 * Use the name of the executable, obtained from argv[0].
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4399 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4400 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4401 p = exe_name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4402 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4403 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4404 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4405 /* remove the file name */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4406 pend = gettail(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4407
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4408 /* remove "doc/" from 'helpfile', if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4409 if (p == p_hf)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4410 pend = remove_tail(p, pend, (char_u *)"doc");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4412 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4413 # ifdef MACOS_X
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4414 /* remove "MacOS" from exe_name and add "Resources/vim" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4415 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4416 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4417 char_u *pend1;
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4418 char_u *pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4419
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4420 pend1 = remove_tail(p, pend, (char_u *)"MacOS");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4421 if (pend1 != pend)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4422 {
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4423 pnew = alloc((unsigned)(pend1 - p) + 15);
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4424 if (pnew != NULL)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4425 {
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4426 STRNCPY(pnew, p, (pend1 - p));
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4427 STRCPY(pnew + (pend1 - p), "Resources/vim");
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4428 p = pnew;
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4429 pend = p + STRLEN(p);
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4430 }
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4431 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4432 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4433 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4434 /* remove "src/" from exe_name, if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4435 if (p == exe_name)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4436 pend = remove_tail(p, pend, (char_u *)"src");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4437 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4439 /* for $VIM, remove "runtime/" or "vim54/", if present */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4440 if (!vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4442 pend = remove_tail(p, pend, (char_u *)RUNTIME_DIRNAME);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4443 pend = remove_tail(p, pend, (char_u *)VIM_VERSION_NODOT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4444 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4446 /* remove trailing path separator */
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4447 if (pend > p && after_pathsep(p, pend))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4448 --pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4449
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4450 #ifdef MACOS_X
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4451 if (p == exe_name || p == p_hf)
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4452 #endif
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4453 /* check that the result is a directory name */
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
4454 p = vim_strnsave(p, (int)(pend - p));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4456 if (p != NULL && !mch_isdir(p))
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
4457 VIM_CLEAR(p);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4458 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4459 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4460 #ifdef USE_EXE_NAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4461 /* may add "/vim54" or "/runtime" if it exists */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4462 if (vimruntime && (pend = vim_version_dir(p)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4463 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4464 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4465 p = pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4466 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4467 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4468 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4470 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4471 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4472
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4473 #ifdef HAVE_PATHDEF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4474 /* When there is a pathdef.c file we can use default_vim_dir and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4475 * default_vimruntime_dir */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4476 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4477 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4478 /* Only use default_vimruntime_dir when it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4479 if (vimruntime && *default_vimruntime_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4480 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4481 p = default_vimruntime_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4482 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4483 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4484 else if (*default_vim_dir != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4485 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4486 if (vimruntime && (p = vim_version_dir(default_vim_dir)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4487 *mustfree = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4488 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4489 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4490 p = default_vim_dir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4491 *mustfree = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4492 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4493 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4494 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4495 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4496
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4497 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4498 * Set the environment variable, so that the new value can be found fast
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4499 * next time, and others can also use it (e.g. Perl).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4500 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4501 if (p != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4502 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4503 if (vimruntime)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4505 vim_setenv((char_u *)"VIMRUNTIME", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4506 didset_vimruntime = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4507 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4508 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4509 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4510 vim_setenv((char_u *)"VIM", p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4511 didset_vim = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4513 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4514 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4515 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4516
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4517 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4518 * Check if the directory "vimdir/<version>" or "vimdir/runtime" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4519 * Return NULL if not, return its name in allocated memory otherwise.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4520 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4521 static char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4522 vim_version_dir(char_u *vimdir)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4523 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4524 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4525
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4526 if (vimdir == NULL || *vimdir == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4527 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4528 p = concat_fnames(vimdir, (char_u *)VIM_VERSION_NODOT, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4529 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4530 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4531 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4532 p = concat_fnames(vimdir, (char_u *)RUNTIME_DIRNAME, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4533 if (p != NULL && mch_isdir(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4534 return p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4535 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4536 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4537 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4538
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4539 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4540 * If the string between "p" and "pend" ends in "name/", return "pend" minus
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4541 * the length of "name/". Otherwise return "pend".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4542 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4543 static char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4544 remove_tail(char_u *p, char_u *pend, char_u *name)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4545 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4546 int len = (int)STRLEN(name) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4547 char_u *newend = pend - len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4548
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4549 if (newend >= p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4550 && fnamencmp(newend, name, len - 1) == 0
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
4551 && (newend == p || after_pathsep(p, newend)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4552 return newend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4553 return pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4554 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4555
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
4556 #if defined(FEAT_EVAL) || defined(PROTO)
13923
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4557 void
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4558 vim_unsetenv(char_u *var)
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4559 {
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4560 #ifdef HAVE_UNSETENV
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4561 unsetenv((char *)var);
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4562 #else
13942
a039c93f5ff7 patch 8.0.1841: HP-UX does not have setenv()
Christian Brabandt <cb@256bit.org>
parents: 13923
diff changeset
4563 vim_setenv(var, (char_u *)"");
13923
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4564 #endif
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4565 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
4566 #endif
13923
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4567
e4d5726e1678 patch 8.0.1832: cannot use :unlet for an environment variable
Christian Brabandt <cb@256bit.org>
parents: 13823
diff changeset
4568
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4569 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4570 * Our portable version of setenv.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4571 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4572 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4573 vim_setenv(char_u *name, char_u *val)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4574 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4575 #ifdef HAVE_SETENV
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4576 mch_setenv((char *)name, (char *)val, 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4577 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4578 char_u *envbuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4579
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4580 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4581 * Putenv does not copy the string, it has to remain
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4582 * valid. The allocated memory will never be freed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4583 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4584 envbuf = alloc((unsigned)(STRLEN(name) + STRLEN(val) + 2));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4585 if (envbuf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4586 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4587 sprintf((char *)envbuf, "%s=%s", name, val);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4588 putenv((char *)envbuf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4589 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4590 #endif
3382
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4591 #ifdef FEAT_GETTEXT
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4592 /*
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4593 * When setting $VIMRUNTIME adjust the directory to find message
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4594 * translations to $VIMRUNTIME/lang.
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4595 */
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4596 if (*val != NUL && STRICMP(name, "VIMRUNTIME") == 0)
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4597 {
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4598 char_u *buf = concat_str(val, (char_u *)"/lang");
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4599
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4600 if (buf != NULL)
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4601 {
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4602 bindtextdomain(VIMPACKAGE, (char *)buf);
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4603 vim_free(buf);
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4604 }
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4605 }
4a2744311b3f updated for version 7.3.457
Bram Moolenaar <bram@vim.org>
parents: 3328
diff changeset
4606 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4607 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4608
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4609 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4610 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4611 * Function given to ExpandGeneric() to obtain an environment variable name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4612 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4613 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4614 get_env_name(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4615 expand_T *xp UNUSED,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4616 int idx)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4617 {
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
4618 # if defined(AMIGA)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4619 /*
12716
351cf7c67bbe patch 8.0.1236: Mac features are confusing
Christian Brabandt <cb@256bit.org>
parents: 12690
diff changeset
4620 * No environ[] on the Amiga.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4621 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4622 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4623 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4624 # ifndef __WIN32__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4625 /* Borland C++ 5.2 has this in a header file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4626 extern char **environ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4627 # endif
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4628 # define ENVNAMELEN 100
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4629 static char_u name[ENVNAMELEN];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4630 char_u *str;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4631 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4632
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4633 str = (char_u *)environ[idx];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4634 if (str == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4635 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4636
17
9be87deaeb52 updated for version 7.0009
vimboss
parents: 16
diff changeset
4637 for (n = 0; n < ENVNAMELEN - 1; ++n)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4639 if (str[n] == '=' || str[n] == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4640 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4641 name[n] = str[n];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4643 name[n] = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4644 return name;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4645 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4646 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4647
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4648 /*
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4649 * Add a user name to the list of users in ga_users.
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4650 * Do nothing if user name is NULL or empty.
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4651 */
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4652 static void
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4653 add_user(char_u *user, int need_copy)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4654 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4655 char_u *user_copy = (user != NULL && need_copy)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4656 ? vim_strsave(user) : user;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4657
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4658 if (user_copy == NULL || *user_copy == NUL || ga_grow(&ga_users, 1) == FAIL)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4659 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4660 if (need_copy)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4661 vim_free(user);
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4662 return;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4663 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4664 ((char_u **)(ga_users.ga_data))[ga_users.ga_len++] = user_copy;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4665 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4666
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4667 /*
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4668 * Find all user names for user completion.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4669 * Done only once and then cached.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4670 */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4671 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4672 init_users(void)
4938
bcb84438bb5b updated for version 7.3.1214
Bram Moolenaar <bram@vim.org>
parents: 4805
diff changeset
4673 {
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4674 static int lazy_init_done = FALSE;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4675
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4676 if (lazy_init_done)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4677 return;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4678
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4679 lazy_init_done = TRUE;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4680 ga_init2(&ga_users, sizeof(char_u *), 20);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4681
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4682 # if defined(HAVE_GETPWENT) && defined(HAVE_PWD_H)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4683 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4684 struct passwd* pw;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4685
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4686 setpwent();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4687 while ((pw = getpwent()) != NULL)
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4688 add_user((char_u *)pw->pw_name, TRUE);
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4689 endpwent();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4690 }
14133
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4691 # elif defined(WIN3264)
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4692 {
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4693 DWORD nusers = 0, ntotal = 0, i;
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4694 PUSER_INFO_0 uinfo;
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4695
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4696 if (NetUserEnum(NULL, 0, 0, (LPBYTE *) &uinfo, MAX_PREFERRED_LENGTH,
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4697 &nusers, &ntotal, NULL) == NERR_Success)
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4698 {
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4699 for (i = 0; i < nusers; i++)
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4700 add_user(utf16_to_enc(uinfo[i].usri0_name, NULL), FALSE);
14133
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4701
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4702 NetApiBufferFree(uinfo);
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4703 }
352c2832d17f patch 8.1.0084: user name completion does not work on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13942
diff changeset
4704 }
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4705 # endif
14698
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4706 # if defined(HAVE_GETPWNAM)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4707 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4708 char_u *user_env = mch_getenv((char_u *)"USER");
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4709
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4710 // The $USER environment variable may be a valid remote user name (NIS,
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4711 // LDAP) not already listed by getpwent(), as getpwent() only lists
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4712 // local user names. If $USER is not already listed, check whether it
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4713 // is a valid remote user name using getpwnam() and if it is, add it to
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4714 // the list of user names.
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4715
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4716 if (user_env != NULL && *user_env != NUL)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4717 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4718 int i;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4719
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4720 for (i = 0; i < ga_users.ga_len; i++)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4721 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4722 char_u *local_user = ((char_u **)ga_users.ga_data)[i];
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4723
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4724 if (STRCMP(local_user, user_env) == 0)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4725 break;
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4726 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4727
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4728 if (i == ga_users.ga_len)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4729 {
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4730 struct passwd *pw = getpwnam((char *)user_env);
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4731
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4732 if (pw != NULL)
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4733 add_user((char_u *)pw->pw_name, TRUE);
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4734 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4735 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4736 }
d2cfca5b178e patch 8.1.0361: remote user not used for completion
Christian Brabandt <cb@256bit.org>
parents: 14629
diff changeset
4737 # endif
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4738 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4739
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4740 /*
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4741 * Function given to ExpandGeneric() to obtain an user names.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4742 */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4743 char_u*
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4744 get_users(expand_T *xp UNUSED, int idx)
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4745 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4746 init_users();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4747 if (idx < ga_users.ga_len)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4748 return ((char_u **)ga_users.ga_data)[idx];
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4749 return NULL;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4750 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4751
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4752 /*
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4753 * Check whether name matches a user name. Return:
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4754 * 0 if name does not match any user name.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4755 * 1 if name partially matches the beginning of a user name.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4756 * 2 is name fully matches a user name.
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4757 */
14286
95030c543411 patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents: 14175
diff changeset
4758 int
95030c543411 patch 8.1.0159: completion for user names does not work for a prefix.
Christian Brabandt <cb@256bit.org>
parents: 14175
diff changeset
4759 match_user(char_u *name)
3744
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4760 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4761 int i;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4762 int n = (int)STRLEN(name);
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4763 int result = 0;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4764
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4765 init_users();
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4766 for (i = 0; i < ga_users.ga_len; i++)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4767 {
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4768 if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4769 return 2; /* full match */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4770 if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0)
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4771 result = 1; /* partial match */
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4772 }
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4773 return result;
99f076ca8d84 updated for version 7.3.631
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
4774 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4775 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4776
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4777 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4778 * Replace home directory by "~" in each space or comma separated file name in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4779 * 'src'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4780 * If anything fails (except when out of space) dst equals src.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4781 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4782 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4783 home_replace(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4784 buf_T *buf, /* when not NULL, check for help files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4785 char_u *src, /* input file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4786 char_u *dst, /* where to put the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4787 int dstlen, /* maximum length of the result */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4788 int one) /* if TRUE, only replace one file name, include
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4789 spaces and commas in the file name. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4791 size_t dirlen = 0, envlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4792 size_t len;
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4793 char_u *homedir_env, *homedir_env_orig;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4794 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4795
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4796 if (src == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4798 *dst = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4799 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4800 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4801
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4802 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4803 * If the file is a help file, remove the path completely.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4804 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4805 if (buf != NULL && buf->b_help)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4806 {
11989
0aae4df3ed8e patch 8.0.0875: crash with weird command sequence
Christian Brabandt <cb@256bit.org>
parents: 11943
diff changeset
4807 vim_snprintf((char *)dst, dstlen, "%s", gettail(src));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4808 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4809 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4811 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4812 * We check both the value of the $HOME environment variable and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4813 * "real" home directory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4814 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4815 if (homedir != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4816 dirlen = STRLEN(homedir);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4817
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4818 #ifdef VMS
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4819 homedir_env_orig = homedir_env = mch_getenv((char_u *)"SYS$LOGIN");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4820 #else
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4821 homedir_env_orig = homedir_env = mch_getenv((char_u *)"HOME");
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4822 #endif
12265
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
4823 #ifdef WIN3264
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
4824 if (homedir_env == NULL)
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
4825 homedir_env_orig = homedir_env = mch_getenv((char_u *)"USERPROFILE");
03e4be2e3d53 patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Christian Brabandt <cb@256bit.org>
parents: 12238
diff changeset
4826 #endif
3658
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
4827 /* Empty is the same as not set. */
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
4828 if (homedir_env != NULL && *homedir_env == NUL)
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
4829 homedir_env = NULL;
e82937b753a8 updated for version 7.3.589
Bram Moolenaar <bram@vim.org>
parents: 3632
diff changeset
4830
4752
77ecab3bb207 updated for version 7.3.1123
Bram Moolenaar <bram@vim.org>
parents: 4352
diff changeset
4831 #if defined(FEAT_MODIFY_FNAME) || defined(FEAT_EVAL)
15308
d7a8f390f6d2 patch 8.1.0662: needlessly searching for tilde in string
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
4832 if (homedir_env != NULL && *homedir_env == '~')
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4833 {
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4834 int usedlen = 0;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4835 int flen;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4836 char_u *fbuf = NULL;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4837
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4838 flen = (int)STRLEN(homedir_env);
14393
c62601adad69 patch 8.1.0211: expanding a file name "~" results in $HOME
Christian Brabandt <cb@256bit.org>
parents: 14286
diff changeset
4839 (void)modify_fname((char_u *)":p", FALSE, &usedlen,
3608
683de9306096 updated for version 7.3.564
Bram Moolenaar <bram@vim.org>
parents: 3598
diff changeset
4840 &homedir_env, &fbuf, &flen);
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4841 flen = (int)STRLEN(homedir_env);
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4842 if (flen > 0 && vim_ispathsep(homedir_env[flen - 1]))
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4843 /* Remove the trailing / that is added to a directory. */
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4844 homedir_env[flen - 1] = NUL;
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4845 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4846 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4847
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4848 if (homedir_env != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4849 envlen = STRLEN(homedir_env);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4850
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4851 if (!one)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4852 src = skipwhite(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4853 while (*src && dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4854 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4855 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4856 * Here we are at the beginning of a file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4857 * First, check to see if the beginning of the file name matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4858 * $HOME or the "real" home directory. Check that there is a '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4859 * after the match (so that if e.g. the file is "/home/pieter/bla",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4860 * and the home directory is "/home/piet", the file does not end up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4861 * as "~er/bla" (which would seem to indicate the file "bla" in user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4862 * er's home directory)).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4863 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4864 p = homedir;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4865 len = dirlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4866 for (;;)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4868 if ( len
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4869 && fnamencmp(src, p, len) == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4870 && (vim_ispathsep(src[len])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4871 || (!one && (src[len] == ',' || src[len] == ' '))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4872 || src[len] == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4874 src += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4875 if (--dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4876 *dst++ = '~';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4877
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4878 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4879 * If it's just the home directory, add "/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4880 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4881 if (!vim_ispathsep(src[0]) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4882 *dst++ = '/';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4883 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4884 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4885 if (p == homedir_env)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4886 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4887 p = homedir_env;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4888 len = envlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4889 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4890
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4891 /* if (!one) skip to separator: space or comma */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4892 while (*src && (one || (*src != ',' && *src != ' ')) && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4893 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4894 /* skip separator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4895 while ((*src == ' ' || *src == ',') && --dstlen > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4896 *dst++ = *src++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4897 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4898 /* if (dstlen == 0) out of space, what to do??? */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4899
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4900 *dst = NUL;
3598
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4901
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4902 if (homedir_env != homedir_env_orig)
74adc9f7e15b updated for version 7.3.559
Bram Moolenaar <bram@vim.org>
parents: 3596
diff changeset
4903 vim_free(homedir_env);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4904 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4905
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4906 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4907 * Like home_replace, store the replaced string in allocated memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4908 * When something fails, NULL is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4909 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4910 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4911 home_replace_save(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4912 buf_T *buf, /* when not NULL, check for help files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4913 char_u *src) /* input file name */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4914 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4915 char_u *dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4916 unsigned len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4917
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4918 len = 3; /* space for "~/" and trailing NUL */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4919 if (src != NULL) /* just in case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4920 len += (unsigned)STRLEN(src);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4921 dst = alloc(len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4922 if (dst != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4923 home_replace(buf, src, dst, len, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4924 return dst;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4927 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4928 * Compare two file names and return:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4929 * FPC_SAME if they both exist and are the same file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4930 * FPC_SAMEX if they both don't exist and have the same file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4931 * FPC_DIFF if they both exist and are different files.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4932 * FPC_NOTX if they both don't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4933 * FPC_DIFFX if one of them doesn't exist.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4934 * For the first name environment variables are expanded
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4935 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4936 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4937 fullpathcmp(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4938 char_u *s1,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4939 char_u *s2,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
4940 int checkname) /* when both don't exist, check file names */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4941 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4942 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4943 char_u exp1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4944 char_u full1[MAXPATHL];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4945 char_u full2[MAXPATHL];
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
4946 stat_T st1, st2;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4947 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4948
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4949 expand_env(s1, exp1, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4950 r1 = mch_stat((char *)exp1, &st1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4951 r2 = mch_stat((char *)s2, &st2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4952 if (r1 != 0 && r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4953 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4954 /* if mch_stat() doesn't work, may compare the names */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4955 if (checkname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4956 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4957 if (fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4958 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4959 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4960 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4961 if (r1 == OK && r2 == OK && fnamecmp(full1, full2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4962 return FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4964 return FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4966 if (r1 != 0 || r2 != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4967 return FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4968 if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4969 return FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4970 return FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4971 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4972 char_u *exp1; /* expanded s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4973 char_u *full1; /* full path of s1 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4974 char_u *full2; /* full path of s2 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4975 int retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4976 int r1, r2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4977
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4978 /* allocate one buffer to store three paths (alloc()/free() is slow!) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4979 if ((exp1 = alloc(MAXPATHL * 3)) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4981 full1 = exp1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4982 full2 = full1 + MAXPATHL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4984 expand_env(s1, exp1, MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4985 r1 = vim_FullName(exp1, full1, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4986 r2 = vim_FullName(s2, full2, MAXPATHL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4987
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4988 /* If vim_FullName() fails, the file probably doesn't exist. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4989 if (r1 != OK && r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4990 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4991 if (checkname && fnamecmp(exp1, s2) == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4992 retval = FPC_SAMEX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4993 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4994 retval = FPC_NOTX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4996 else if (r1 != OK || r2 != OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4997 retval = FPC_DIFFX;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4998 else if (fnamecmp(full1, full2))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4999 retval = FPC_DIFF;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5000 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5001 retval = FPC_SAME;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5002 vim_free(exp1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5003 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5004 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5005 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5006 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5007
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5008 /*
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5009 * Get the tail of a path: the file name.
2549
c210e31a2ec5 More fixes for :find completion. (mostly by Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2542
diff changeset
5010 * When the path ends in a path separator the tail is the NUL after it.
10
4e2284e71352 updated for version 7.0002
vimboss
parents: 7
diff changeset
5011 * Fail safe: never returns NULL.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5012 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5013 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5014 gettail(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5015 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5016 char_u *p1, *p2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5017
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5018 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5019 return (char_u *)"";
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5020 for (p1 = p2 = get_past_head(fname); *p2; ) /* find last part of path */
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5021 {
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5022 if (vim_ispathsep_nocolon(*p2))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5023 p1 = p2 + 1;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
5024 MB_PTR_ADV(p2);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5025 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5026 return p1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5027 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5029 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5030 * Get pointer to tail of "fname", including path separators. Putting a NUL
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5031 * here leaves the directory name. Takes care of "c:/" and "//".
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5032 * Always returns a valid pointer.
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5033 */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5034 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5035 gettail_sep(char_u *fname)
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5036 {
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5037 char_u *p;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5038 char_u *t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5039
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5040 p = get_past_head(fname); /* don't remove the '/' from "c:/file" */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5041 t = gettail(fname);
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5042 while (t > p && after_pathsep(fname, t))
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5043 --t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5044 #ifdef VMS
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5045 /* path separator is part of the path */
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5046 ++t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5047 #endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5048 return t;
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5049 }
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5050
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5051 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5052 * get the next path component (just after the next path separator).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5053 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5054 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5055 getnextcomp(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5057 while (*fname && !vim_ispathsep(*fname))
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
5058 MB_PTR_ADV(fname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5059 if (*fname)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5060 ++fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5061 return fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5062 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5063
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5064 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5065 * Get a pointer to one character past the head of a path name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5066 * Unix: after "/"; DOS: after "c:\"; Amiga: after "disk:/"; Mac: no head.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5067 * If there is no head, path is returned.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5068 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5069 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5070 get_past_head(char_u *path)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5072 char_u *retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5073
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
5074 #if defined(MSWIN)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5075 /* may skip "c:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5076 if (isalpha(path[0]) && path[1] == ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5077 retval = path + 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5078 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5079 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5080 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5081 # if defined(AMIGA)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5082 /* may skip "label:" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5083 retval = vim_strchr(path, ':');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5084 if (retval == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5085 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5086 # else /* Unix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5087 retval = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5088 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5089 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5090
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5091 while (vim_ispathsep(*retval))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5092 ++retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5093
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5094 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5095 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5096
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5097 /*
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5098 * Return TRUE if 'c' is a path separator.
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5099 * Note that for MS-Windows this includes the colon.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5100 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5101 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5102 vim_ispathsep(int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5103 {
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5104 #ifdef UNIX
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5105 return (c == '/'); /* UNIX has ':' inside file names */
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5106 #else
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5107 # ifdef BACKSLASH_IN_FILENAME
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5108 return (c == ':' || c == '/' || c == '\\');
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5109 # else
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5110 # ifdef VMS
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5111 /* server"user passwd"::device:[full.path.name]fname.extension;version" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5112 return (c == ':' || c == '[' || c == ']' || c == '/'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5113 || c == '<' || c == '>' || c == '"' );
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5114 # else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5115 return (c == ':' || c == '/');
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5116 # endif /* VMS */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5117 # endif
2823
8bd38abda314 updated for version 7.3.187
Bram Moolenaar <bram@vim.org>
parents: 2813
diff changeset
5118 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5119 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5120
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5121 /*
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5122 * Like vim_ispathsep(c), but exclude the colon for MS-Windows.
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5123 */
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5124 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5125 vim_ispathsep_nocolon(int c)
5432
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5126 {
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5127 return vim_ispathsep(c)
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5128 #ifdef BACKSLASH_IN_FILENAME
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5129 && c != ':'
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5130 #endif
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5131 ;
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5132 }
38b948f534e4 updated for version 7.4.066
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
5133
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5134 /*
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5135 * Shorten the path of a file from "~/foo/../.bar/fname" to "~/f/../.b/fname"
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5136 * It's done in-place.
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5137 */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5138 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5139 shorten_dir(char_u *str)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5140 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5141 char_u *tail, *s, *d;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5142 int skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5143
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5144 tail = gettail(str);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5145 d = str;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5146 for (s = str; ; ++s)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5147 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5148 if (s >= tail) /* copy the whole tail */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5149 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5150 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5151 if (*s == NUL)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5152 break;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5153 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5154 else if (vim_ispathsep(*s)) /* copy '/' and next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5155 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5156 *d++ = *s;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5157 skip = FALSE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5158 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5159 else if (!skip)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5160 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5161 *d++ = *s; /* copy next char */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5162 if (*s != '~' && *s != '.') /* and leading "~" and "." */
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5163 skip = TRUE;
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5164 if (has_mbyte)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5165 {
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5166 int l = mb_ptr2len(s);
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5167
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5168 while (--l > 0)
927
6632670ff6fc updated for version 7.0-053
vimboss
parents: 856
diff changeset
5169 *d++ = *++s;
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5170 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5171 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5172 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5173 }
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 810
diff changeset
5174
594
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5175 /*
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5176 * Return TRUE if the directory of "fname" exists, FALSE otherwise.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5177 * Also returns TRUE if there is no directory name.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5178 * "fname" must be writable!.
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5179 */
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5180 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5181 dir_of_file_exists(char_u *fname)
594
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5182 {
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5183 char_u *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5184 int c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5185 int retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5186
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5187 p = gettail_sep(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5188 if (p == fname)
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5189 return TRUE;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5190 c = *p;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5191 *p = NUL;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5192 retval = mch_isdir(fname);
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5193 *p = c;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5194 return retval;
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5195 }
35cef95a6b76 updated for version 7.0168
vimboss
parents: 587
diff changeset
5196
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5197 /*
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5198 * Versions of fnamecmp() and fnamencmp() that handle '/' and '\' equally
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5199 * and deal with 'fileignorecase'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5200 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5201 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5202 vim_fnamecmp(char_u *x, char_u *y)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5203 {
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5204 #ifdef BACKSLASH_IN_FILENAME
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5205 return vim_fnamencmp(x, y, MAXPATHL);
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5206 #else
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5207 if (p_fic)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5208 return MB_STRICMP(x, y);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5209 return STRCMP(x, y);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5210 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5211 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5212
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5213 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5214 vim_fnamencmp(char_u *x, char_u *y, size_t len)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5215 {
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5216 #ifdef BACKSLASH_IN_FILENAME
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5217 char_u *px = x;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5218 char_u *py = y;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5219 int cx = NUL;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5220 int cy = NUL;
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5221
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5222 while (len > 0)
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5223 {
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5224 cx = PTR2CHAR(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5225 cy = PTR2CHAR(py);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5226 if (cx == NUL || cy == NUL
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5227 || ((p_fic ? MB_TOLOWER(cx) != MB_TOLOWER(cy) : cx != cy)
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5228 && !(cx == '/' && cy == '\\')
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5229 && !(cx == '\\' && cy == '/')))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5230 break;
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5231 len -= MB_PTR2LEN(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5232 px += MB_PTR2LEN(px);
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5233 py += MB_PTR2LEN(py);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5234 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5235 if (len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5236 return 0;
4246
4d0b39bcec20 updated for version 7.3.874
Bram Moolenaar <bram@vim.org>
parents: 4242
diff changeset
5237 return (cx - cy);
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5238 #else
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5239 if (p_fic)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5240 return MB_STRNICMP(x, y, len);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5241 return STRNCMP(x, y, len);
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5242 #endif
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5243 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5244
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5245 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5246 * Concatenate file names fname1 and fname2 into allocated memory.
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
5247 * Only add a '/' or '\\' when 'sep' is TRUE and it is necessary.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5248 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5249 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5250 concat_fnames(char_u *fname1, char_u *fname2, int sep)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5252 char_u *dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5253
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5254 dest = alloc((unsigned)(STRLEN(fname1) + STRLEN(fname2) + 3));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5255 if (dest != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5256 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5257 STRCPY(dest, fname1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5258 if (sep)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5259 add_pathsep(dest);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5260 STRCAT(dest, fname2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5262 return dest;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5264
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5265 /*
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5266 * Concatenate two strings and return the result in allocated memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5267 * Returns NULL when out of memory.
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5268 */
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5269 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5270 concat_str(char_u *str1, char_u *str2)
115
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5271 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5272 char_u *dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5273 size_t l = STRLEN(str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5274
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5275 dest = alloc((unsigned)(l + STRLEN(str2) + 1L));
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5276 if (dest != NULL)
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5277 {
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5278 STRCPY(dest, str1);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5279 STRCPY(dest + l, str2);
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5280 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5281 return dest;
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5282 }
2201ea50555e updated for version 7.0041
vimboss
parents: 41
diff changeset
5283
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5284 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5285 * Add a path separator to a file name, unless it already ends in a path
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5286 * separator.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5287 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5288 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5289 add_pathsep(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5290 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5291 if (*p != NUL && !after_pathsep(p, p + STRLEN(p)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5292 STRCAT(p, PATHSEPSTR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5294
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5296 * FullName_save - Make an allocated copy of a full file name.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5297 * Returns NULL when out of memory.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5298 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5299 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5300 FullName_save(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5301 char_u *fname,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5302 int force) /* force expansion, even when it already looks
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3578
diff changeset
5303 * like a full path name */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5305 char_u *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5306 char_u *new_fname = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5308 if (fname == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5309 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5311 buf = alloc((unsigned)MAXPATHL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5312 if (buf != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5314 if (vim_FullName(fname, buf, MAXPATHL, force) != FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5315 new_fname = vim_strsave(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5316 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5317 new_fname = vim_strsave(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5318 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5319 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5320 return new_fname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5323 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5324 prepare_to_exit(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5325 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5326 #if defined(SIGHUP) && defined(SIG_IGN)
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5327 /* Ignore SIGHUP, because a dropped connection causes a read error, which
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5328 * makes Vim exit and then handling SIGHUP causes various reentrance
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5329 * problems. */
36
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
5330 signal(SIGHUP, SIG_IGN);
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
5331 #endif
125e80798a85 updated for version 7.0021
vimboss
parents: 24
diff changeset
5332
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5333 #ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5334 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5335 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5336 gui.dying = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5337 out_trash(); /* trash any pending output */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5339 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5340 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5341 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5342 windgoto((int)Rows - 1, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5344 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5345 * Switch terminal mode back now, so messages end up on the "normal"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5346 * screen (if there are two screens).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5347 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5348 settmode(TMODE_COOK);
10264
c036c0f636d5 commit https://github.com/vim/vim/commit/cea912af725c54f4727a0565e31661f6b29c6bb1
Christian Brabandt <cb@256bit.org>
parents: 10180
diff changeset
5349 stoptermcap();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5350 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5351 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5352 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5353
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5354 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5355 * Preserve files and exit.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5356 * When called IObuff must contain a message.
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
5357 * NOTE: This may be called from deathtrap() in a signal handler, avoid unsafe
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
5358 * functions, such as allocating memory.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5359 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5360 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5361 preserve_exit(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5362 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5363 buf_T *buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5365 prepare_to_exit();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5366
625
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
5367 /* Setting this will prevent free() calls. That avoids calling free()
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
5368 * recursively when free() was invoked with a bad pointer. */
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
5369 really_exiting = TRUE;
81fe2ccc1207 updated for version 7.0179
vimboss
parents: 613
diff changeset
5370
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5371 out_str(IObuff);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5372 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5373 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5374
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5375 ml_close_notmod(); /* close all not-modified buffers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5376
9649
fd9727ae3c49 commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents: 9536
diff changeset
5377 FOR_ALL_BUFFERS(buf)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5379 if (buf->b_ml.ml_mfp != NULL && buf->b_ml.ml_mfp->mf_fname != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5380 {
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
5381 OUT_STR("Vim: preserving files...\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5382 screen_start(); /* don't know where cursor is now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5383 out_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5384 ml_sync_all(FALSE, FALSE); /* preserve all swap files */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5385 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5386 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5387 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5389 ml_close_all(FALSE); /* close all memfiles, without deleting */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5390
5338
965044860b7f updated for version 7.4.022
Bram Moolenaar <bram@vim.org>
parents: 5275
diff changeset
5391 OUT_STR("Vim: Finished.\n");
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5392
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5393 getout(1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5394 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5395
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5396 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5397 * return TRUE if "fname" exists.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5398 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5399 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5400 vim_fexists(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5401 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
5402 stat_T st;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5404 if (mch_stat((char *)fname, &st))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5405 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5406 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5407 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5409 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5410 * Check for CTRL-C pressed, but only once in a while.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5411 * Should be used instead of ui_breakcheck() for functions that check for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5412 * each line in the file. Calling ui_breakcheck() each time takes too much
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5413 * time, because it can be a system call.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5414 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5416 #ifndef BREAKCHECK_SKIP
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5417 # ifdef FEAT_GUI /* assume the GUI only runs on fast computers */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5418 # define BREAKCHECK_SKIP 200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5419 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5420 # define BREAKCHECK_SKIP 32
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5421 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5422 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5424 static int breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5426 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5427 line_breakcheck(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5428 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5429 if (++breakcheck_count >= BREAKCHECK_SKIP)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5430 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5431 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5432 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5433 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5436 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5437 * Like line_breakcheck() but check 10 times less often.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5438 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5439 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5440 fast_breakcheck(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5441 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5442 if (++breakcheck_count >= BREAKCHECK_SKIP * 10)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5443 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5444 breakcheck_count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5445 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5446 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5449 /*
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5450 * Invoke expand_wildcards() for one pattern.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5451 * Expand items like "%:h" before the expansion.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5452 * Returns OK or FAIL.
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5453 */
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5454 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5455 expand_wildcards_eval(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5456 char_u **pat, /* pointer to input pattern */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5457 int *num_file, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5458 char_u ***file, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5459 int flags) /* EW_DIR, etc. */
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5460 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5461 int ret = FAIL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5462 char_u *eval_pat = NULL;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5463 char_u *exp_pat = *pat;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
5464 char *ignored_msg;
2016
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5465 int usedlen;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5466
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5467 if (*exp_pat == '%' || *exp_pat == '#' || *exp_pat == '<')
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5468 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5469 ++emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5470 eval_pat = eval_vars(exp_pat, exp_pat, &usedlen,
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5471 NULL, &ignored_msg, NULL);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5472 --emsg_off;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5473 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5474 exp_pat = concat_str(eval_pat, exp_pat + usedlen);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5475 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5476
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5477 if (exp_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5478 ret = expand_wildcards(1, &exp_pat, num_file, file, flags);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5479
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5480 if (eval_pat != NULL)
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5481 {
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5482 vim_free(exp_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5483 vim_free(eval_pat);
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5484 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5485
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5486 return ret;
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5487 }
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5488
03c191181749 updated for version 7.2-313
vimboss
parents: 2002
diff changeset
5489 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5490 * Expand wildcards. Calls gen_expand_wildcards() and removes files matching
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5491 * 'wildignore'.
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5492 * Returns OK or FAIL. When FAIL then "num_files" won't be set.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5493 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5494 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5495 expand_wildcards(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5496 int num_pat, /* number of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5497 char_u **pat, /* array of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5498 int *num_files, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5499 char_u ***files, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5500 int flags) /* EW_DIR, etc. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5501 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5502 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5503 int i, j;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5504 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5505 int non_suf_match; /* number without matching suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5506
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5507 retval = gen_expand_wildcards(num_pat, pat, num_files, files, flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5509 /* When keeping all matches, return here */
2354
f4440cdd59ae Fixed: crash with ":find " completion, using uninitialized count.
Bram Moolenaar <bram@vim.org>
parents: 2328
diff changeset
5510 if ((flags & EW_KEEPALL) || retval == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5511 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5513 #ifdef FEAT_WILDIGN
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5514 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5515 * Remove names that match 'wildignore'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5516 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5517 if (*p_wig)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5518 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5519 char_u *ffname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5520
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5521 /* check all files in (*files)[] */
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5522 for (i = 0; i < *num_files; ++i)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5523 {
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5524 ffname = FullName_save((*files)[i], FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5525 if (ffname == NULL) /* out of memory */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5526 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5527 # ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5528 vms_remove_version(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5529 # endif
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5530 if (match_file_list(p_wig, (*files)[i], ffname))
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5531 {
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
5532 /* remove this matching file from the list */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5533 vim_free((*files)[i]);
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5534 for (j = i; j + 1 < *num_files; ++j)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5535 (*files)[j] = (*files)[j + 1];
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5536 --*num_files;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5537 --i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5538 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5539 vim_free(ffname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5540 }
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5541
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5542 /* If the number of matches is now zero, we fail. */
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5543 if (*num_files == 0)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5544 {
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
5545 VIM_CLEAR(*files);
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5546 return FAIL;
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5547 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5548 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5549 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5550
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5551 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5552 * Move the names where 'suffixes' match to the end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5553 */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5554 if (*num_files > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5555 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5556 non_suf_match = 0;
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5557 for (i = 0; i < *num_files; ++i)
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5558 {
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5559 if (!match_suffix((*files)[i]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5560 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5561 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5562 * Move the name without matching suffix to the front
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5563 * of the list.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5564 */
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5565 p = (*files)[i];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5566 for (j = i; j > non_suf_match; --j)
7119
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5567 (*files)[j] = (*files)[j - 1];
6bc1695b7f11 commit https://github.com/vim/vim/commit/7b256fe7445b46929f660ea74e9090418f857696
Christian Brabandt <cb@256bit.org>
parents: 7066
diff changeset
5568 (*files)[non_suf_match++] = p;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5569 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5571 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5572
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5573 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5574 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5576 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5577 * Return TRUE if "fname" matches with an entry in 'suffixes'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5578 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5579 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5580 match_suffix(char_u *fname)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5582 int fnamelen, setsuflen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5583 char_u *setsuf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5584 #define MAXSUFLEN 30 /* maximum length of a file suffix */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5585 char_u suf_buf[MAXSUFLEN];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5586
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5587 fnamelen = (int)STRLEN(fname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5588 setsuflen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5589 for (setsuf = p_su; *setsuf; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5591 setsuflen = copy_option_part(&setsuf, suf_buf, MAXSUFLEN, ".,");
1937
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5592 if (setsuflen == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5593 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5594 char_u *tail = gettail(fname);
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5595
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5596 /* empty entry: match name without a '.' */
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5597 if (vim_strchr(tail, '.') == NULL)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5598 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5599 setsuflen = 1;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5600 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5601 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5602 }
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5603 else
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5604 {
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5605 if (fnamelen >= setsuflen
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5606 && fnamencmp(suf_buf, fname + fnamelen - setsuflen,
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5607 (size_t)setsuflen) == 0)
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5608 break;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5609 setsuflen = 0;
d92bab35a167 updated for version 7.2-234
vimboss
parents: 1929
diff changeset
5610 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5611 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5612 return (setsuflen != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5613 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5614
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5615 #if !defined(NO_EXPANDPATH) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5616
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5617 # ifdef VIM_BACKTICK
7803
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
5618 static int vim_backtick(char_u *p);
37c929c4a073 commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents: 7641
diff changeset
5619 static int expand_backtick(garray_T *gap, char_u *pat, int flags);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5620 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5621
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
5622 # if defined(WIN3264)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5623 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5624 * File name expansion code for MS-DOS, Win16 and Win32. It's here because
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5625 * it's shared between these systems.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5626 */
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
5627 # if defined(PROTO)
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
5628 # define _cdecl
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5629 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5630 # ifdef __BORLANDC__
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5631 # define _cdecl _RTLENTRYF
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5632 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5633 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5635 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5636 * comparison function for qsort in dos_expandpath()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5637 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5638 static int _cdecl
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5639 pstrcmp(const void *a, const void *b)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5640 {
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
5641 return (pathcmp(*(char **)a, *(char **)b, -1));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5643
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5644 /*
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5645 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5646 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5647 * Return the number of matches found.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5648 * "path" has backslashes before chars that are not to be expanded, starting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5649 * at "path[wildoff]".
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5650 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5651 * NOTE: much of this is identical to unix_expandpath(), keep in sync!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5652 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5653 static int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5654 dos_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5655 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5656 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5657 int wildoff,
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5658 int flags, /* EW_* flags */
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
5659 int didstar) /* expanded "**" once already */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5660 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5661 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5662 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5663 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5664 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5665 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5666 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5667 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5668 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5669 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5670 int starstar = FALSE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5671 static int stardepth = 0; /* depth for "**" expansion */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5672 WIN32_FIND_DATA fb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5673 HANDLE hFind = (HANDLE)0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5674 WIN32_FIND_DATAW wfb;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5675 WCHAR *wn = NULL; /* UCS-2 name, NULL when not used. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5676 char_u *matchname;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5677 int ok;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5678
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5679 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5680 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5681 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5682 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5683 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5684 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5685 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5686
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
5687 // Make room for file name. When doing encoding conversion the actual
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
5688 // length may be quite a bit longer, thus use the maximum possible length.
7186
41885de3d577 commit https://github.com/vim/vim/commit/7314efd87d8c4095229bdc2867a553c36c064918
Christian Brabandt <cb@256bit.org>
parents: 7164
diff changeset
5689 buf = alloc((int)MAXPATHL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5690 if (buf == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5691 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5692
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5693 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5694 * Find the first part in the path name that contains a wildcard or a ~1.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5695 * Copy it into buf, including the preceding characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5696 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5697 p = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5698 s = buf;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5699 e = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5700 path_end = path;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5701 while (*path_end != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5703 /* May ignore a wildcard that has a backslash before it; it will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5704 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5705 if (path_end >= path + wildoff && rem_backslash(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5706 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5707 else if (*path_end == '\\' || *path_end == ':' || *path_end == '/')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5708 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5709 if (e != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5710 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5711 s = p + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5712 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5713 else if (path_end >= path + wildoff
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5714 && vim_strchr((char_u *)"*?[~", *path_end) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5715 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5716 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5717 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
5718 len = (*mb_ptr2len)(path_end);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5719 STRNCPY(p, path_end, len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5720 p += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5721 path_end += len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5722 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5723 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5724 *p++ = *path_end++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5725 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5726 e = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5727 *e = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5729 /* now we have one wildcard component between s and e */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5730 /* Remove backslashes between "wildoff" and the start of the wildcard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5731 * component. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5732 for (p = buf + wildoff; p < s; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5733 if (rem_backslash(p))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5734 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
5735 STRMOVE(p, p + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5736 --e;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5737 --s;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5738 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5739
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5740 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5741 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5742 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5743 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5744
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
5745 starts_with_dot = *s == '.';
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5746 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5747 if (pat == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5748 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5749 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5750 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5752
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5753 /* compile the regexp into a program */
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
5754 if (flags & (EW_NOERROR | EW_NOTWILD))
2966
aa998de9f959 updated for version 7.3.255
Bram Moolenaar <bram@vim.org>
parents: 2953
diff changeset
5755 ++emsg_silent;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5756 regmatch.rm_ic = TRUE; /* Always ignore case */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5757 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
5758 if (flags & (EW_NOERROR | EW_NOTWILD))
2966
aa998de9f959 updated for version 7.3.255
Bram Moolenaar <bram@vim.org>
parents: 2953
diff changeset
5759 --emsg_silent;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5760 vim_free(pat);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5761
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
5762 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5763 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5764 vim_free(buf);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5765 return 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5766 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5767
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5768 /* remember the pattern or file name being looked for */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5769 matchname = vim_strsave(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5770
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5771 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5772 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5773 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5774 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5775 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5776 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5777 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5778 (void)dos_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5779 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5780 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5781
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5782 /* Scan all files in the directory with "dir/ *.*" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5783 STRCPY(s, "*.*");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5784 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5786 /* The active codepage differs from 'encoding'. Attempt using the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5787 * wide function. If it fails because it is not implemented fall back
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5788 * to the non-wide version (for Windows 98) */
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
5789 wn = enc_to_utf16(buf, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5790 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5791 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5792 hFind = FindFirstFileW(wn, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5793 if (hFind == INVALID_HANDLE_VALUE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5794 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
5795 VIM_CLEAR(wn);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5796 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5797 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5798
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5799 if (wn == NULL)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
5800 hFind = FindFirstFile((LPCSTR)buf, &fb);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5801 ok = (hFind != INVALID_HANDLE_VALUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5802
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5803 while (ok)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5804 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5805 if (wn != NULL)
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
5806 p = utf16_to_enc(wfb.cFileName, NULL); /* p is allocated here */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5807 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5808 p = (char_u *)fb.cFileName;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5809 /* Ignore entries starting with a dot, unless when asked for. Accept
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5810 * all entries found with "matchname". */
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
5811 if ((p[0] != '.' || starts_with_dot
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
5812 || ((flags & EW_DODOT)
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
5813 && p[1] != NUL && (p[1] != '.' || p[2] != NUL)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5814 && (matchname == NULL
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
5815 || (regmatch.regprog != NULL
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
5816 && vim_regexec(&regmatch, p, (colnr_T)0))
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
5817 || ((flags & EW_NOTWILD)
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
5818 && fnamencmp(path + (s - buf), p, e - s) == 0)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5819 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5820 STRCPY(s, p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5821 len = (int)STRLEN(buf);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5822
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5823 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5824 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5825 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5826 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5827 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5828 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5829 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5830 (void)dos_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5831 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5832 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5833
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5834 STRCPY(buf + len, path_end);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5835 if (mch_has_exp_wildcard(path_end))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5836 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5837 /* need to expand another component of the path */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5838 /* remove backslashes for the remaining components only */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5839 (void)dos_expandpath(gap, buf, len + 1, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5840 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5841 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5842 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5843 /* no more wildcards, check if there is a match */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5844 /* remove backslashes for the remaining components only */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5845 if (*path_end != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5846 backslash_halve(buf + len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5847 if (mch_getperm(buf) >= 0) /* add existing file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5848 addfile(gap, buf, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5849 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5850 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5851
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5852 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5853 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5854 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5855 ok = FindNextFileW(hFind, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5857 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5858 ok = FindNextFile(hFind, &fb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5859
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5860 /* If no more matches and no match was used, try expanding the name
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5861 * itself. Finds the long name of a short filename. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5862 if (!ok && matchname != NULL && gap->ga_len == start_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5863 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5864 STRCPY(s, matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5865 FindClose(hFind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5866 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5867 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5868 vim_free(wn);
1752
a8aae2e1d2ae updated for version 7.2-049
vimboss
parents: 1733
diff changeset
5869 wn = enc_to_utf16(buf, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5870 if (wn != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5871 hFind = FindFirstFileW(wn, &wfb);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5872 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5873 if (wn == NULL)
8080
b6cb94ad97a4 commit https://github.com/vim/vim/commit/6aa2cd4be287f35f95f35c2cec6d5a24f53c4d3c
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
5874 hFind = FindFirstFile((LPCSTR)buf, &fb);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5875 ok = (hFind != INVALID_HANDLE_VALUE);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
5876 VIM_CLEAR(matchname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5879
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5880 FindClose(hFind);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5881 vim_free(wn);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5882 vim_free(buf);
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
5883 vim_regfree(regmatch.regprog);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5884 vim_free(matchname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5885
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5886 matches = gap->ga_len - start_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5887 if (matches > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5888 qsort(((char_u **)gap->ga_data) + start_len, (size_t)matches,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5889 sizeof(char_u *), pstrcmp);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5890 return matches;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5891 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5892
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5893 int
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5894 mch_expandpath(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5895 garray_T *gap,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5896 char_u *path,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5897 int flags) /* EW_* flags */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5898 {
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5899 return dos_expandpath(gap, path, 0, flags, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5900 }
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
5901 # endif /* WIN3264 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5902
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5903 #if (defined(UNIX) && !defined(VMS)) || defined(USE_UNIXFILENAME) \
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5904 || defined(PROTO)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5905 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5906 * Unix style wildcard expansion code.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5907 * It's here because it's used both for Unix and Mac.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5908 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5909 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5910 pstrcmp(const void *a, const void *b)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5911 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5912 return (pathcmp(*(char **)a, *(char **)b, -1));
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5913 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5914
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5915 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5916 * Recursively expand one path component into all matching files and/or
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5917 * directories. Adds matches to "gap". Handles "*", "?", "[a-z]", "**", etc.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5918 * "path" has backslashes before chars that are not to be expanded, starting
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5919 * at "path + wildoff".
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5920 * Return the number of matches found.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5921 * NOTE: much of this is identical to dos_expandpath(), keep in sync!
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5922 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5923 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5924 unix_expandpath(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5925 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5926 char_u *path,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5927 int wildoff,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5928 int flags, /* EW_* flags */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
5929 int didstar) /* expanded "**" once already */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5930 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5931 char_u *buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5932 char_u *path_end;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5933 char_u *p, *s, *e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5934 int start_len = gap->ga_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5935 char_u *pat;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5936 regmatch_T regmatch;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5937 int starts_with_dot;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5938 int matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5939 int len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5940 int starstar = FALSE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5941 static int stardepth = 0; /* depth for "**" expansion */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5942
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5943 DIR *dirp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5944 struct dirent *dp;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5945
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5946 /* Expanding "**" may take a long time, check for CTRL-C. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5947 if (stardepth > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5948 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5949 ui_breakcheck();
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5950 if (got_int)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5951 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5952 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5953
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5954 /* make room for file name */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5955 buf = alloc((int)STRLEN(path) + BASENAMELEN + 5);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5956 if (buf == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5957 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5958
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5959 /*
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5960 * Find the first part in the path name that contains a wildcard.
3505
6c318419e331 updated for version 7.3.515
Bram Moolenaar <bram@vim.org>
parents: 3461
diff changeset
5961 * When EW_ICASE is set every letter is considered to be a wildcard.
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5962 * Copy it into "buf", including the preceding characters.
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5963 */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5964 p = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5965 s = buf;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5966 e = NULL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5967 path_end = path;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5968 while (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5969 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5970 /* May ignore a wildcard that has a backslash before it; it will
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5971 * be removed by rem_backslash() or file_pat_to_reg_pat() below. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5972 if (path_end >= path + wildoff && rem_backslash(path_end))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5973 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5974 else if (*path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5975 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5976 if (e != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5977 break;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5978 s = p + 1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5979 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5980 else if (path_end >= path + wildoff
3505
6c318419e331 updated for version 7.3.515
Bram Moolenaar <bram@vim.org>
parents: 3461
diff changeset
5981 && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5982 || (!p_fic && (flags & EW_ICASE)
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
5983 && isalpha(PTR2CHAR(path_end)))))
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5984 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5985 if (has_mbyte)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5986 {
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 445
diff changeset
5987 len = (*mb_ptr2len)(path_end);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5988 STRNCPY(p, path_end, len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5989 p += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5990 path_end += len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5991 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5992 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5993 *p++ = *path_end++;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5994 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5995 e = p;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5996 *e = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5997
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
5998 /* Now we have one wildcard component between "s" and "e". */
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
5999 /* Remove backslashes between "wildoff" and the start of the wildcard
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6000 * component. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6001 for (p = buf + wildoff; p < s; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6002 if (rem_backslash(p))
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6003 {
1624
18ee39301b82 updated for version 7.2a
vimboss
parents: 1617
diff changeset
6004 STRMOVE(p, p + 1);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6005 --e;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6006 --s;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6007 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6008
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6009 /* Check for "**" between "s" and "e". */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6010 for (p = s; p < e; ++p)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6011 if (p[0] == '*' && p[1] == '*')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6012 starstar = TRUE;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6013
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6014 /* convert the file pattern to a regexp pattern */
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
6015 starts_with_dot = *s == '.';
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6016 pat = file_pat_to_reg_pat(s, e, NULL, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6017 if (pat == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6018 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6019 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6020 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6021 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6022
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6023 /* compile the regexp into a program */
2652
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
6024 if (flags & EW_ICASE)
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
6025 regmatch.rm_ic = TRUE; /* 'wildignorecase' set */
b2a7d143abe2 updated for version 7.3.072
Bram Moolenaar <bram@vim.org>
parents: 2577
diff changeset
6026 else
4242
edd0bc1f26bd updated for version 7.3.872
Bram Moolenaar <bram@vim.org>
parents: 4225
diff changeset
6027 regmatch.rm_ic = p_fic; /* ignore case when 'fileignorecase' is set */
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6028 if (flags & (EW_NOERROR | EW_NOTWILD))
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6029 ++emsg_silent;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6030 regmatch.regprog = vim_regcomp(pat, RE_MAGIC);
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6031 if (flags & (EW_NOERROR | EW_NOTWILD))
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6032 --emsg_silent;
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6033 vim_free(pat);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6034
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6035 if (regmatch.regprog == NULL && (flags & EW_NOTWILD) == 0)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6036 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6037 vim_free(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6038 return 0;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6039 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6040
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6041 /* If "**" is by itself, this is the first time we encounter it and more
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6042 * is following then find matches without any directory. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6043 if (!didstar && stardepth < 100 && starstar && e - s == 2
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6044 && *path_end == '/')
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6045 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6046 STRCPY(s, path_end + 1);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6047 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6048 (void)unix_expandpath(gap, buf, (int)(s - buf), flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6049 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6050 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6051
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6052 /* open the directory for scanning */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6053 *s = NUL;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6054 dirp = opendir(*buf == NUL ? "." : (char *)buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6055
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6056 /* Find all matching entries */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6057 if (dirp != NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6058 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6059 for (;;)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6060 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6061 dp = readdir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6062 if (dp == NULL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6063 break;
7635
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
6064 if ((dp->d_name[0] != '.' || starts_with_dot
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
6065 || ((flags & EW_DODOT)
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
6066 && dp->d_name[1] != NUL
1506f86b120f commit https://github.com/vim/vim/commit/d82103ed8534a1207742e9666ac7ef1e47dda12d
Christian Brabandt <cb@256bit.org>
parents: 7633
diff changeset
6067 && (dp->d_name[1] != '.' || dp->d_name[2] != NUL)))
3261
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6068 && ((regmatch.regprog != NULL && vim_regexec(&regmatch,
ce6afdc00290 updated for version 7.3.399
Bram Moolenaar <bram@vim.org>
parents: 3220
diff changeset
6069 (char_u *)dp->d_name, (colnr_T)0))
2984
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
6070 || ((flags & EW_NOTWILD)
aa40bddeea9a updated for version 7.3.264
Bram Moolenaar <bram@vim.org>
parents: 2966
diff changeset
6071 && fnamencmp(path + (s - buf), dp->d_name, e - s) == 0)))
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6072 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6073 STRCPY(s, dp->d_name);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6074 len = STRLEN(buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6075
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6076 if (starstar && stardepth < 100)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6077 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6078 /* For "**" in the pattern first go deeper in the tree to
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6079 * find matches. */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6080 STRCPY(buf + len, "/**");
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6081 STRCPY(buf + len + 3, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6082 ++stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6083 (void)unix_expandpath(gap, buf, len + 1, flags, TRUE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6084 --stardepth;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6085 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6086
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6087 STRCPY(buf + len, path_end);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6088 if (mch_has_exp_wildcard(path_end)) /* handle more wildcards */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6089 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6090 /* need to expand another component of the path */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6091 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6092 (void)unix_expandpath(gap, buf, len + 1, flags, FALSE);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6093 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6094 else
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6095 {
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
6096 stat_T sb;
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6097
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6098 /* no more wildcards, check if there is a match */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6099 /* remove backslashes for the remaining components only */
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6100 if (*path_end != NUL)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6101 backslash_halve(buf + len + 1);
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6102 /* add existing file or symbolic link */
6665
9fda0c52db0b updated for version 7.4.657
Bram Moolenaar <bram@vim.org>
parents: 6663
diff changeset
6103 if ((flags & EW_ALLLINKS) ? mch_lstat((char *)buf, &sb) >= 0
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6104 : mch_getperm(buf) >= 0)
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6105 {
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
6106 #ifdef MACOS_CONVERT
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6107 size_t precomp_len = STRLEN(buf)+1;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6108 char_u *precomp_buf =
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6109 mac_precompose_path(buf, precomp_len, &precomp_len);
768
8ccb9047b14d updated for version 7.0225
vimboss
parents: 720
diff changeset
6110
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6111 if (precomp_buf)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6112 {
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6113 mch_memmove(buf, precomp_buf, precomp_len);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6114 vim_free(precomp_buf);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6115 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6116 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6117 addfile(gap, buf, flags);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6118 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6119 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6120 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6121 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6122
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6123 closedir(dirp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6124 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6125
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6126 vim_free(buf);
4805
66803af09906 updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents: 4752
diff changeset
6127 vim_regfree(regmatch.regprog);
445
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6128
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6129 matches = gap->ga_len - start_len;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6130 if (matches > 0)
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6131 qsort(((char_u **)gap->ga_data) + start_len, matches,
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6132 sizeof(char_u *), pstrcmp);
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6133 return matches;
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6134 }
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6135 #endif
c773cb978acf updated for version 7.0116
vimboss
parents: 419
diff changeset
6136
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6137 #if defined(FEAT_SEARCHPATH) || defined(FEAT_CMDL_COMPL) || defined(PROTO)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6138 /*
2559
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
6139 * Sort "gap" and remove duplicate entries. "gap" is expected to contain a
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
6140 * list of file names in allocated memory.
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6141 */
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6142 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6143 remove_duplicates(garray_T *gap)
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6144 {
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6145 int i;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6146 int j;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6147 char_u **fnames = (char_u **)gap->ga_data;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6148
2559
7850c8c12347 Cleanup in :find completion code. Make it work for "./subdir" in 'path'.
Bram Moolenaar <bram@vim.org>
parents: 2549
diff changeset
6149 sort_strings(fnames, gap->ga_len);
2433
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6150 for (i = gap->ga_len - 1; i > 0; --i)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6151 if (fnamecmp(fnames[i - 1], fnames[i]) == 0)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6152 {
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6153 vim_free(fnames[i]);
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6154 for (j = i + 1; j < gap->ga_len; ++j)
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6155 fnames[j - 1] = fnames[j];
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6156 --gap->ga_len;
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6157 }
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6158 }
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6159 #endif
98b9a6b9e7d5 Add completion for ":ownsyntax" and improve completion for ":filetype".
Bram Moolenaar <bram@vim.org>
parents: 2429
diff changeset
6160
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6161 /*
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6162 * Return TRUE if "p" contains what looks like an environment variable.
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6163 * Allowing for escaping.
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6164 */
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6165 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6166 has_env_var(char_u *p)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6167 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
6168 for ( ; *p; MB_PTR_ADV(p))
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6169 {
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6170 if (*p == '\\' && p[1] != NUL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6171 ++p;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6172 else if (vim_strchr((char_u *)
8212
05b88224cea1 commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents: 8163
diff changeset
6173 #if defined(MSWIN)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6174 "$%"
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6175 #else
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6176 "$"
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6177 #endif
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6178 , *p) != NULL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6179 return TRUE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6180 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6181 return FALSE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6182 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6183
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6184 #ifdef SPECIAL_WILDCHAR
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6185 /*
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
6186 * Return TRUE if "p" contains a special wildcard character, one that Vim
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
6187 * cannot expand, requires using a shell.
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6188 */
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6189 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6190 has_special_wildchar(char_u *p)
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6191 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
6192 for ( ; *p; MB_PTR_ADV(p))
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6193 {
10932
141fe140976c patch 8.0.0355: using uninitialized memory when 'isfname' is empty
Christian Brabandt <cb@256bit.org>
parents: 10889
diff changeset
6194 /* Allow for escaping. */
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6195 if (*p == '\\' && p[1] != NUL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6196 ++p;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6197 else if (vim_strchr((char_u *)SPECIAL_WILDCHAR, *p) != NULL)
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6198 return TRUE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6199 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6200 return FALSE;
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6201 }
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6202 #endif
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6203
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6204 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6205 * Generic wildcard expansion code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6206 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6207 * Characters in "pat" that should not be expanded must be preceded with a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6208 * backslash. E.g., "/path\ with\ spaces/my\*star*"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6209 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6210 * Return FAIL when no single file was found. In this case "num_file" is not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6211 * set, and "file" may contain an error message.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6212 * Return OK when some files found. "num_file" is set to the number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6213 * matches, "file" to the array of matches. Call FreeWild() later.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6214 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6215 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6216 gen_expand_wildcards(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6217 int num_pat, /* number of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6218 char_u **pat, /* array of input patterns */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6219 int *num_file, /* resulting number of files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6220 char_u ***file, /* array of resulting files */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6221 int flags) /* EW_* flags */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6222 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6223 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6224 garray_T ga;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6225 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6226 static int recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6227 int add_pat;
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6228 int retval = OK;
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6229 #if defined(FEAT_SEARCHPATH)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6230 int did_expand_in_path = FALSE;
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6231 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6233 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6234 * expand_env() is called to expand things like "~user". If this fails,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6235 * it calls ExpandOne(), which brings us back here. In this case, always
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6236 * call the machine specific expansion function, if possible. Otherwise,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6237 * return FAIL.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6238 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6239 if (recursive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6240 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6241 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6242 #else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6243 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6244 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6245
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6246 #ifdef SPECIAL_WILDCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6247 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6248 * If there are any special wildcard characters which we cannot handle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6249 * here, call machine specific function for all the expansion. This
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6250 * avoids starting the shell for each argument separately.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6251 * For `=expr` do use the internal function.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6252 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6253 for (i = 0; i < num_pat; i++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6254 {
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6255 if (has_special_wildchar(pat[i])
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6256 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6257 && !(vim_backtick(pat[i]) && pat[i][1] == '=')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6258 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6259 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6260 return mch_expand_wildcards(num_pat, pat, num_file, file, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6262 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6264 recursive = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6266 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6267 * The matching file names are stored in a growarray. Init it empty.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6268 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6269 ga_init2(&ga, (int)sizeof(char_u *), 30);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6271 for (i = 0; i < num_pat; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6273 add_pat = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6274 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6275
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6276 #ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6277 if (vim_backtick(p))
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6278 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6279 add_pat = expand_backtick(&ga, p, flags);
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6280 if (add_pat == -1)
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6281 retval = FAIL;
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6282 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6283 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6284 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6286 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6287 * First expand environment variables, "~/" and "~user/".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6288 */
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6289 if (has_env_var(p) || *p == '~')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6290 {
1408
db8309865794 updated for version 7.1-123
vimboss
parents: 1359
diff changeset
6291 p = expand_env_save_opt(p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6292 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6293 p = pat[i];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6294 #ifdef UNIX
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6295 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6296 * On Unix, if expand_env() can't expand an environment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6297 * variable, use the shell to do that. Discard previously
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6298 * found file names and start all over again.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6299 */
5104
93cccad6a26b updated for version 7.3.1295
Bram Moolenaar <bram@vim.org>
parents: 4940
diff changeset
6300 else if (has_env_var(p) || *p == '~')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6301 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6302 vim_free(p);
1914
28641f0ed9de updated for version 7.2-211
vimboss
parents: 1883
diff changeset
6303 ga_clear_strings(&ga);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6304 i = mch_expand_wildcards(num_pat, pat, num_file, file,
6174
96a4fa8e530c updated for version 7.4.423
Bram Moolenaar <bram@vim.org>
parents: 6114
diff changeset
6305 flags|EW_KEEPDOLLAR);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6306 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6307 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6308 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6309 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6310 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6311
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6312 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6313 * If there are wildcards: Expand file names and add each match to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6314 * the list. If there is no match, and EW_NOTFOUND is given, add
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6315 * the pattern.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6316 * If there are no wildcards: Add the file name if it exists or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6317 * when EW_NOTFOUND is given.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6318 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6319 if (mch_has_exp_wildcard(p))
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6320 {
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6321 #if defined(FEAT_SEARCHPATH)
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6322 if ((flags & EW_PATH)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6323 && !mch_isFullName(p)
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6324 && !(p[0] == '.'
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6325 && (vim_ispathsep(p[1])
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6326 || (p[1] == '.' && vim_ispathsep(p[2]))))
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6327 )
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
6328 {
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6329 /* :find completion where 'path' is used.
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6330 * Recursiveness is OK here. */
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
6331 recursive = FALSE;
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6332 add_pat = expand_in_path(&ga, p, flags);
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
6333 recursive = TRUE;
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6334 did_expand_in_path = TRUE;
2487
7ec9ada2cd81 Make :find completion consistent between Unix and MS-Windows. Add a test.
Bram Moolenaar <bram@vim.org>
parents: 2481
diff changeset
6335 }
2311
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6336 else
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6337 #endif
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6338 add_pat = mch_expandpath(&ga, p, flags);
ccda151dde4e Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2302
diff changeset
6339 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6340 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6341
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6342 if (add_pat == -1 || (add_pat == 0 && (flags & EW_NOTFOUND)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6343 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6344 char_u *t = backslash_halve_save(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6345
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6346 /* When EW_NOTFOUND is used, always add files and dirs. Makes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6347 * "vim c:/" work. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6348 if (flags & EW_NOTFOUND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6349 addfile(&ga, t, flags | EW_DIR | EW_FILE);
9420
9f78f3f0c81f commit https://github.com/vim/vim/commit/00efded1064427ab3f84e4d57af62e0aab876fc6
Christian Brabandt <cb@256bit.org>
parents: 9389
diff changeset
6350 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6351 addfile(&ga, t, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6352 vim_free(t);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6353 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6354
2313
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
6355 #if defined(FEAT_SEARCHPATH)
2568
1ead15c2ffd0 Two fixes for :find completion and more testing. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2562
diff changeset
6356 if (did_expand_in_path && ga.ga_len > 0 && (flags & EW_PATH))
2313
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
6357 uniquefy_paths(&ga, p);
e382b66b936d Fix using freed memory in :find completion.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
6358 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6359 if (p != pat[i])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6360 vim_free(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6361 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6362
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6363 *num_file = ga.ga_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6364 *file = (ga.ga_data != NULL) ? (char_u **)ga.ga_data : (char_u **)"";
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6365
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6366 recursive = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6367
7641
b44fc33ef92a commit https://github.com/vim/vim/commit/336bd622c31e1805495c034e1a8cfadcc0bbabc7
Christian Brabandt <cb@256bit.org>
parents: 7635
diff changeset
6368 return ((flags & EW_EMPTYOK) || ga.ga_data != NULL) ? retval : FAIL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6369 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6370
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6371 # ifdef VIM_BACKTICK
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6372
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6373 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6374 * Return TRUE if we can expand this backtick thing here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6375 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6376 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6377 vim_backtick(char_u *p)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6378 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6379 return (*p == '`' && *(p + 1) != NUL && *(p + STRLEN(p) - 1) == '`');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6380 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6381
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6382 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6383 * Expand an item in `backticks` by executing it as a command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6384 * Currently only works when pat[] starts and ends with a `.
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6385 * Returns number of file names found, -1 if an error is encountered.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6386 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6387 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6388 expand_backtick(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6389 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6390 char_u *pat,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6391 int flags) /* EW_* flags */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6392 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6393 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6394 char_u *cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6395 char_u *buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6396 int cnt = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6397 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6399 /* Create the command: lop off the backticks. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6400 cmd = vim_strnsave(pat + 1, (int)STRLEN(pat) - 2);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6401 if (cmd == NULL)
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6402 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6404 #ifdef FEAT_EVAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6405 if (*cmd == '=') /* `={expr}`: Expand expression */
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 694
diff changeset
6406 buffer = eval_to_string(cmd + 1, &p, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6407 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6408 #endif
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
6409 buffer = get_cmd_output(cmd, NULL,
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6410 (flags & EW_SILENT) ? SHELL_SILENT : 0, NULL);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6411 vim_free(cmd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6412 if (buffer == NULL)
7036
5f00b8d7148f commit https://github.com/vim/vim/commit/3f188935ec4db5117c4a64cc3f71219175624745
Christian Brabandt <cb@256bit.org>
parents: 6971
diff changeset
6413 return -1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6415 cmd = buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6416 while (*cmd != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6417 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6418 cmd = skipwhite(cmd); /* skip over white space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6419 p = cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6420 while (*p != NUL && *p != '\r' && *p != '\n') /* skip over entry */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6421 ++p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6422 /* add an entry if it is not empty */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6423 if (p > cmd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6424 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6425 i = *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6426 *p = NUL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6427 addfile(gap, cmd, flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6428 *p = i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6429 ++cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6430 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6431 cmd = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6432 while (*cmd != NUL && (*cmd == '\r' || *cmd == '\n'))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6433 ++cmd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6434 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6435
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6436 vim_free(buffer);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6437 return cnt;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6438 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6439 # endif /* VIM_BACKTICK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6440
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6441 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6442 * Add a file to a file list. Accepted flags:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6443 * EW_DIR add directories
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6444 * EW_FILE add files
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
6445 * EW_EXEC add executable files
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6446 * EW_NOTFOUND add even when it doesn't exist
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6447 * EW_ADDSLASH add slash after directory name
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6448 * EW_ALLLINKS add symlink also when the referred file does not exist
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6449 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6450 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6451 addfile(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6452 garray_T *gap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6453 char_u *f, /* filename */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6454 int flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6455 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6456 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6457 int isdir;
9387
f094d4085014 commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents: 9225
diff changeset
6458 stat_T sb;
6663
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6459
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6460 /* if the file/dir/link doesn't exist, may not add it */
056809de0b29 updated for version 7.4.656
Bram Moolenaar <bram@vim.org>
parents: 6596
diff changeset
6461 if (!(flags & EW_NOTFOUND) && ((flags & EW_ALLLINKS)
6665
9fda0c52db0b updated for version 7.4.657
Bram Moolenaar <bram@vim.org>
parents: 6663
diff changeset
6462 ? mch_lstat((char *)f, &sb) < 0 : mch_getperm(f) < 0))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6463 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6465 #ifdef FNAME_ILLEGAL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6466 /* if the file/dir contains illegal characters, don't add it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6467 if (vim_strpbrk(f, (char_u *)FNAME_ILLEGAL) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6468 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6469 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6471 isdir = mch_isdir(f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6472 if ((isdir && !(flags & EW_DIR)) || (!isdir && !(flags & EW_FILE)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6473 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6474
6695
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
6475 /* If the file isn't executable, may not add it. Do accept directories.
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
6476 * When invoked from expand_shellcmd() do not use $PATH. */
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
6477 if (!isdir && (flags & EW_EXEC)
6529590f6c43 updated for version 7.4.672
Bram Moolenaar <bram@vim.org>
parents: 6691
diff changeset
6478 && !mch_can_exe(f, NULL, !(flags & EW_SHELLCMD)))
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
6479 return;
8ae24f338cab updated for version 7.0217
vimboss
parents: 714
diff changeset
6480
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6481 /* Make room for another item in the file list. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6482 if (ga_grow(gap, 1) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6483 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6484
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6485 p = alloc((unsigned)(STRLEN(f) + 1 + isdir));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6486 if (p == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6487 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6488
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6489 STRCPY(p, f);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6490 #ifdef BACKSLASH_IN_FILENAME
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6491 slash_adjust(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6492 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6493 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6494 * Append a slash or backslash after directory names if none is present.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6495 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6496 #ifndef DONT_ADD_PATHSEP_TO_DIR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6497 if (isdir && (flags & EW_ADDSLASH))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6498 add_pathsep(p);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6499 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6500 ((char_u **)gap->ga_data)[gap->ga_len++] = p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6501 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6502 #endif /* !NO_EXPANDPATH */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6503
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6504 #if defined(VIM_BACKTICK) || defined(FEAT_EVAL) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6506 #ifndef SEEK_SET
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6507 # define SEEK_SET 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6508 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6509 #ifndef SEEK_END
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6510 # define SEEK_END 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6511 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6513 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6514 * Get the stdout of an external command.
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6515 * If "ret_len" is NULL replace NUL characters with NL. When "ret_len" is not
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6516 * NULL store the length there.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6517 * Returns an allocated string, or NULL for error.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6518 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6519 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6520 get_cmd_output(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6521 char_u *cmd,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6522 char_u *infile, /* optional input file name */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6523 int flags, /* can be SHELL_SILENT */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6524 int *ret_len)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6526 char_u *tempname;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6527 char_u *command;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6528 char_u *buffer = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6529 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6530 int i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6531 FILE *fd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6533 if (check_restricted() || check_secure())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6534 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6535
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6536 /* get a name for the temp file */
6721
7347229a646a updated for version 7.4.684
Bram Moolenaar <bram@vim.org>
parents: 6695
diff changeset
6537 if ((tempname = vim_tempname('o', FALSE)) == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6538 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
6539 emsg(_(e_notmp));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6540 return NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6541 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6543 /* Add the redirection stuff */
24
8ff7fd162d3c updated for version 7.0016
vimboss
parents: 22
diff changeset
6544 command = make_filter_cmd(cmd, infile, tempname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6545 if (command == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6546 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6547
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6548 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6549 * Call the shell to execute the command (errors are ignored).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6550 * Don't check timestamps here.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6551 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6552 ++no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6553 call_shell(command, SHELL_DOOUT | SHELL_EXPAND | flags);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6554 --no_check_timestamps;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6556 vim_free(command);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6558 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6559 * read the names from the file into memory
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6560 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6561 # ifdef VMS
1224
edc1c9d6dab9 updated for version 7.1b
vimboss
parents: 1096
diff changeset
6562 /* created temporary file is not always readable as binary */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6563 fd = mch_fopen((char *)tempname, "r");
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6564 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6565 fd = mch_fopen((char *)tempname, READBIN);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6566 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6567
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6568 if (fd == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6569 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
6570 semsg(_(e_notopen), tempname);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6571 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6574 fseek(fd, 0L, SEEK_END);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6575 len = ftell(fd); /* get size of temp file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6576 fseek(fd, 0L, SEEK_SET);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6578 buffer = alloc(len + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6579 if (buffer != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6580 i = (int)fread((char *)buffer, (size_t)1, (size_t)len, fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6581 fclose(fd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6582 mch_remove(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6583 if (buffer == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6584 goto done;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6585 #ifdef VMS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6586 len = i; /* VMS doesn't give us what we asked for... */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6587 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6588 if (i != len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6589 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15420
diff changeset
6590 semsg(_(e_notread), tempname);
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13188
diff changeset
6591 VIM_CLEAR(buffer);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6592 }
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6593 else if (ret_len == NULL)
5271
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
6594 {
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
6595 /* Change NUL into SOH, otherwise the string is truncated. */
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
6596 for (i = 0; i < len; ++i)
5275
3ddec3d25bd1 updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents: 5271
diff changeset
6597 if (buffer[i] == NUL)
3ddec3d25bd1 updated for version 7.4b.014
Bram Moolenaar <bram@vim.org>
parents: 5271
diff changeset
6598 buffer[i] = 1;
5271
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
6599
2429
7ce8b24450dc Improvements for ":find" completion. (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents: 2409
diff changeset
6600 buffer[len] = NUL; /* make sure the buffer is terminated */
5271
25f67b62afd8 updated for version 7.4b.012
Bram Moolenaar <bram@vim.org>
parents: 5104
diff changeset
6601 }
5808
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6602 else
e5f1f2ea0b4a updated for version 7.4.248
Bram Moolenaar <bram@vim.org>
parents: 5782
diff changeset
6603 *ret_len = len;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6604
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6605 done:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6606 vim_free(tempname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6607 return buffer;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6608 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6609 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6610
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6611 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6612 * Free the list of files returned by expand_wildcards() or other expansion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6613 * functions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6614 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6615 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6616 FreeWild(int count, char_u **files)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6617 {
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 835
diff changeset
6618 if (count <= 0 || files == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6619 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6620 while (count--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6621 vim_free(files[count]);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6622 vim_free(files);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6624
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6625 /*
2302
488be8cbe19c Make CTRL-L in command line mode respect 'ignorecase' and 'smartcase'. (Martin
Bram Moolenaar <bram@vim.org>
parents: 2297
diff changeset
6626 * Return TRUE when need to go to Insert mode because of 'insertmode'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6627 * Don't do this when still processing a command or a mapping.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6628 * Don't do this when inside a ":normal" command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6629 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6630 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6631 goto_im(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6632 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6633 return (p_im && stuff_empty() && typebuf_typed());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6634 }
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6635
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6636 /*
5911
81f5a056b2a5 updated for version 7.4.297
Bram Moolenaar <bram@vim.org>
parents: 5885
diff changeset
6637 * Returns the isolated name of the shell in allocated memory:
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6638 * - Skip beyond any path. E.g., "/usr/bin/csh -f" -> "csh -f".
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6639 * - Remove any argument. E.g., "csh -f" -> "csh".
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6640 * But don't allow a space in the path, so that this works:
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6641 * "/usr/bin/csh --rcfile ~/.cshrc"
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6642 * But don't do that for Windows, it's common to have a space in the path.
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6643 */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6644 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7803
diff changeset
6645 get_isolated_shell_name(void)
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6646 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6647 char_u *p;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6648
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6649 #ifdef WIN3264
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6650 p = gettail(p_sh);
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6651 p = vim_strnsave(p, (int)(skiptowhite(p) - p));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6652 #else
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6653 p = skiptowhite(p_sh);
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6654 if (*p == NUL)
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6655 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6656 /* No white space, use the tail. */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6657 p = vim_strsave(gettail(p_sh));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6658 }
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6659 else
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6660 {
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6661 char_u *p1, *p2;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6662
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6663 /* Find the last path separator before the space. */
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6664 p1 = p_sh;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
6665 for (p2 = p_sh; p2 < p; MB_PTR_ADV(p2))
5867
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6666 if (vim_ispathsep(*p2))
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6667 p1 = p2 + 1;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6668 p = vim_strnsave(p1, (int)(p - p1));
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6669 }
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6670 #endif
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6671 return p;
a6b59ee633a3 updated for version 7.4.276
Bram Moolenaar <bram@vim.org>
parents: 5808
diff changeset
6672 }
15814
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6673
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6674 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6675 * Check if the "://" of a URL is at the pointer, return URL_SLASH.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6676 * Also check for ":\\", which MS Internet Explorer accepts, return
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6677 * URL_BACKSLASH.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6678 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6679 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6680 path_is_url(char_u *p)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6681 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6682 if (STRNCMP(p, "://", (size_t)3) == 0)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6683 return URL_SLASH;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6684 else if (STRNCMP(p, ":\\\\", (size_t)3) == 0)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6685 return URL_BACKSLASH;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6686 return 0;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6687 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6688
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6689 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6690 * Check if "fname" starts with "name://". Return URL_SLASH if it does.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6691 * Return URL_BACKSLASH for "name:\\".
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6692 * Return zero otherwise.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6693 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6694 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6695 path_with_url(char_u *fname)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6696 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6697 char_u *p;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6698
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6699 for (p = fname; isalpha(*p); ++p)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6700 ;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6701 return path_is_url(p);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6702 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6703
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6704 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6705 * Return TRUE if "name" is a full (absolute) path name or URL.
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6706 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6707 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6708 vim_isAbsName(char_u *name)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6709 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6710 return (path_with_url(name) != 0 || mch_isFullName(name));
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6711 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6712
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6713 /*
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6714 * Get absolute file name into buffer "buf[len]".
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6715 *
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6716 * return FAIL for failure, OK otherwise
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6717 */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6718 int
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6719 vim_FullName(
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6720 char_u *fname,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6721 char_u *buf,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6722 int len,
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6723 int force) /* force expansion even when already absolute */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6724 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6725 int retval = OK;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6726 int url;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6727
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6728 *buf = NUL;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6729 if (fname == NULL)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6730 return FAIL;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6731
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6732 url = path_with_url(fname);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6733 if (!url)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6734 retval = mch_FullName(fname, buf, len, force);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6735 if (url || retval == FAIL)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6736 {
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6737 /* something failed; use the file name (truncate when too long) */
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6738 vim_strncpy(buf, fname, len - 1);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6739 }
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6740 #if defined(MSWIN)
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6741 slash_adjust(buf);
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6742 #endif
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6743 return retval;
99ebf78686a9 patch 8.1.0914: code related to findfile() is spread out
Bram Moolenaar <Bram@vim.org>
parents: 15699
diff changeset
6744 }