Mercurial > vim
annotate src/buffer.c @ 20403:eba6981e3c9c v8.2.0756
patch 8.2.0756: MS-Windows: still a compiler warning
Commit: https://github.com/vim/vim/commit/7e6f3fcc3ce89fc8ade85be39aa475e606c0b26c
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 15 18:21:51 2020 +0200
patch 8.2.0756: MS-Windows: still a compiler warning
Problem: MS-Windows: still a compiler warning.
Solution: Move flag to another place in the Makefile. (Ken Takata,
closes #6083)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 15 May 2020 18:30:05 +0200 |
parents | 3ff714d765ba |
children | d571231175b4 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9943
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * buffer.c: functions for dealing with the buffer structure | |
12 */ | |
13 | |
14 /* | |
15 * The buffer list is a double linked list of all buffers. | |
16 * Each buffer can be in one of these states: | |
17 * never loaded: BF_NEVERLOADED is set, only the file name is valid | |
18 * not loaded: b_ml.ml_mfp == NULL, no memfile allocated | |
19 * hidden: b_nwindows == 0, loaded but not displayed in a window | |
20 * normal: loaded and displayed in a window | |
21 * | |
22 * Instead of storing file names all over the place, each file name is | |
23 * stored in the buffer list. It can be referenced by a number. | |
24 * | |
25 * The current implementation remembers all file names ever used. | |
26 */ | |
27 | |
28 #include "vim.h" | |
29 | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
30 static void enter_buffer(buf_T *buf); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
31 static void buflist_getfpos(void); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
32 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
33 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); |
7 | 34 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
35 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
36 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
37 static int buf_same_ino(buf_T *buf, stat_T *stp); |
7 | 38 #else |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
39 static int otherfile_buf(buf_T *buf, char_u *ffname); |
7 | 40 #endif |
41 #ifdef FEAT_TITLE | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
42 static int value_changed(char_u *str, char_u **last); |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
43 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
44 static int append_arg_number(win_T *wp, char_u *buf, int buflen, int add_file); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
45 static void free_buffer(buf_T *); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
46 static void free_buffer_stuff(buf_T *buf, int free_options); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
47 static void clear_wininfo(buf_T *buf); |
7 | 48 |
49 #ifdef UNIX | |
50 # define dev_T dev_t | |
51 #else | |
52 # define dev_T unsigned | |
53 #endif | |
54 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
55 #define FOR_ALL_BUFS_FROM_LAST(buf) \ |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
56 for ((buf) = lastbuf; (buf) != NULL; (buf) = (buf)->b_prev) |
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
57 |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
58 #if defined(FEAT_QUICKFIX) |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
59 static char *msg_loclist = N_("[Location List]"); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
60 static char *msg_qflist = N_("[Quickfix List]"); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
61 #endif |
3365 | 62 static char *e_auabort = N_("E855: Autocommands caused command to abort"); |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
63 |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
64 // Number of times free_buffer() was called. |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
65 static int buf_free_count = 0; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
66 |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
67 static int top_file_num = 1; // highest file number |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
68 static garray_T buf_reuse = GA_EMPTY; // file numbers to recycle |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
69 |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
70 /* |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
71 * Return the highest possible buffer number. |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
72 */ |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
73 int |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
74 get_highest_fnum(void) |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
75 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
76 return top_file_num - 1; |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
77 } |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
78 |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
79 /* |
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
80 * Read data from buffer for retrying. |
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
81 */ |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
82 static int |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
83 read_buffer( |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
84 int read_stdin, // read file from stdin, otherwise fifo |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
85 exarg_T *eap, // for forced 'ff' and 'fenc' or NULL |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
86 int flags) // extra flags for readfile() |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
87 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
88 int retval = OK; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
89 linenr_T line_count; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
90 |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
91 /* |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
92 * Read from the buffer which the text is already filled in and append at |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
93 * the end. This makes it possible to retry when 'fileformat' or |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
94 * 'fileencoding' was guessed wrong. |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
95 */ |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
96 line_count = curbuf->b_ml.ml_line_count; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
97 retval = readfile( |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
98 read_stdin ? NULL : curbuf->b_ffname, |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
99 read_stdin ? NULL : curbuf->b_fname, |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
100 (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
101 flags | READ_BUFFER); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
102 if (retval == OK) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
103 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
104 // Delete the binary lines. |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
105 while (--line_count >= 0) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
106 ml_delete((linenr_T)1, FALSE); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
107 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
108 else |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
109 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
110 // Delete the converted lines. |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
111 while (curbuf->b_ml.ml_line_count > line_count) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
112 ml_delete(line_count, FALSE); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
113 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
114 // Put the cursor on the first line. |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
115 curwin->w_cursor.lnum = 1; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
116 curwin->w_cursor.col = 0; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
117 |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
118 if (read_stdin) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
119 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
120 // Set or reset 'modified' before executing autocommands, so that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
121 // it can be changed there. |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11063
diff
changeset
|
122 if (!readonlymode && !BUFEMPTY()) |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
123 changed(); |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
124 else if (retval == OK) |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
125 unchanged(curbuf, FALSE, TRUE); |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
126 |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
127 if (retval == OK) |
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
128 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
129 #ifdef FEAT_EVAL |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
130 apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE, |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
131 curbuf, &retval); |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
132 #else |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
133 apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
134 #endif |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
135 } |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
136 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
137 return retval; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
138 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
139 |
7 | 140 /* |
17225
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
141 * Ensure buffer "buf" is loaded. Does not trigger the swap-exists action. |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
142 */ |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
143 void |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
144 buffer_ensure_loaded(buf_T *buf) |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
145 { |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
146 if (buf->b_ml.ml_mfp == NULL) |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
147 { |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
148 aco_save_T aco; |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
149 |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
150 aucmd_prepbuf(&aco, buf); |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
151 swap_exists_action = SEA_NONE; |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
152 open_buffer(FALSE, NULL, 0); |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
153 aucmd_restbuf(&aco); |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
154 } |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
155 } |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
156 |
09fa437d33d8
patch 8.1.1612: cannot show an existing buffer in a popup window
Bram Moolenaar <Bram@vim.org>
parents:
17151
diff
changeset
|
157 /* |
2214
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
158 * Open current buffer, that is: open the memfile and read the file into |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
159 * memory. |
f8222d1f9a73
Included patch for persistent undo. Lots of changes and added test.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
160 * Return FAIL for failure, OK otherwise. |
7 | 161 */ |
162 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
163 open_buffer( |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
164 int read_stdin, // read file from stdin |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
165 exarg_T *eap, // for forced 'ff' and 'fenc' or NULL |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
166 int flags) // extra flags for readfile() |
7 | 167 { |
168 int retval = OK; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
169 bufref_T old_curbuf; |
4139 | 170 #ifdef FEAT_SYN_HL |
171 long old_tw = curbuf->b_p_tw; | |
172 #endif | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
173 int read_fifo = FALSE; |
7 | 174 |
175 /* | |
176 * The 'readonly' flag is only set when BF_NEVERLOADED is being reset. | |
177 * When re-entering the same buffer, it should not change, because the | |
178 * user may have reset the flag by hand. | |
179 */ | |
180 if (readonlymode && curbuf->b_ffname != NULL | |
181 && (curbuf->b_flags & BF_NEVERLOADED)) | |
182 curbuf->b_p_ro = TRUE; | |
183 | |
625 | 184 if (ml_open(curbuf) == FAIL) |
7 | 185 { |
186 /* | |
187 * There MUST be a memfile, otherwise we can't do anything | |
188 * If we can't create one for the current buffer, take another buffer | |
189 */ | |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
190 close_buffer(NULL, curbuf, 0, FALSE, FALSE); |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
191 FOR_ALL_BUFFERS(curbuf) |
7 | 192 if (curbuf->b_ml.ml_mfp != NULL) |
193 break; | |
194 /* | |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
195 * If there is no memfile at all, exit. |
1698 | 196 * This is OK, since there are no changes to lose. |
7 | 197 */ |
198 if (curbuf == NULL) | |
199 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
200 emsg(_("E82: Cannot allocate any buffer, exiting...")); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
201 |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
202 // Don't try to do any saving, with "curbuf" NULL almost nothing |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
203 // will work. |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
204 v_dying = 2; |
7 | 205 getout(2); |
206 } | |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
207 |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
208 emsg(_("E83: Cannot allocate buffer, using other one...")); |
7 | 209 enter_buffer(curbuf); |
4139 | 210 #ifdef FEAT_SYN_HL |
211 if (old_tw != curbuf->b_p_tw) | |
212 check_colorcolumn(curwin); | |
213 #endif | |
7 | 214 return FAIL; |
215 } | |
216 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
217 // The autocommands in readfile() may change the buffer, but only AFTER |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
218 // reading the file. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
219 set_bufref(&old_curbuf, curbuf); |
7 | 220 modified_was_set = FALSE; |
221 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
222 // mark cursor position as being invalid |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
223 curwin->w_valid = 0; |
7 | 224 |
225 if (curbuf->b_ffname != NULL | |
226 #ifdef FEAT_NETBEANS_INTG | |
227 && netbeansReadFile | |
228 #endif | |
229 ) | |
230 { | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
231 int old_msg_silent = msg_silent; |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
232 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
233 int save_bin = curbuf->b_p_bin; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
234 int perm; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
235 #endif |
7 | 236 #ifdef FEAT_NETBEANS_INTG |
237 int oldFire = netbeansFireChanges; | |
238 | |
239 netbeansFireChanges = 0; | |
240 #endif | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
241 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
242 perm = mch_getperm(curbuf->b_ffname); |
14509
80f715651c4c
patch 8.1.0268: file type checking has too many #ifdef
Christian Brabandt <cb@256bit.org>
parents:
14479
diff
changeset
|
243 if (perm >= 0 && (S_ISFIFO(perm) |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
244 || S_ISSOCK(perm) |
9911
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
245 # ifdef OPEN_CHR_FILES |
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
246 || (S_ISCHR(perm) && is_dev_fd_file(curbuf->b_ffname)) |
74e345d2878c
commit https://github.com/vim/vim/commit/f04507d132fbcb63999167ec006fc6e700b5af4f
Christian Brabandt <cb@256bit.org>
parents:
9875
diff
changeset
|
247 # endif |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
248 )) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
249 read_fifo = TRUE; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
250 if (read_fifo) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
251 curbuf->b_p_bin = TRUE; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
252 #endif |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
253 if (shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
254 msg_silent = 1; |
7 | 255 retval = readfile(curbuf->b_ffname, curbuf->b_fname, |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
256 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
257 flags | READ_NEW | (read_fifo ? READ_FIFO : 0)); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
258 #ifdef UNIX |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
259 if (read_fifo) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
260 { |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
261 curbuf->b_p_bin = save_bin; |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
262 if (retval == OK) |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
263 retval = read_buffer(FALSE, eap, flags); |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
264 } |
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
265 #endif |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8441
diff
changeset
|
266 msg_silent = old_msg_silent; |
7 | 267 #ifdef FEAT_NETBEANS_INTG |
268 netbeansFireChanges = oldFire; | |
269 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
270 // Help buffer is filtered. |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
271 if (bt_help(curbuf)) |
7 | 272 fix_help_buffer(); |
273 } | |
274 else if (read_stdin) | |
275 { | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
276 int save_bin = curbuf->b_p_bin; |
7 | 277 |
278 /* | |
279 * First read the text in binary mode into the buffer. | |
280 * Then read from that same buffer and append at the end. This makes | |
281 * it possible to retry when 'fileformat' or 'fileencoding' was | |
282 * guessed wrong. | |
283 */ | |
284 curbuf->b_p_bin = TRUE; | |
285 retval = readfile(NULL, NULL, (linenr_T)0, | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
286 (linenr_T)0, (linenr_T)MAXLNUM, NULL, |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
287 flags | (READ_NEW + READ_STDIN)); |
7 | 288 curbuf->b_p_bin = save_bin; |
289 if (retval == OK) | |
9828
e84e45786691
commit https://github.com/vim/vim/commit/f71d7b9ee5ceba75f70c30845332ddd728fd16c6
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
290 retval = read_buffer(TRUE, eap, flags); |
7 | 291 } |
292 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
293 // if first time loading this buffer, init b_chartab[] |
7 | 294 if (curbuf->b_flags & BF_NEVERLOADED) |
5438 | 295 { |
7 | 296 (void)buf_init_chartab(curbuf, FALSE); |
5440 | 297 #ifdef FEAT_CINDENT |
5438 | 298 parse_cino(curbuf); |
5440 | 299 #endif |
5438 | 300 } |
7 | 301 |
302 /* | |
303 * Set/reset the Changed flag first, autocmds may change the buffer. | |
304 * Apply the automatic commands, before processing the modelines. | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
305 * So the modelines have priority over autocommands. |
7 | 306 */ |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
307 // When reading stdin, the buffer contents always needs writing, so set |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
308 // the changed flag. Unless in readonly mode: "ls | gview -". |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
309 // When interrupted and 'cpoptions' contains 'i' set changed flag. |
1291 | 310 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
311 || modified_was_set // ":set modified" used in autocmd |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
312 #ifdef FEAT_EVAL |
7 | 313 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
314 #endif | |
1291 | 315 ) |
7 | 316 changed(); |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
317 else if (retval == OK && !read_stdin && !read_fifo) |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
318 unchanged(curbuf, FALSE, TRUE); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
319 save_file_ff(curbuf); // keep this fileformat |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
320 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
321 // Set last_changedtick to avoid triggering a TextChanged autocommand right |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
322 // after it was added. |
13519
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
323 curbuf->b_last_changedtick = CHANGEDTICK(curbuf); |
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
324 curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf); |
4a44c90dd671
patch 8.0.1633: a TextChanged autocmd triggers when it is defined
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
325 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
326 // require "!" to overwrite the file, because it wasn't read completely |
7 | 327 #ifdef FEAT_EVAL |
328 if (aborting()) | |
329 #else | |
330 if (got_int) | |
331 #endif | |
332 curbuf->b_flags |= BF_READERR; | |
333 | |
20 | 334 #ifdef FEAT_FOLDING |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
335 // Need to update automatic folding. Do this before the autocommands, |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
336 // they may use the fold info. |
20 | 337 foldUpdateAll(curwin); |
338 #endif | |
339 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
340 // need to set w_topline, unless some autocommand already did that. |
7 | 341 if (!(curwin->w_valid & VALID_TOPLINE)) |
342 { | |
343 curwin->w_topline = 1; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
344 #ifdef FEAT_DIFF |
7 | 345 curwin->w_topfill = 0; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
346 #endif |
7 | 347 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
348 #ifdef FEAT_EVAL |
7 | 349 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
350 #else |
7 | 351 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
352 #endif | |
353 | |
10575
01a5f64a7a20
patch 8.0.0177: BufEnter autocommand not fired for a directory
Christian Brabandt <cb@256bit.org>
parents:
10432
diff
changeset
|
354 if (retval == OK) |
7 | 355 { |
356 /* | |
357 * The autocommands may have changed the current buffer. Apply the | |
358 * modelines to the correct buffer, if it still exists and is loaded. | |
359 */ | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
360 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) |
7 | 361 { |
362 aco_save_T aco; | |
363 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
364 // Go to the buffer that was opened. |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
365 aucmd_prepbuf(&aco, old_curbuf.br_buf); |
717 | 366 do_modelines(0); |
7 | 367 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); |
368 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
369 #ifdef FEAT_EVAL |
7 | 370 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
371 &retval); |
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
372 #else |
7 | 373 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
374 #endif |
7 | 375 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
376 // restore curwin/curbuf and a few other things |
7 | 377 aucmd_restbuf(&aco); |
378 } | |
379 } | |
380 | |
381 return retval; | |
382 } | |
383 | |
384 /* | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
385 * Store "buf" in "bufref" and set the free count. |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
386 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
387 void |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
388 set_bufref(bufref_T *bufref, buf_T *buf) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
389 { |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
390 bufref->br_buf = buf; |
11531
e349dc7889f5
patch 8.0.0648: possible use of NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
391 bufref->br_fnum = buf == NULL ? 0 : buf->b_fnum; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
392 bufref->br_buf_free_count = buf_free_count; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
393 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
394 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
395 /* |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
396 * Return TRUE if "bufref->br_buf" points to the same buffer as when |
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
397 * set_bufref() was called and it is a valid buffer. |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
398 * Only goes through the buffer list if buf_free_count changed. |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
399 * Also checks if b_fnum is still the same, a :bwipe followed by :new might get |
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
400 * the same allocated memory, but it's a different buffer. |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
401 */ |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
402 int |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
403 bufref_valid(bufref_T *bufref) |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
404 { |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
405 return bufref->br_buf_free_count == buf_free_count |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
406 ? TRUE : buf_valid(bufref->br_buf) |
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
407 && bufref->br_fnum == bufref->br_buf->b_fnum; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
408 } |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
409 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
410 /* |
7 | 411 * Return TRUE if "buf" points to a valid buffer (in the buffer list). |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
412 * This can be slow if there are many buffers, prefer using bufref_valid(). |
7 | 413 */ |
414 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
415 buf_valid(buf_T *buf) |
7 | 416 { |
417 buf_T *bp; | |
418 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
419 // Assume that we more often have a recent buffer, start with the last |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
420 // one. |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
421 FOR_ALL_BUFS_FROM_LAST(bp) |
7 | 422 if (bp == buf) |
423 return TRUE; | |
424 return FALSE; | |
425 } | |
426 | |
427 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
428 * A hash table used to quickly lookup a buffer by its number. |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
429 */ |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
430 static hashtab_T buf_hashtab; |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
431 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
432 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
433 buf_hashtab_add(buf_T *buf) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
434 { |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
435 sprintf((char *)buf->b_key, "%x", buf->b_fnum); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
436 if (hash_add(&buf_hashtab, buf->b_key) == FAIL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
437 emsg(_("E931: Buffer cannot be registered")); |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
438 } |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
439 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
440 static void |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
441 buf_hashtab_remove(buf_T *buf) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
442 { |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
443 hashitem_T *hi = hash_find(&buf_hashtab, buf->b_key); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
444 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
445 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
446 hash_remove(&buf_hashtab, hi); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
447 } |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
448 |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
449 /* |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
450 * Return TRUE when buffer "buf" can be unloaded. |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
451 * Give an error message and return FALSE when the buffer is locked or the |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
452 * screen is being redrawn and the buffer is in a window. |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
453 */ |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
454 static int |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
455 can_unload_buffer(buf_T *buf) |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
456 { |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
457 int can_unload = !buf->b_locked; |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
458 |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
459 if (can_unload && updating_screen) |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
460 { |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
461 win_T *wp; |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
462 |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
463 FOR_ALL_WINDOWS(wp) |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
464 if (wp->w_buffer == buf) |
14826
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
465 { |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
466 can_unload = FALSE; |
14826
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
467 break; |
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
468 } |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
469 } |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
470 if (!can_unload) |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
471 semsg(_("E937: Attempt to delete a buffer that is in use: %s"), |
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
472 buf->b_fname); |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
473 return can_unload; |
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
474 } |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
475 |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
476 /* |
7 | 477 * Close the link to a buffer. |
478 * "action" is used when there is no longer a window for the buffer. | |
479 * It can be: | |
480 * 0 buffer becomes hidden | |
481 * DOBUF_UNLOAD buffer is unloaded | |
482 * DOBUF_DELETE buffer is unloaded and removed from buffer list | |
483 * DOBUF_WIPE buffer is unloaded and really deleted | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
484 * DOBUF_WIPE_REUSE idem, and add to buf_reuse list |
7 | 485 * When doing all but the first one on the current buffer, the caller should |
486 * get a new buffer very soon! | |
487 * | |
488 * The 'bufhidden' option can force freeing and deleting. | |
3365 | 489 * |
490 * When "abort_if_last" is TRUE then do not close the buffer if autocommands | |
491 * cause there to be only one window with this buffer. e.g. when ":quit" is | |
492 * supposed to close the window but autocommands close all other windows. | |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
493 * |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
494 * When "ignore_abort" is TRUE don't abort even when aborting() returns TRUE. |
7 | 495 */ |
496 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
497 close_buffer( |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
498 win_T *win, // if not NULL, set b_last_cursor |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
499 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
500 int action, |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
501 int abort_if_last, |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
502 int ignore_abort) |
7 | 503 { |
504 int is_curbuf; | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
1883
diff
changeset
|
505 int nwindows; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
506 bufref_T bufref; |
10320
6ab770e97152
commit https://github.com/vim/vim/commit/3a117e19e02bf29cfc5e398470dd7851ae3d6803
Christian Brabandt <cb@256bit.org>
parents:
10184
diff
changeset
|
507 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
10114
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
508 win_T *the_curwin = curwin; |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
509 tabpage_T *the_curtab = curtab; |
7 | 510 int unload_buf = (action != 0); |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
511 int wipe_buf = (action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
512 int del_buf = (action == DOBUF_DEL || wipe_buf); |
7 | 513 |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
514 CHECK_CURBUF; |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
515 /* |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
516 * Force unloading or deleting when 'bufhidden' says so. |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
517 * The caller must take care of NOT deleting/freeing when 'bufhidden' is |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
518 * "hide" (otherwise we could never free or delete a buffer). |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
519 */ |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
520 if (buf->b_p_bh[0] == 'd') // 'bufhidden' == "delete" |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
521 { |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
522 del_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
523 unload_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
524 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
525 else if (buf->b_p_bh[0] == 'w') // 'bufhidden' == "wipe" |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
526 { |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
527 del_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
528 unload_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
529 wipe_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
530 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
531 else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload" |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
532 unload_buf = TRUE; |
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
533 |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
534 #ifdef FEAT_TERMINAL |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
535 if (bt_terminal(buf) && (buf->b_nwindows == 1 || del_buf)) |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
536 { |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
537 CHECK_CURBUF; |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
538 if (term_job_running(buf->b_term)) |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
539 { |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
540 if (wipe_buf || unload_buf) |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
541 { |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
542 if (!can_unload_buffer(buf)) |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
543 return; |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
544 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
545 // Wiping out or unloading a terminal buffer kills the job. |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
546 free_terminal(buf); |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
547 } |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
548 else |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
549 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
550 // The job keeps running, hide the buffer. |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
551 del_buf = FALSE; |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
552 unload_buf = FALSE; |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
553 } |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
554 } |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
555 else |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
556 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
557 // A terminal buffer is wiped out if the job has finished. |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
558 del_buf = TRUE; |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
559 unload_buf = TRUE; |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
560 wipe_buf = TRUE; |
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
561 } |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
562 CHECK_CURBUF; |
11917
00836eb177cb
patch 8.0.0838: buffer hangs around whem terminal window is closed
Christian Brabandt <cb@256bit.org>
parents:
11834
diff
changeset
|
563 } |
12479
65c7769ef6d1
patch 8.0.1119: quitting a split terminal window kills the job
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
564 #endif |
7 | 565 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
566 // Disallow deleting the buffer when it is locked (already being closed or |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
567 // halfway a command that relies on it). Unloading is allowed. |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
568 if ((del_buf || wipe_buf) && !can_unload_buffer(buf)) |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
569 return; |
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
570 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
571 // check no autocommands closed the window |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
572 if (win != NULL && win_valid_any_tab(win)) |
7 | 573 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
574 // Set b_last_cursor when closing the last window for the buffer. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
575 // Remember the last cursor position and window options of the buffer. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
576 // This used to be only for the current window, but then options like |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
577 // 'foldmethod' may be lost with a ":only" command. |
7 | 578 if (buf->b_nwindows == 1) |
579 set_last_cursor(win); | |
580 buflist_setfpos(buf, win, | |
581 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, | |
582 win->w_cursor.col, TRUE); | |
583 } | |
584 | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
585 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
586 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
587 // When the buffer is no longer in a window, trigger BufWinLeave |
7 | 588 if (buf->b_nwindows == 1) |
589 { | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
590 ++buf->b_locked; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
591 if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
592 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
593 && !bufref_valid(&bufref)) |
3365 | 594 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
595 // Autocommands deleted the buffer. |
3570 | 596 aucmd_abort: |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
597 emsg(_(e_auabort)); |
7 | 598 return; |
3365 | 599 } |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
600 --buf->b_locked; |
3570 | 601 if (abort_if_last && one_window()) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
602 // Autocommands made this the only window. |
3570 | 603 goto aucmd_abort; |
7 | 604 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
605 // When the buffer becomes hidden, but is not unloaded, trigger |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
606 // BufHidden |
7 | 607 if (!unload_buf) |
608 { | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
609 ++buf->b_locked; |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
610 if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
611 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
612 && !bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
613 // Autocommands deleted the buffer. |
3570 | 614 goto aucmd_abort; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
615 --buf->b_locked; |
3570 | 616 if (abort_if_last && one_window()) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
617 // Autocommands made this the only window. |
3570 | 618 goto aucmd_abort; |
7 | 619 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
620 #ifdef FEAT_EVAL |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
621 // autocmds may abort script processing |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
622 if (!ignore_abort && aborting()) |
7 | 623 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
624 #endif |
7 | 625 } |
10114
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
626 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
627 // If the buffer was in curwin and the window has changed, go back to that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
628 // window, if it still exists. This avoids that ":edit x" triggering a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
629 // "tabnext" BufUnload autocmd leaves a window behind without a buffer. |
10114
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
630 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
631 { |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
632 block_autocmds(); |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
633 goto_tabpage_win(the_curtab, the_curwin); |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
634 unblock_autocmds(); |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
635 } |
aa2219afd1c2
commit https://github.com/vim/vim/commit/f9e687e0681a250e1549ab27b6c7ef2c500395e3
Christian Brabandt <cb@256bit.org>
parents:
10108
diff
changeset
|
636 |
7 | 637 nwindows = buf->b_nwindows; |
638 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
639 // decrease the link count from windows (unless not in any window) |
7 | 640 if (buf->b_nwindows > 0) |
641 --buf->b_nwindows; | |
642 | |
12971
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12684
diff
changeset
|
643 #ifdef FEAT_DIFF |
ca3cb1997f08
patch 8.0.1361: some users don't want to diff with hidden buffers
Christian Brabandt <cb@256bit.org>
parents:
12684
diff
changeset
|
644 if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
645 diff_buf_delete(buf); // Clear 'diff' for hidden buffer. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
646 #endif |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
647 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
648 // Return when a window is displaying the buffer or when it's not |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
649 // unloaded. |
7 | 650 if (buf->b_nwindows > 0 || !unload_buf) |
651 return; | |
652 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
653 // Always remove the buffer when there is no file name. |
7 | 654 if (buf->b_ffname == NULL) |
655 del_buf = TRUE; | |
656 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
657 // When closing the current buffer stop Visual mode before freeing |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
658 // anything. |
10184
4669440016f2
commit https://github.com/vim/vim/commit/4930a76a0357f76a829eafe4985d04cf3ce0e9e0
Christian Brabandt <cb@256bit.org>
parents:
10156
diff
changeset
|
659 if (buf == curbuf && VIsual_active |
10156
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
660 #if defined(EXITFREE) |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
661 && !entered_free_all_mem |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
662 #endif |
f1ad88f3834c
commit https://github.com/vim/vim/commit/9a27c7fde6d453d9892b6f6baa756bce4d6d419d
Christian Brabandt <cb@256bit.org>
parents:
10154
diff
changeset
|
663 ) |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
664 end_visual_mode(); |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
665 |
7 | 666 /* |
667 * Free all things allocated for this buffer. | |
668 * Also calls the "BufDelete" autocommands when del_buf is TRUE. | |
669 */ | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
670 // Remember if we are closing the current buffer. Restore the number of |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
671 // windows, so that autocommands in buf_freeall() don't get confused. |
7 | 672 is_curbuf = (buf == curbuf); |
673 buf->b_nwindows = nwindows; | |
674 | |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
675 buf_freeall(buf, (del_buf ? BFA_DEL : 0) |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
676 + (wipe_buf ? BFA_WIPE : 0) |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
677 + (ignore_abort ? BFA_IGNORE_ABORT : 0)); |
7 | 678 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
679 // Autocommands may have deleted the buffer. |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
680 if (!bufref_valid(&bufref)) |
7 | 681 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
682 #ifdef FEAT_EVAL |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
683 // autocmds may abort script processing |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
684 if (!ignore_abort && aborting()) |
7 | 685 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
686 #endif |
7 | 687 |
688 /* | |
689 * It's possible that autocommands change curbuf to the one being deleted. | |
690 * This might cause the previous curbuf to be deleted unexpectedly. But | |
691 * in some cases it's OK to delete the curbuf, because a new one is | |
692 * obtained anyway. Therefore only return if curbuf changed to the | |
693 * deleted buffer. | |
694 */ | |
695 if (buf == curbuf && !is_curbuf) | |
696 return; | |
9450
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
697 |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
698 if (win_valid_any_tab(win) && win->w_buffer == buf) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
699 win->w_buffer = NULL; // make sure we don't use the buffer now |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
700 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
701 // Autocommands may have opened or closed windows for this buffer. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
702 // Decrement the count for the close we do here. |
9450
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
703 if (buf->b_nwindows > 0) |
073aebdba121
commit https://github.com/vim/vim/commit/30445cb6e94698d212ba866ef3e4022ac625540a
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
704 --buf->b_nwindows; |
7 | 705 |
706 /* | |
707 * Remove the buffer from the list. | |
708 */ | |
709 if (wipe_buf) | |
710 { | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
711 if (action == DOBUF_WIPE_REUSE) |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
712 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
713 // we can re-use this buffer number, store it |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
714 if (buf_reuse.ga_itemsize == 0) |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
715 ga_init2(&buf_reuse, sizeof(int), 50); |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
716 if (ga_grow(&buf_reuse, 1) == OK) |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
717 ((int *)buf_reuse.ga_data)[buf_reuse.ga_len++] = buf->b_fnum; |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
718 } |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
719 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
720 VIM_CLEAR(buf->b_sfname); |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
721 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
722 buf->b_sfname = NULL; |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
723 VIM_CLEAR(buf->b_ffname); |
7 | 724 if (buf->b_prev == NULL) |
725 firstbuf = buf->b_next; | |
726 else | |
727 buf->b_prev->b_next = buf->b_next; | |
728 if (buf->b_next == NULL) | |
729 lastbuf = buf->b_prev; | |
730 else | |
731 buf->b_next->b_prev = buf->b_prev; | |
732 free_buffer(buf); | |
733 } | |
734 else | |
735 { | |
736 if (del_buf) | |
737 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
738 // Free all internal variables and reset option values, to make |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
739 // ":bdel" compatible with Vim 5.7. |
7 | 740 free_buffer_stuff(buf, TRUE); |
741 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
742 // Make it look like a new buffer. |
7 | 743 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; |
744 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
745 // Init the options when loaded again. |
7 | 746 buf->b_p_initialized = FALSE; |
747 } | |
748 buf_clear_file(buf); | |
749 if (del_buf) | |
750 buf->b_p_bl = FALSE; | |
751 } | |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
752 // NOTE: at this point "curbuf" may be invalid! |
7 | 753 } |
754 | |
755 /* | |
756 * Make buffer not contain a file. | |
757 */ | |
758 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
759 buf_clear_file(buf_T *buf) |
7 | 760 { |
761 buf->b_ml.ml_line_count = 1; | |
16996
d5e1e09a829f
patch 8.1.1498: ":write" increments b:changedtick even though nothing changed
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
762 unchanged(buf, TRUE, TRUE); |
7 | 763 buf->b_shortname = FALSE; |
764 buf->b_p_eol = TRUE; | |
765 buf->b_start_eol = TRUE; | |
766 buf->b_p_bomb = FALSE; | |
1352 | 767 buf->b_start_bomb = FALSE; |
7 | 768 buf->b_ml.ml_mfp = NULL; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
769 buf->b_ml.ml_flags = ML_EMPTY; // empty buffer |
7 | 770 #ifdef FEAT_NETBEANS_INTG |
771 netbeans_deleted_all_lines(buf); | |
772 #endif | |
773 } | |
774 | |
775 /* | |
776 * buf_freeall() - free all things allocated for a buffer that are related to | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
777 * the file. Careful: get here with "curwin" NULL when exiting. |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
778 * flags: |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
779 * BFA_DEL buffer is going to be deleted |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
780 * BFA_WIPE buffer is going to be wiped out |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
781 * BFA_KEEP_UNDO do not free undo information |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
782 * BFA_IGNORE_ABORT don't abort even when aborting() returns TRUE |
7 | 783 */ |
784 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
785 buf_freeall(buf_T *buf, int flags) |
7 | 786 { |
787 int is_curbuf = (buf == curbuf); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
788 bufref_T bufref; |
10118
5d77565e6222
commit https://github.com/vim/vim/commit/030cddc7ec0c3d2fe3969140cd1b92b2f18633c0
Christian Brabandt <cb@256bit.org>
parents:
10114
diff
changeset
|
789 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
790 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
791 tabpage_T *the_curtab = curtab; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
792 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
793 // Make sure the buffer isn't closed by autocommands. |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
794 ++buf->b_locked; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
795 set_bufref(&bufref, buf); |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
796 if (buf->b_ml.ml_mfp != NULL) |
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
797 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
798 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
799 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
800 && !bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
801 // autocommands deleted the buffer |
9106
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
802 return; |
97a9538c37ff
commit https://github.com/vim/vim/commit/c67e89213476b5f4756d92208b57ce9ef4a4cf24
Christian Brabandt <cb@256bit.org>
parents:
9087
diff
changeset
|
803 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
804 if ((flags & BFA_DEL) && buf->b_p_bl) |
7 | 805 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
806 if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
807 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
808 && !bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
809 // autocommands deleted the buffer |
7 | 810 return; |
811 } | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
812 if (flags & BFA_WIPE) |
7 | 813 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
814 if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname, |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
815 FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
816 && !bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
817 // autocommands deleted the buffer |
7 | 818 return; |
819 } | |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
820 --buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
821 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
822 // If the buffer was in curwin and the window has changed, go back to that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
823 // window, if it still exists. This avoids that ":edit x" triggering a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
824 // "tabnext" BufUnload autocmd leaves a window behind without a buffer. |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
825 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
826 { |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
827 block_autocmds(); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
828 goto_tabpage_win(the_curtab, the_curwin); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
829 unblock_autocmds(); |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
830 } |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
831 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
832 #ifdef FEAT_EVAL |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
833 // autocmds may abort script processing |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
834 if ((flags & BFA_IGNORE_ABORT) == 0 && aborting()) |
7 | 835 return; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
836 #endif |
7 | 837 |
838 /* | |
839 * It's possible that autocommands change curbuf to the one being deleted. | |
840 * This might cause curbuf to be deleted unexpectedly. But in some cases | |
841 * it's OK to delete the curbuf, because a new one is obtained anyway. | |
842 * Therefore only return if curbuf changed to the deleted buffer. | |
843 */ | |
844 if (buf == curbuf && !is_curbuf) | |
845 return; | |
846 #ifdef FEAT_DIFF | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
847 diff_buf_delete(buf); // Can't use 'diff' for unloaded buffer. |
7 | 848 #endif |
3068 | 849 #ifdef FEAT_SYN_HL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
850 // Remove any ownsyntax, unless exiting. |
10118
5d77565e6222
commit https://github.com/vim/vim/commit/030cddc7ec0c3d2fe3969140cd1b92b2f18633c0
Christian Brabandt <cb@256bit.org>
parents:
10114
diff
changeset
|
851 if (curwin != NULL && curwin->w_buffer == buf) |
3182 | 852 reset_synblock(curwin); |
3068 | 853 #endif |
1187 | 854 |
855 #ifdef FEAT_FOLDING | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
856 // No folds in an empty buffer. |
1187 | 857 { |
858 win_T *win; | |
859 tabpage_T *tp; | |
860 | |
861 FOR_ALL_TAB_WINDOWS(tp, win) | |
862 if (win->w_buffer == buf) | |
863 clearFolding(win); | |
864 } | |
865 #endif | |
866 | |
7 | 867 #ifdef FEAT_TCL |
868 tcl_buffer_free(buf); | |
869 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
870 ml_close(buf, TRUE); // close and delete the memline/memfile |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
871 buf->b_ml.ml_line_count = 0; // no lines in buffer |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
872 if ((flags & BFA_KEEP_UNDO) == 0) |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
873 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
874 u_blockfree(buf); // free the memory allocated for undo |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
875 u_clearall(buf); // reset all undo information |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
876 } |
7 | 877 #ifdef FEAT_SYN_HL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
878 syntax_clear(&buf->b_s); // reset syntax info |
7 | 879 #endif |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
880 #ifdef FEAT_PROP_POPUP |
15138
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15056
diff
changeset
|
881 clear_buf_prop_types(buf); |
9df130fd5e0d
patch 8.1.0579: cannot attach properties to text
Bram Moolenaar <Bram@vim.org>
parents:
15056
diff
changeset
|
882 #endif |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
883 buf->b_flags &= ~BF_READERR; // a read error is no longer relevant |
7 | 884 } |
885 | |
886 /* | |
887 * Free a buffer structure and the things it contains related to the buffer | |
888 * itself (not the file, that must have been done already). | |
889 */ | |
890 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
891 free_buffer(buf_T *buf) |
7 | 892 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
893 ++buf_free_count; |
7 | 894 free_buffer_stuff(buf, TRUE); |
4287 | 895 #ifdef FEAT_EVAL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
896 // b:changedtick uses an item in buf_T, remove it now |
12630
560adb3eed8b
patch 8.0.1193: crash when wiping out a buffer after using getbufinfo()
Christian Brabandt <cb@256bit.org>
parents:
12572
diff
changeset
|
897 dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di); |
4287 | 898 unref_var_dict(buf->b_vars); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
899 remove_listeners(buf); |
4287 | 900 #endif |
2320
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
901 #ifdef FEAT_LUA |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
902 lua_buffer_free(buf); |
966a5609669e
Added Lua interfae. (Luis Carvalho)
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
903 #endif |
14 | 904 #ifdef FEAT_MZSCHEME |
905 mzscheme_buffer_free(buf); | |
906 #endif | |
7 | 907 #ifdef FEAT_PERL |
908 perl_buf_free(buf); | |
909 #endif | |
910 #ifdef FEAT_PYTHON | |
911 python_buffer_free(buf); | |
912 #endif | |
2329
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
913 #ifdef FEAT_PYTHON3 |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
914 python3_buffer_free(buf); |
ad2889f48843
Added support for Python 3. (Roland Puntaier)
Bram Moolenaar <bram@vim.org>
parents:
2320
diff
changeset
|
915 #endif |
7 | 916 #ifdef FEAT_RUBY |
917 ruby_buffer_free(buf); | |
918 #endif | |
9087
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
919 #ifdef FEAT_JOB_CHANNEL |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
920 channel_buffer_free(buf); |
d4606ae170aa
commit https://github.com/vim/vim/commit/e0f76d00979c972329f6c371463a20da61ccad65
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
921 #endif |
11690
ce434212d682
patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents:
11531
diff
changeset
|
922 #ifdef FEAT_TERMINAL |
11834
0cfe4a07c2ad
patch 8.0.0797: finished job in terminal window is not handled
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
923 free_terminal(buf); |
11690
ce434212d682
patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents:
11531
diff
changeset
|
924 #endif |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
925 #ifdef FEAT_JOB_CHANNEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
926 vim_free(buf->b_prompt_text); |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16859
diff
changeset
|
927 free_callback(&buf->b_prompt_callback); |
18225
6c3a8312486d
patch 8.1.2107: various memory leaks reported by asan
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
928 free_callback(&buf->b_prompt_interrupt); |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
929 #endif |
9515
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
930 |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
931 buf_hashtab_remove(buf); |
bb538c090668
commit https://github.com/vim/vim/commit/9280e3f95d065733f04fa22869e5ef071d531931
Christian Brabandt <cb@256bit.org>
parents:
9511
diff
changeset
|
932 |
40 | 933 aubuflocal_remove(buf); |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
934 |
5816 | 935 if (autocmd_busy) |
936 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
937 // Do not free the buffer structure while autocommands are executing, |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
938 // it's still needed. Free it when autocmd_busy is reset. |
5816 | 939 buf->b_next = au_pending_free_buf; |
940 au_pending_free_buf = buf; | |
941 } | |
942 else | |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
943 { |
5816 | 944 vim_free(buf); |
19629
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
945 if (curbuf == buf) |
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
946 curbuf = NULL; // make clear it's not to be used |
804322d6c6ba
patch 8.2.0371: crash with combination of terminal popup and autocmd
Bram Moolenaar <Bram@vim.org>
parents:
19354
diff
changeset
|
947 } |
7 | 948 } |
949 | |
950 /* | |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
951 * Initializes b:changedtick. |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
952 */ |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
953 static void |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
954 init_changedtick(buf_T *buf) |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
955 { |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
956 dictitem_T *di = (dictitem_T *)&buf->b_ct_di; |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
957 |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
958 di->di_flags = DI_FLAGS_FIX | DI_FLAGS_RO; |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
959 di->di_tv.v_type = VAR_NUMBER; |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
960 di->di_tv.v_lock = VAR_FIXED; |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
961 di->di_tv.vval.v_number = 0; |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
962 |
10954
8ff62b4cffae
patch 8.0.0366: build fails with tiny features
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
963 #ifdef FEAT_EVAL |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
964 STRCPY(buf->b_ct_di.di_key, "changedtick"); |
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
965 (void)dict_add(buf->b_vars, di); |
10954
8ff62b4cffae
patch 8.0.0366: build fails with tiny features
Christian Brabandt <cb@256bit.org>
parents:
10952
diff
changeset
|
966 #endif |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
967 } |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
968 |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
969 /* |
7 | 970 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. |
971 */ | |
972 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
973 free_buffer_stuff( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
974 buf_T *buf, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
975 int free_options) // free options as well |
7 | 976 { |
977 if (free_options) | |
978 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
979 clear_wininfo(buf); // including window-local options |
7 | 980 free_buf_options(buf, TRUE); |
2620 | 981 #ifdef FEAT_SPELL |
982 ga_clear(&buf->b_s.b_langp); | |
983 #endif | |
7 | 984 } |
985 #ifdef FEAT_EVAL | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
986 { |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
987 varnumber_T tick = CHANGEDTICK(buf); |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
988 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
989 vars_clear(&buf->b_vars->dv_hashtab); // free all buffer variables |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
990 hash_init(&buf->b_vars->dv_hashtab); |
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
991 init_changedtick(buf); |
10952
835604f3c37a
patch 8.0.0365: might free a dict item that wasn't allocated
Christian Brabandt <cb@256bit.org>
parents:
10912
diff
changeset
|
992 CHANGEDTICK(buf) = tick; |
19044
af795b6a2624
patch 8.2.0082: when reusing a buffer listeners are not cleared
Bram Moolenaar <Bram@vim.org>
parents:
19007
diff
changeset
|
993 remove_listeners(buf); |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
994 } |
7 | 995 #endif |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16261
diff
changeset
|
996 uc_clear(&buf->b_ucmds); // clear local user commands |
7 | 997 #ifdef FEAT_SIGNS |
16411
5b5c5daf57de
patch 8.1.1210: support for user commands is spread out
Bram Moolenaar <Bram@vim.org>
parents:
16261
diff
changeset
|
998 buf_delete_signs(buf, (char_u *)"*"); // delete any signs |
7 | 999 #endif |
1781 | 1000 #ifdef FEAT_NETBEANS_INTG |
2210 | 1001 netbeans_file_killed(buf); |
1781 | 1002 #endif |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1003 map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1004 map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
1005 VIM_CLEAR(buf->b_start_fenc); |
7 | 1006 } |
1007 | |
1008 /* | |
1009 * Free the b_wininfo list for buffer "buf". | |
1010 */ | |
1011 static void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1012 clear_wininfo(buf_T *buf) |
7 | 1013 { |
1014 wininfo_T *wip; | |
1015 | |
1016 while (buf->b_wininfo != NULL) | |
1017 { | |
1018 wip = buf->b_wininfo; | |
1019 buf->b_wininfo = wip->wi_next; | |
1020 if (wip->wi_optset) | |
1021 { | |
1022 clear_winopt(&wip->wi_opt); | |
1023 #ifdef FEAT_FOLDING | |
1024 deleteFoldRecurse(&wip->wi_folds); | |
1025 #endif | |
1026 } | |
1027 vim_free(wip); | |
1028 } | |
1029 } | |
1030 | |
1031 /* | |
1032 * Go to another buffer. Handles the result of the ATTENTION dialog. | |
1033 */ | |
1034 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1035 goto_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1036 exarg_T *eap, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1037 int start, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1038 int dir, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1039 int count) |
7 | 1040 { |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1041 bufref_T old_curbuf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1042 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1043 set_bufref(&old_curbuf, curbuf); |
7 | 1044 |
1045 swap_exists_action = SEA_DIALOG; | |
1046 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | |
1047 start, dir, count, eap->forceit); | |
1048 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') | |
1049 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1050 #if defined(FEAT_EVAL) |
24 | 1051 cleanup_T cs; |
1052 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1053 // Reset the error/interrupt/exception state here so that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1054 // aborting() returns FALSE when closing a window. |
24 | 1055 enter_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1056 #endif |
24 | 1057 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1058 // Quitting means closing the split window, nothing else. |
7 | 1059 win_close(curwin, TRUE); |
1060 swap_exists_action = SEA_NONE; | |
602 | 1061 swap_exists_did_quit = TRUE; |
24 | 1062 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1063 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1064 // Restore the error/interrupt/exception state if not discarded by a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1065 // new aborting error, interrupt, or uncaught exception. |
24 | 1066 leave_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1067 #endif |
7 | 1068 } |
1069 else | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1070 handle_swap_exists(&old_curbuf); |
7 | 1071 } |
1072 | |
1073 /* | |
1074 * Handle the situation of swap_exists_action being set. | |
1075 * It is allowed for "old_curbuf" to be NULL or invalid. | |
1076 */ | |
1077 void | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1078 handle_swap_exists(bufref_T *old_curbuf) |
7 | 1079 { |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1080 #if defined(FEAT_EVAL) |
24 | 1081 cleanup_T cs; |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1082 #endif |
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1083 #ifdef FEAT_SYN_HL |
4139 | 1084 long old_tw = curbuf->b_p_tw; |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1085 #endif |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1086 buf_T *buf; |
20 | 1087 |
7 | 1088 if (swap_exists_action == SEA_QUIT) |
1089 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1090 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1091 // Reset the error/interrupt/exception state here so that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1092 // aborting() returns FALSE when closing a buffer. |
24 | 1093 enter_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1094 #endif |
24 | 1095 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1096 // User selected Quit at ATTENTION prompt. Go back to previous |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1097 // buffer. If that buffer is gone or the same as the current one, |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1098 // open a new, empty buffer. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1099 swap_exists_action = SEA_NONE; // don't want it again |
602 | 1100 swap_exists_did_quit = TRUE; |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
1101 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE, FALSE); |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1102 if (old_curbuf == NULL || !bufref_valid(old_curbuf) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1103 || old_curbuf->br_buf == curbuf) |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1104 buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED); |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1105 else |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1106 buf = old_curbuf->br_buf; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1107 if (buf != NULL) |
4139 | 1108 { |
14593
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1109 int old_msg_silent = msg_silent; |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1110 |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1111 if (shortmess(SHM_FILEINFO)) |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1112 msg_silent = 1; // prevent fileinfo message |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9485
diff
changeset
|
1113 enter_buffer(buf); |
14593
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1114 // restore msg_silent, so that the command line will be shown |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1115 msg_silent = old_msg_silent; |
b6b2f7d69c7f
patch 8.1.0310: file info msg not always suppressed with 'F' in 'shortmess'
Christian Brabandt <cb@256bit.org>
parents:
14585
diff
changeset
|
1116 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1117 #ifdef FEAT_SYN_HL |
4139 | 1118 if (old_tw != curbuf->b_p_tw) |
1119 check_colorcolumn(curwin); | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1120 #endif |
4139 | 1121 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1122 // If "old_curbuf" is NULL we are in big trouble here... |
24 | 1123 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1124 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1125 // Restore the error/interrupt/exception state if not discarded by a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1126 // new aborting error, interrupt, or uncaught exception. |
24 | 1127 leave_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1128 #endif |
7 | 1129 } |
1130 else if (swap_exists_action == SEA_RECOVER) | |
1131 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1132 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1133 // Reset the error/interrupt/exception state here so that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1134 // aborting() returns FALSE when closing a buffer. |
24 | 1135 enter_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1136 #endif |
24 | 1137 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1138 // User selected Recover at ATTENTION prompt. |
7 | 1139 msg_scroll = TRUE; |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16664
diff
changeset
|
1140 ml_recover(FALSE); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1141 msg_puts("\n"); // don't overwrite the last message |
7 | 1142 cmdline_row = msg_row; |
717 | 1143 do_modelines(0); |
24 | 1144 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1145 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1146 // Restore the error/interrupt/exception state if not discarded by a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1147 // new aborting error, interrupt, or uncaught exception. |
24 | 1148 leave_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
1149 #endif |
7 | 1150 } |
1151 swap_exists_action = SEA_NONE; | |
1152 } | |
1153 | |
1154 /* | |
1155 * do_bufdel() - delete or unload buffer(s) | |
1156 * | |
1157 * addr_count == 0: ":bdel" - delete current buffer | |
1158 * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete | |
1159 * buffer "end_bnr", then any other arguments. | |
1160 * addr_count == 2: ":N,N bdel" - delete buffers in range | |
1161 * | |
1162 * command can be DOBUF_UNLOAD (":bunload"), DOBUF_WIPE (":bwipeout") or | |
1163 * DOBUF_DEL (":bdel") | |
1164 * | |
1165 * Returns error message or NULL | |
1166 */ | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1167 char * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1168 do_bufdel( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1169 int command, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1170 char_u *arg, // pointer to extra arguments |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1171 int addr_count, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1172 int start_bnr, // first buffer number in a range |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1173 int end_bnr, // buffer nr or last buffer nr in a range |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1174 int forceit) |
7 | 1175 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1176 int do_current = 0; // delete current buffer? |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1177 int deleted = 0; // number of buffers deleted |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1178 char *errormsg = NULL; // return value |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1179 int bnr; // buffer number |
7 | 1180 char_u *p; |
1181 | |
1182 if (addr_count == 0) | |
1183 { | |
1184 (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); | |
1185 } | |
1186 else | |
1187 { | |
1188 if (addr_count == 2) | |
1189 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1190 if (*arg) // both range and argument is not allowed |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1191 return _(e_trailing); |
7 | 1192 bnr = start_bnr; |
1193 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1194 else // addr_count == 1 |
7 | 1195 bnr = end_bnr; |
1196 | |
1197 for ( ;!got_int; ui_breakcheck()) | |
1198 { | |
1199 /* | |
1200 * delete the current buffer last, otherwise when the | |
1201 * current buffer is deleted, the next buffer becomes | |
1202 * the current one and will be loaded, which may then | |
1203 * also be deleted, etc. | |
1204 */ | |
1205 if (bnr == curbuf->b_fnum) | |
1206 do_current = bnr; | |
1207 else if (do_buffer(command, DOBUF_FIRST, FORWARD, (int)bnr, | |
1208 forceit) == OK) | |
1209 ++deleted; | |
1210 | |
1211 /* | |
1212 * find next buffer number to delete/unload | |
1213 */ | |
1214 if (addr_count == 2) | |
1215 { | |
1216 if (++bnr > end_bnr) | |
1217 break; | |
1218 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1219 else // addr_count == 1 |
7 | 1220 { |
1221 arg = skipwhite(arg); | |
1222 if (*arg == NUL) | |
1223 break; | |
1224 if (!VIM_ISDIGIT(*arg)) | |
1225 { | |
1226 p = skiptowhite_esc(arg); | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1227 bnr = buflist_findpat(arg, p, |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1228 command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE, |
4236 | 1229 FALSE, FALSE); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1230 if (bnr < 0) // failed |
7 | 1231 break; |
1232 arg = p; | |
1233 } | |
1234 else | |
1235 bnr = getdigits(&arg); | |
1236 } | |
1237 } | |
1238 if (!got_int && do_current && do_buffer(command, DOBUF_FIRST, | |
1239 FORWARD, do_current, forceit) == OK) | |
1240 ++deleted; | |
1241 | |
1242 if (deleted == 0) | |
1243 { | |
1244 if (command == DOBUF_UNLOAD) | |
300 | 1245 STRCPY(IObuff, _("E515: No buffers were unloaded")); |
7 | 1246 else if (command == DOBUF_DEL) |
300 | 1247 STRCPY(IObuff, _("E516: No buffers were deleted")); |
7 | 1248 else |
300 | 1249 STRCPY(IObuff, _("E517: No buffers were wiped out")); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1250 errormsg = (char *)IObuff; |
7 | 1251 } |
1252 else if (deleted >= p_report) | |
1253 { | |
1254 if (command == DOBUF_UNLOAD) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1255 smsg(NGETTEXT("%d buffer unloaded", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
1256 "%d buffers unloaded", deleted), deleted); |
7 | 1257 else if (command == DOBUF_DEL) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1258 smsg(NGETTEXT("%d buffer deleted", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
1259 "%d buffers deleted", deleted), deleted); |
7 | 1260 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1261 smsg(NGETTEXT("%d buffer wiped out", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
1262 "%d buffers wiped out", deleted), deleted); |
7 | 1263 } |
1264 } | |
1265 | |
1266 | |
1267 return errormsg; | |
1268 } | |
1269 | |
5586 | 1270 /* |
1271 * Make the current buffer empty. | |
1272 * Used when it is wiped out and it's the last buffer. | |
1273 */ | |
1274 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1275 empty_curbuf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1276 int close_others, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1277 int forceit, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1278 int action) |
5586 | 1279 { |
1280 int retval; | |
1281 buf_T *buf = curbuf; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1282 bufref_T bufref; |
5586 | 1283 |
1284 if (action == DOBUF_UNLOAD) | |
1285 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1286 emsg(_("E90: Cannot unload last buffer")); |
5586 | 1287 return FAIL; |
1288 } | |
1289 | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1290 set_bufref(&bufref, buf); |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1291 if (close_others) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1292 // Close any other windows on this buffer, then make it empty. |
5586 | 1293 close_windows(buf, TRUE); |
1294 | |
1295 setpcmark(); | |
1296 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, | |
1297 forceit ? ECMD_FORCEIT : 0, curwin); | |
1298 | |
1299 /* | |
1300 * do_ecmd() may create a new buffer, then we have to delete | |
1301 * the old one. But do_ecmd() may have done that already, check | |
1302 * if the buffer still exists. | |
1303 */ | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1304 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows == 0) |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
1305 close_buffer(NULL, buf, action, FALSE, FALSE); |
5586 | 1306 if (!close_others) |
1307 need_fileinfo = FALSE; | |
1308 return retval; | |
1309 } | |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
1310 |
7 | 1311 /* |
1312 * Implementation of the commands for the buffer list. | |
1313 * | |
1314 * action == DOBUF_GOTO go to specified buffer | |
1315 * action == DOBUF_SPLIT split window and go to specified buffer | |
1316 * action == DOBUF_UNLOAD unload specified buffer(s) | |
1317 * action == DOBUF_DEL delete specified buffer(s) from buffer list | |
1318 * action == DOBUF_WIPE delete specified buffer(s) really | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1319 * action == DOBUF_WIPE_REUSE idem, and add number to "buf_reuse" |
7 | 1320 * |
1321 * start == DOBUF_CURRENT go to "count" buffer from current buffer | |
1322 * start == DOBUF_FIRST go to "count" buffer from first buffer | |
1323 * start == DOBUF_LAST go to "count" buffer from last buffer | |
1324 * start == DOBUF_MOD go to "count" modified buffer from current buffer | |
1325 * | |
1326 * Return FAIL or OK. | |
1327 */ | |
1328 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1329 do_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1330 int action, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1331 int start, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1332 int dir, // FORWARD or BACKWARD |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1333 int count, // buffer number or number of buffers |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1334 int forceit) // TRUE for :...! |
7 | 1335 { |
1336 buf_T *buf; | |
1337 buf_T *bp; | |
1338 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1339 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); |
7 | 1340 |
1341 switch (start) | |
1342 { | |
1343 case DOBUF_FIRST: buf = firstbuf; break; | |
1344 case DOBUF_LAST: buf = lastbuf; break; | |
1345 default: buf = curbuf; break; | |
1346 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1347 if (start == DOBUF_MOD) // find next modified buffer |
7 | 1348 { |
1349 while (count-- > 0) | |
1350 { | |
1351 do | |
1352 { | |
1353 buf = buf->b_next; | |
1354 if (buf == NULL) | |
1355 buf = firstbuf; | |
1356 } | |
1357 while (buf != curbuf && !bufIsChanged(buf)); | |
1358 } | |
1359 if (!bufIsChanged(buf)) | |
1360 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1361 emsg(_("E84: No modified buffer found")); |
7 | 1362 return FAIL; |
1363 } | |
1364 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1365 else if (start == DOBUF_FIRST && count) // find specified buffer number |
7 | 1366 { |
1367 while (buf != NULL && buf->b_fnum != count) | |
1368 buf = buf->b_next; | |
1369 } | |
1370 else | |
1371 { | |
1372 bp = NULL; | |
1373 while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) | |
1374 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1375 // remember the buffer where we start, we come back there when all |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1376 // buffers are unlisted. |
7 | 1377 if (bp == NULL) |
1378 bp = buf; | |
1379 if (dir == FORWARD) | |
1380 { | |
1381 buf = buf->b_next; | |
1382 if (buf == NULL) | |
1383 buf = firstbuf; | |
1384 } | |
1385 else | |
1386 { | |
1387 buf = buf->b_prev; | |
1388 if (buf == NULL) | |
1389 buf = lastbuf; | |
1390 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1391 // don't count unlisted buffers |
7 | 1392 if (unload || buf->b_p_bl) |
1393 { | |
1394 --count; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1395 bp = NULL; // use this buffer as new starting point |
7 | 1396 } |
1397 if (bp == buf) | |
1398 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1399 // back where we started, didn't find anything. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1400 emsg(_("E85: There is no listed buffer")); |
7 | 1401 return FAIL; |
1402 } | |
1403 } | |
1404 } | |
1405 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1406 if (buf == NULL) // could not find it |
7 | 1407 { |
1408 if (start == DOBUF_FIRST) | |
1409 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1410 // don't warn when deleting |
7 | 1411 if (!unload) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1412 semsg(_(e_nobufnr), count); |
7 | 1413 } |
1414 else if (dir == FORWARD) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1415 emsg(_("E87: Cannot go beyond last buffer")); |
7 | 1416 else |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1417 emsg(_("E88: Cannot go before first buffer")); |
7 | 1418 return FAIL; |
1419 } | |
1420 | |
1421 #ifdef FEAT_GUI | |
1422 need_mouse_correct = TRUE; | |
1423 #endif | |
1424 | |
1425 /* | |
1426 * delete buffer buf from memory and/or the list | |
1427 */ | |
1428 if (unload) | |
1429 { | |
1430 int forward; | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1431 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1432 |
14658
9ffd7d0650c6
patch 8.1.0342: crash when a callback deletes a window that is being used
Christian Brabandt <cb@256bit.org>
parents:
14593
diff
changeset
|
1433 if (!can_unload_buffer(buf)) |
13720
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
1434 return FAIL; |
7d2039b2ecc8
patch 8.0.1732: crash when terminal API call deletes the buffer
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
1435 |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1436 set_bufref(&bufref, buf); |
7 | 1437 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1438 // When unloading or deleting a buffer that's already unloaded and |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1439 // unlisted: fail silently. |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1440 if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1441 && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) |
7 | 1442 return FAIL; |
1443 | |
1444 if (!forceit && bufIsChanged(buf)) | |
1445 { | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13535
diff
changeset
|
1446 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
7 | 1447 if ((p_confirm || cmdmod.confirm) && p_write) |
1448 { | |
1449 dialog_changed(buf, FALSE); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1450 if (!bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1451 // Autocommand deleted buffer, oops! It's not changed |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1452 // now. |
7 | 1453 return FAIL; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1454 // If it's still changed fail silently, the dialog already |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1455 // mentioned why it fails. |
36 | 1456 if (bufIsChanged(buf)) |
1457 return FAIL; | |
7 | 1458 } |
36 | 1459 else |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13535
diff
changeset
|
1460 #endif |
7 | 1461 { |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
1462 semsg(_("E89: No write since last change for buffer %d (add ! to override)"), |
7 | 1463 buf->b_fnum); |
1464 return FAIL; | |
1465 } | |
1466 } | |
1467 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1468 // When closing the current buffer stop Visual mode. |
10184
4669440016f2
commit https://github.com/vim/vim/commit/4930a76a0357f76a829eafe4985d04cf3ce0e9e0
Christian Brabandt <cb@256bit.org>
parents:
10156
diff
changeset
|
1469 if (buf == curbuf && VIsual_active) |
10154
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
1470 end_visual_mode(); |
4647267906cc
commit https://github.com/vim/vim/commit/c4a908e83690844b0d3a46124ba6af7d23485d69
Christian Brabandt <cb@256bit.org>
parents:
10118
diff
changeset
|
1471 |
7 | 1472 /* |
1473 * If deleting the last (listed) buffer, make it empty. | |
1474 * The last (listed) buffer cannot be unloaded. | |
1475 */ | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
1476 FOR_ALL_BUFFERS(bp) |
7 | 1477 if (bp->b_p_bl && bp != buf) |
1478 break; | |
1479 if (bp == NULL && buf == curbuf) | |
5586 | 1480 return empty_curbuf(TRUE, forceit, action); |
7 | 1481 |
1482 /* | |
1483 * If the deleted buffer is the current one, close the current window | |
671 | 1484 * (unless it's the only window). Repeat this so long as we end up in |
1485 * a window with this buffer. | |
7 | 1486 */ |
671 | 1487 while (buf == curbuf |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
1488 && !(curwin->w_closing || curwin->w_buffer->b_locked > 0) |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
1489 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) |
5302 | 1490 { |
1491 if (win_close(curwin, FALSE) == FAIL) | |
1492 break; | |
1493 } | |
7 | 1494 |
1495 /* | |
1496 * If the buffer to be deleted is not the current one, delete it here. | |
1497 */ | |
1498 if (buf != curbuf) | |
1499 { | |
671 | 1500 close_windows(buf, FALSE); |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
1501 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows <= 0) |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
1502 close_buffer(NULL, buf, action, FALSE, FALSE); |
7 | 1503 return OK; |
1504 } | |
1505 | |
1506 /* | |
1507 * Deleting the current buffer: Need to find another buffer to go to. | |
5586 | 1508 * There should be another, otherwise it would have been handled |
1509 * above. However, autocommands may have deleted all buffers. | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1510 * First use au_new_curbuf.br_buf, if it is valid. |
7 | 1511 * Then prefer the buffer we most recently visited. |
1512 * Else try to find one that is loaded, after the current buffer, | |
1513 * then before the current buffer. | |
1514 * Finally use any buffer. | |
1515 */ | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1516 buf = NULL; // selected buffer |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1517 bp = NULL; // used when no loaded buffer found |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1518 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9479
diff
changeset
|
1519 buf = au_new_curbuf.br_buf; |
7 | 1520 #ifdef FEAT_JUMPLIST |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1521 else if (curwin->w_jumplistlen > 0) |
7 | 1522 { |
1523 int jumpidx; | |
1524 | |
1525 jumpidx = curwin->w_jumplistidx - 1; | |
1526 if (jumpidx < 0) | |
1527 jumpidx = curwin->w_jumplistlen - 1; | |
1528 | |
1529 forward = jumpidx; | |
1530 while (jumpidx != curwin->w_jumplistidx) | |
1531 { | |
1532 buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum); | |
1533 if (buf != NULL) | |
1534 { | |
1535 if (buf == curbuf || !buf->b_p_bl) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1536 buf = NULL; // skip current and unlisted bufs |
7 | 1537 else if (buf->b_ml.ml_mfp == NULL) |
1538 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1539 // skip unloaded buf, but may keep it for later |
7 | 1540 if (bp == NULL) |
1541 bp = buf; | |
1542 buf = NULL; | |
1543 } | |
1544 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1545 if (buf != NULL) // found a valid buffer: stop searching |
7 | 1546 break; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1547 // advance to older entry in jump list |
7 | 1548 if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) |
1549 break; | |
1550 if (--jumpidx < 0) | |
1551 jumpidx = curwin->w_jumplistlen - 1; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1552 if (jumpidx == forward) // List exhausted for sure |
7 | 1553 break; |
1554 } | |
1555 } | |
1556 #endif | |
1557 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1558 if (buf == NULL) // No previous buffer, Try 2'nd approach |
7 | 1559 { |
1560 forward = TRUE; | |
1561 buf = curbuf->b_next; | |
1562 for (;;) | |
1563 { | |
1564 if (buf == NULL) | |
1565 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1566 if (!forward) // tried both directions |
7 | 1567 break; |
1568 buf = curbuf->b_prev; | |
1569 forward = FALSE; | |
1570 continue; | |
1571 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1572 // in non-help buffer, try to skip help buffers, and vv |
7 | 1573 if (buf->b_help == curbuf->b_help && buf->b_p_bl) |
1574 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1575 if (buf->b_ml.ml_mfp != NULL) // found loaded buffer |
7 | 1576 break; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1577 if (bp == NULL) // remember unloaded buf for later |
7 | 1578 bp = buf; |
1579 } | |
1580 if (forward) | |
1581 buf = buf->b_next; | |
1582 else | |
1583 buf = buf->b_prev; | |
1584 } | |
1585 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1586 if (buf == NULL) // No loaded buffer, use unloaded one |
7 | 1587 buf = bp; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1588 if (buf == NULL) // No loaded buffer, find listed one |
7 | 1589 { |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
1590 FOR_ALL_BUFFERS(buf) |
7 | 1591 if (buf->b_p_bl && buf != curbuf) |
1592 break; | |
1593 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1594 if (buf == NULL) // Still no buffer, just take one |
7 | 1595 { |
1596 if (curbuf->b_next != NULL) | |
1597 buf = curbuf->b_next; | |
1598 else | |
1599 buf = curbuf->b_prev; | |
1600 } | |
1601 } | |
1602 | |
5586 | 1603 if (buf == NULL) |
1604 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1605 // Autocommands must have wiped out all other buffers. Only option |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1606 // now is to make the current buffer empty. |
5586 | 1607 return empty_curbuf(FALSE, forceit, action); |
1608 } | |
1609 | |
7 | 1610 /* |
1611 * make buf current buffer | |
1612 */ | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1613 if (action == DOBUF_SPLIT) // split window first |
7 | 1614 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1615 // If 'switchbuf' contains "useopen": jump to first window containing |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1616 // "buf" if one exists |
1618 | 1617 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) |
825 | 1618 return OK; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1619 // If 'switchbuf' contains "usetab": jump to first window in any tab |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1620 // page containing "buf" if one exists |
1618 | 1621 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) |
7 | 1622 return OK; |
1623 if (win_split(0, 0) == FAIL) | |
1624 return FAIL; | |
1625 } | |
1626 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1627 // go to current buffer - nothing to do |
7 | 1628 if (buf == curbuf) |
1629 return OK; | |
1630 | |
1631 /* | |
1632 * Check if the current buffer may be abandoned. | |
1633 */ | |
1634 if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) | |
1635 { | |
1636 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
1637 if ((p_confirm || cmdmod.confirm) && p_write) | |
1638 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1639 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1640 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1641 set_bufref(&bufref, buf); |
7 | 1642 dialog_changed(curbuf, FALSE); |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1643 if (!bufref_valid(&bufref)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1644 // Autocommand deleted buffer, oops! |
7 | 1645 return FAIL; |
1646 } | |
1647 if (bufIsChanged(curbuf)) | |
1648 #endif | |
1649 { | |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1650 no_write_message(); |
7 | 1651 return FAIL; |
1652 } | |
1653 } | |
1654 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1655 // Go to the other buffer. |
7 | 1656 set_curbuf(buf, action); |
1657 | |
1658 if (action == DOBUF_SPLIT) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1659 RESET_BINDING(curwin); // reset 'scrollbind' and 'cursorbind' |
7 | 1660 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1661 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1662 if (aborting()) // autocmds may abort script processing |
7 | 1663 return FAIL; |
1664 #endif | |
1665 | |
1666 return OK; | |
1667 } | |
1668 | |
1669 /* | |
1670 * Set current buffer to "buf". Executes autocommands and closes current | |
1671 * buffer. "action" tells how to close the current buffer: | |
1672 * DOBUF_GOTO free or hide it | |
1673 * DOBUF_SPLIT nothing | |
1674 * DOBUF_UNLOAD unload it | |
1675 * DOBUF_DEL delete it | |
1676 * DOBUF_WIPE wipe it out | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1677 * DOBUF_WIPE_REUSE wipe it out and add to "buf_reuse" |
7 | 1678 */ |
1679 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1680 set_curbuf(buf_T *buf, int action) |
7 | 1681 { |
1682 buf_T *prevbuf; | |
1683 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1684 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); |
4139 | 1685 #ifdef FEAT_SYN_HL |
1686 long old_tw = curbuf->b_p_tw; | |
1687 #endif | |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1688 bufref_T newbufref; |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1689 bufref_T prevbufref; |
7 | 1690 |
1691 setpcmark(); | |
22 | 1692 if (!cmdmod.keepalt) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1693 curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1694 buflist_altfpos(curwin); // remember curpos |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1695 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1696 // Don't restart Select mode after switching to another buffer. |
7 | 1697 VIsual_reselect = FALSE; |
1698 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1699 // close_windows() or apply_autocmds() may change curbuf and wipe out "buf" |
7 | 1700 prevbuf = curbuf; |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1701 set_bufref(&prevbufref, prevbuf); |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1702 set_bufref(&newbufref, buf); |
7 | 1703 |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1704 // Autocommands may delete the current buffer and/or the buffer we want to go |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1705 // to. In those cases don't close the buffer. |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1706 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1707 || (bufref_valid(&prevbufref) |
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1708 && bufref_valid(&newbufref) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1709 #ifdef FEAT_EVAL |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1710 && !aborting() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1711 #endif |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1712 )) |
7 | 1713 { |
3068 | 1714 #ifdef FEAT_SYN_HL |
1715 if (prevbuf == curwin->w_buffer) | |
1716 reset_synblock(curwin); | |
1717 #endif | |
7 | 1718 if (unload) |
671 | 1719 close_windows(prevbuf, FALSE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1720 #if defined(FEAT_EVAL) |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1721 if (bufref_valid(&prevbufref) && !aborting()) |
7 | 1722 #else |
13054
197a08152ad5
patch 8.0.1402: crash with nasty autocommand
Christian Brabandt <cb@256bit.org>
parents:
12971
diff
changeset
|
1723 if (bufref_valid(&prevbufref)) |
7 | 1724 #endif |
815 | 1725 { |
3654 | 1726 win_T *previouswin = curwin; |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1727 |
815 | 1728 if (prevbuf == curbuf) |
825 | 1729 u_sync(FALSE); |
7 | 1730 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, |
1731 unload ? action : (action == DOBUF_GOTO | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11917
diff
changeset
|
1732 && !buf_hide(prevbuf) |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
1733 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, |
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
1734 FALSE, FALSE); |
3654 | 1735 if (curwin != previouswin && win_valid(previouswin)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1736 // autocommands changed curwin, Grr! |
3654 | 1737 curwin = previouswin; |
815 | 1738 } |
7 | 1739 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1740 // An autocommand may have deleted "buf", already entered it (e.g., when |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1741 // it did ":bunload") or aborted the script processing. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1742 // If curwin->w_buffer is null, enter_buffer() will make it valid again |
3594 | 1743 if ((buf_valid(buf) && buf != curbuf |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1744 #ifdef FEAT_EVAL |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
1745 && !aborting() |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1746 #endif |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
1747 ) || curwin->w_buffer == NULL) |
4139 | 1748 { |
7 | 1749 enter_buffer(buf); |
4139 | 1750 #ifdef FEAT_SYN_HL |
1751 if (old_tw != curbuf->b_p_tw) | |
1752 check_colorcolumn(curwin); | |
1753 #endif | |
1754 } | |
7 | 1755 } |
1756 | |
1757 /* | |
1758 * Enter a new current buffer. | |
4139 | 1759 * Old curbuf must have been abandoned already! This also means "curbuf" may |
1760 * be pointing to freed memory. | |
7 | 1761 */ |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
1762 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1763 enter_buffer(buf_T *buf) |
7 | 1764 { |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1765 // Get the buffer in the current window. |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1766 curwin->w_buffer = buf; |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1767 curbuf = buf; |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1768 ++curbuf->b_nwindows; |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1769 |
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1770 // Copy buffer and window local option values. Not for a help buffer. |
7 | 1771 buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); |
1772 if (!buf->b_help) | |
1773 get_winopts(buf); | |
1774 #ifdef FEAT_FOLDING | |
1775 else | |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1776 // Remove all folds in the window. |
7 | 1777 clearFolding(curwin); |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
1778 foldUpdateAll(curwin); // update folds (later). |
7 | 1779 #endif |
1780 | |
1781 #ifdef FEAT_DIFF | |
672 | 1782 if (curwin->w_p_diff) |
1783 diff_buf_add(curbuf); | |
7 | 1784 #endif |
1785 | |
3068 | 1786 #ifdef FEAT_SYN_HL |
11690
ce434212d682
patch 8.0.0728: the terminal structure is never freed
Christian Brabandt <cb@256bit.org>
parents:
11531
diff
changeset
|
1787 curwin->w_s = &(curbuf->b_s); |
3068 | 1788 #endif |
1789 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1790 // Cursor on first line by default. |
7 | 1791 curwin->w_cursor.lnum = 1; |
1792 curwin->w_cursor.col = 0; | |
1793 curwin->w_cursor.coladd = 0; | |
1794 curwin->w_set_curswant = TRUE; | |
1744 | 1795 curwin->w_topline_was_set = FALSE; |
7 | 1796 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1797 // mark cursor position as being invalid |
2091
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1798 curwin->w_valid = 0; |
95b659982b7c
updated for version 7.2.375
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1799 |
14826
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
1800 buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum, |
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
1801 curbuf->b_last_cursor.col, TRUE); |
75d474a8868a
patch 8.1.0425: ml_get error and crash with appendbufline()
Christian Brabandt <cb@256bit.org>
parents:
14744
diff
changeset
|
1802 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1803 // Make sure the buffer is loaded. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1804 if (curbuf->b_ml.ml_mfp == NULL) // need to load the file |
22 | 1805 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1806 // If there is no filetype, allow for detecting one. Esp. useful for |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1807 // ":ball" used in a autocommand. If there already is a filetype we |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1808 // might prefer to keep it. |
22 | 1809 if (*curbuf->b_p_ft == NUL) |
1810 did_filetype = FALSE; | |
1811 | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
1812 open_buffer(FALSE, NULL, 0); |
22 | 1813 } |
7 | 1814 else |
1815 { | |
16664
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1816 if (!msg_silent && !shortmess(SHM_FILEINFO)) |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1817 need_fileinfo = TRUE; // display file info after redraw |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1818 |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1819 // check if file changed |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1820 (void)buf_check_timestamp(curbuf, FALSE); |
ca1814eeecf5
patch 8.1.1334: when buffer is hidden "F" in 'shortmess' is not used
Bram Moolenaar <Bram@vim.org>
parents:
16453
diff
changeset
|
1821 |
7 | 1822 curwin->w_topline = 1; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1823 #ifdef FEAT_DIFF |
7 | 1824 curwin->w_topfill = 0; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1825 #endif |
7 | 1826 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
1827 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | |
1828 } | |
1829 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1830 // If autocommands did not change the cursor position, restore cursor lnum |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1831 // and possibly cursor col. |
7 | 1832 if (curwin->w_cursor.lnum == 1 && inindent(0)) |
1833 buflist_getfpos(); | |
1834 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1835 check_arg_idx(curwin); // check for valid arg_idx |
7 | 1836 #ifdef FEAT_TITLE |
1837 maketitle(); | |
1838 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1839 // when autocmds didn't change it |
1744 | 1840 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1841 scroll_cursor_halfway(FALSE); // redisplay at correct position |
7 | 1842 |
33 | 1843 #ifdef FEAT_NETBEANS_INTG |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1844 // Send fileOpened event because we've changed buffers. |
2210 | 1845 netbeans_file_activated(curbuf); |
33 | 1846 #endif |
1847 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1848 // Change directories when the 'acd' option is set. |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13555
diff
changeset
|
1849 DO_AUTOCHDIR; |
7 | 1850 |
1851 #ifdef FEAT_KEYMAP | |
1852 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 1853 (void)keymap_init(); |
7 | 1854 #endif |
1185 | 1855 #ifdef FEAT_SPELL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1856 // May need to set the spell language. Can only do this after the buffer |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1857 // has been properly setup. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1858 if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
1859 (void)did_set_spelllang(curwin); |
1185 | 1860 #endif |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1861 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1862 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1863 #endif |
1185 | 1864 |
7 | 1865 redraw_later(NOT_VALID); |
1866 } | |
1867 | |
961 | 1868 #if defined(FEAT_AUTOCHDIR) || defined(PROTO) |
1869 /* | |
1870 * Change to the directory of the current buffer. | |
8216
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1871 * Don't do this while still starting up. |
961 | 1872 */ |
1873 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1874 do_autochdir(void) |
961 | 1875 { |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9450
diff
changeset
|
1876 if ((starting == 0 || test_autochdir) |
8216
03af9acbefb0
commit https://github.com/vim/vim/commit/6bd364e08461159ad3c153ffba4def5b896486a1
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
1877 && curbuf->b_ffname != NULL |
13170
6559e98f3e74
patch 8.0.1459: cannot handle change of directory
Christian Brabandt <cb@256bit.org>
parents:
13121
diff
changeset
|
1878 && vim_chdirfile(curbuf->b_ffname, "auto") == OK) |
961 | 1879 shorten_fnames(TRUE); |
1880 } | |
1881 #endif | |
1882 | |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1883 void |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1884 no_write_message(void) |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1885 { |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1886 #ifdef FEAT_TERMINAL |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1887 if (term_job_running(curbuf->b_term)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1888 emsg(_("E948: Job still running (add ! to end the job)")); |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1889 else |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1890 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1891 emsg(_("E37: No write since last change (add ! to override)")); |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1892 } |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1893 |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1894 void |
13302
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1895 no_write_message_nobang(buf_T *buf UNUSED) |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1896 { |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1897 #ifdef FEAT_TERMINAL |
13302
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1898 if (term_job_running(buf->b_term)) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1899 emsg(_("E948: Job still running")); |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1900 else |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1901 #endif |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
1902 emsg(_("E37: No write since last change")); |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1903 } |
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
12110
diff
changeset
|
1904 |
7 | 1905 /* |
1906 * functions for dealing with the buffer list | |
1907 */ | |
1908 | |
1909 /* | |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1910 * Return TRUE if the current buffer is empty, unnamed, unmodified and used in |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1911 * only one window. That means it can be re-used. |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1912 */ |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1913 int |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1914 curbuf_reusable(void) |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1915 { |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1916 return (curbuf != NULL |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1917 && curbuf->b_ffname == NULL |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1918 && curbuf->b_nwindows <= 1 |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1919 && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY()) |
16261
2001ef982570
patch 8.1.1135: build failure for small version
Bram Moolenaar <Bram@vim.org>
parents:
16259
diff
changeset
|
1920 #if defined(FEAT_QUICKFIX) |
16259
1f18984498e1
patch 8.1.1134: buffer for quickfix window is reused for another file
Bram Moolenaar <Bram@vim.org>
parents:
16223
diff
changeset
|
1921 && !bt_quickfix(curbuf) |
16261
2001ef982570
patch 8.1.1135: build failure for small version
Bram Moolenaar <Bram@vim.org>
parents:
16259
diff
changeset
|
1922 #endif |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1923 && !curbufIsChanged()); |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1924 } |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1925 |
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
1926 /* |
7 | 1927 * Add a file name to the buffer list. Return a pointer to the buffer. |
1928 * If the same file name already exists return a pointer to that buffer. | |
1929 * If it does not exist, or if fname == NULL, a new entry is created. | |
1930 * If (flags & BLN_CURBUF) is TRUE, may use current buffer. | |
1931 * If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list. | |
1932 * If (flags & BLN_DUMMY) is TRUE, don't count it as a real buffer. | |
9149
18bbf31015c2
commit https://github.com/vim/vim/commit/b127cfd75f59e82580df395b6e2c009774644b16
Christian Brabandt <cb@256bit.org>
parents:
9106
diff
changeset
|
1933 * If (flags & BLN_NEW) is TRUE, don't use an existing buffer. |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1934 * If (flags & BLN_NOOPT) is TRUE, don't copy options from the current buffer |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1935 * if the buffer already exists. |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
1936 * If (flags & BLN_REUSE) is TRUE, may use buffer number from "buf_reuse". |
7 | 1937 * This is the ONLY way to create a new buffer. |
1938 */ | |
1939 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1940 buflist_new( |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1941 char_u *ffname_arg, // full path of fname or relative |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1942 char_u *sfname_arg, // short fname or NULL |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1943 linenr_T lnum, // preferred cursor line |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1944 int flags) // BLN_ defines |
7 | 1945 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1946 char_u *ffname = ffname_arg; |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1947 char_u *sfname = sfname_arg; |
7 | 1948 buf_T *buf; |
1949 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
1950 stat_T st; |
7 | 1951 #endif |
1952 | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1953 if (top_file_num == 1) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1954 hash_init(&buf_hashtab); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1955 |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
1956 fname_expand(curbuf, &ffname, &sfname); // will allocate ffname |
7 | 1957 |
1958 /* | |
1959 * If file name already exists in the list, update the entry. | |
1960 */ | |
1961 #ifdef UNIX | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1962 // On Unix we can use inode numbers when the file exists. Works better |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1963 // for hard links. |
7 | 1964 if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) |
1965 st.st_dev = (dev_T)-1; | |
1966 #endif | |
9149
18bbf31015c2
commit https://github.com/vim/vim/commit/b127cfd75f59e82580df395b6e2c009774644b16
Christian Brabandt <cb@256bit.org>
parents:
9106
diff
changeset
|
1967 if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) && (buf = |
7 | 1968 #ifdef UNIX |
1969 buflist_findname_stat(ffname, &st) | |
1970 #else | |
1971 buflist_findname(ffname) | |
1972 #endif | |
1973 ) != NULL) | |
1974 { | |
1975 vim_free(ffname); | |
1976 if (lnum != 0) | |
1977 buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); | |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1978 |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1979 if ((flags & BLN_NOOPT) == 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1980 // copy the options now, if 'cpo' doesn't have 's' and not done |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
1981 // already |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1982 buf_copy_options(buf, 0); |
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1983 |
7 | 1984 if ((flags & BLN_LISTED) && !buf->b_p_bl) |
1985 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1986 bufref_T bufref; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
1987 |
7 | 1988 buf->b_p_bl = TRUE; |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1989 set_bufref(&bufref, buf); |
7 | 1990 if (!(flags & BLN_DUMMY)) |
5816 | 1991 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
1992 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
1993 && !bufref_valid(&bufref)) |
5816 | 1994 return NULL; |
1995 } | |
7 | 1996 } |
1997 return buf; | |
1998 } | |
1999 | |
2000 /* | |
2001 * If the current buffer has no name and no contents, use the current | |
2002 * buffer. Otherwise: Need to allocate a new buffer structure. | |
2003 * | |
2004 * This is the ONLY place where a new buffer structure is allocated! | |
625 | 2005 * (A spell file buffer is allocated in spell.c, but that's not a normal |
2006 * buffer.) | |
7 | 2007 */ |
2008 buf = NULL; | |
13782
3be5e8306a3e
patch 8.0.1763: :argedit does not reuse an empty unnamed buffer
Christian Brabandt <cb@256bit.org>
parents:
13720
diff
changeset
|
2009 if ((flags & BLN_CURBUF) && curbuf_reusable()) |
7 | 2010 { |
2011 buf = curbuf; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2012 // It's like this buffer is deleted. Watch out for autocommands that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2013 // change curbuf! If that happens, allocate a new buffer anyway. |
7 | 2014 if (curbuf->b_p_bl) |
2015 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
2016 if (buf == curbuf) | |
2017 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2018 #ifdef FEAT_EVAL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2019 if (aborting()) // autocmds may abort script processing |
19816
f37028184d6a
patch 8.2.0464: typos and other small problems
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
2020 { |
f37028184d6a
patch 8.2.0464: typos and other small problems
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
2021 vim_free(ffname); |
7 | 2022 return NULL; |
19816
f37028184d6a
patch 8.2.0464: typos and other small problems
Bram Moolenaar <Bram@vim.org>
parents:
19629
diff
changeset
|
2023 } |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2024 #endif |
7 | 2025 if (buf == curbuf) |
2026 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2027 // Make sure 'bufhidden' and 'buftype' are empty |
7 | 2028 clear_string_option(&buf->b_p_bh); |
2029 clear_string_option(&buf->b_p_bt); | |
2030 } | |
2031 } | |
2032 if (buf != curbuf || curbuf == NULL) | |
2033 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
2034 buf = ALLOC_CLEAR_ONE(buf_T); |
7 | 2035 if (buf == NULL) |
2036 { | |
2037 vim_free(ffname); | |
2038 return NULL; | |
2039 } | |
4287 | 2040 #ifdef FEAT_EVAL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2041 // init b: variables |
4287 | 2042 buf->b_vars = dict_alloc(); |
2043 if (buf->b_vars == NULL) | |
2044 { | |
2045 vim_free(ffname); | |
2046 vim_free(buf); | |
2047 return NULL; | |
2048 } | |
2049 init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE); | |
2050 #endif | |
10889
5780bd3a5a7e
patch 8.0.0334: can't access b:changedtick from a dict reference
Christian Brabandt <cb@256bit.org>
parents:
10678
diff
changeset
|
2051 init_changedtick(buf); |
7 | 2052 } |
2053 | |
2054 if (ffname != NULL) | |
2055 { | |
2056 buf->b_ffname = ffname; | |
2057 buf->b_sfname = vim_strsave(sfname); | |
2058 } | |
2059 | |
2060 clear_wininfo(buf); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
2061 buf->b_wininfo = ALLOC_CLEAR_ONE(wininfo_T); |
7 | 2062 |
2063 if ((ffname != NULL && (buf->b_ffname == NULL || buf->b_sfname == NULL)) | |
2064 || buf->b_wininfo == NULL) | |
2065 { | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2066 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2067 VIM_CLEAR(buf->b_sfname); |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2068 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2069 buf->b_sfname = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
2070 VIM_CLEAR(buf->b_ffname); |
7 | 2071 if (buf != curbuf) |
2072 free_buffer(buf); | |
2073 return NULL; | |
2074 } | |
2075 | |
2076 if (buf == curbuf) | |
2077 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2078 // free all things allocated for this buffer |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2360
diff
changeset
|
2079 buf_freeall(buf, 0); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2080 if (buf != curbuf) // autocommands deleted the buffer! |
7 | 2081 return NULL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2082 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2083 if (aborting()) // autocmds may abort script processing |
7 | 2084 return NULL; |
2085 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2086 free_buffer_stuff(buf, FALSE); // delete local variables et al. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2087 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2088 // Init the options. |
3925 | 2089 buf->b_p_initialized = FALSE; |
2090 buf_copy_options(buf, BCO_ENTER); | |
2091 | |
7 | 2092 #ifdef FEAT_KEYMAP |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2093 // need to reload lmaps and set b:keymap_name |
7 | 2094 curbuf->b_kmap_state |= KEYMAP_INIT; |
2095 #endif | |
2096 } | |
2097 else | |
2098 { | |
2099 /* | |
2100 * put new buffer at the end of the buffer list | |
2101 */ | |
2102 buf->b_next = NULL; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2103 if (firstbuf == NULL) // buffer list is empty |
7 | 2104 { |
2105 buf->b_prev = NULL; | |
2106 firstbuf = buf; | |
2107 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2108 else // append new buffer at end of list |
7 | 2109 { |
2110 lastbuf->b_next = buf; | |
2111 buf->b_prev = lastbuf; | |
2112 } | |
2113 lastbuf = buf; | |
2114 | |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2115 if ((flags & BLN_REUSE) && buf_reuse.ga_len > 0) |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2116 { |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2117 // Recycle a previously used buffer number. Used for buffers which |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2118 // are normally hidden, e.g. in a popup window. Avoids that the |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2119 // buffer number grows rapidly. |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2120 --buf_reuse.ga_len; |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2121 buf->b_fnum = ((int *)buf_reuse.ga_data)[buf_reuse.ga_len]; |
18864
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2122 |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2123 // Move buffer to the right place in the buffer list. |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2124 while (buf->b_prev != NULL && buf->b_fnum < buf->b_prev->b_fnum) |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2125 { |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2126 buf_T *prev = buf->b_prev; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2127 |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2128 prev->b_next = buf->b_next; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2129 if (prev->b_next != NULL) |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2130 prev->b_next->b_prev = prev; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2131 buf->b_next = prev; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2132 buf->b_prev = prev->b_prev; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2133 if (buf->b_prev != NULL) |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2134 buf->b_prev->b_next = buf; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2135 prev->b_prev = buf; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2136 if (lastbuf == buf) |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2137 lastbuf = prev; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2138 if (firstbuf == prev) |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2139 firstbuf = buf; |
9449ed2ee8d4
patch 8.1.2418: bufnr('$') is wrong after recycling popup buffer
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2140 } |
17823
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2141 } |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2142 else |
7e6b7a4f13bc
patch 8.1.1908: every popup window consumes a buffer number
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
2143 buf->b_fnum = top_file_num++; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2144 if (top_file_num < 0) // wrap around (may cause duplicates) |
7 | 2145 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2146 emsg(_("W14: Warning: List of file names overflow")); |
7 | 2147 if (emsg_silent == 0) |
2148 { | |
2149 out_flush(); | |
18642
bbea1f108187
patch 8.1.2313: debugging where a delay comes from is not easy
Bram Moolenaar <Bram@vim.org>
parents:
18546
diff
changeset
|
2150 ui_delay(3001L, TRUE); // make sure it is noticed |
7 | 2151 } |
2152 top_file_num = 1; | |
2153 } | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2154 buf_hashtab_add(buf); |
7 | 2155 |
2156 /* | |
2157 * Always copy the options from the current buffer. | |
2158 */ | |
2159 buf_copy_options(buf, BCO_ALWAYS); | |
2160 } | |
2161 | |
2162 buf->b_wininfo->wi_fpos.lnum = lnum; | |
2163 buf->b_wininfo->wi_win = curwin; | |
2164 | |
126 | 2165 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2166 hash_init(&buf->b_s.b_keywtab); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2167 hash_init(&buf->b_s.b_keywtab_ic); |
7 | 2168 #endif |
2169 | |
2170 buf->b_fname = buf->b_sfname; | |
2171 #ifdef UNIX | |
2172 if (st.st_dev == (dev_T)-1) | |
1873 | 2173 buf->b_dev_valid = FALSE; |
7 | 2174 else |
2175 { | |
1873 | 2176 buf->b_dev_valid = TRUE; |
7 | 2177 buf->b_dev = st.st_dev; |
2178 buf->b_ino = st.st_ino; | |
2179 } | |
2180 #endif | |
2181 buf->b_u_synced = TRUE; | |
2182 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; | |
42 | 2183 if (flags & BLN_DUMMY) |
2184 buf->b_flags |= BF_DUMMY; | |
7 | 2185 buf_clear_file(buf); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2186 clrallmarks(buf); // clear marks |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2187 fmarks_check_names(buf); // check file marks for this file |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2188 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; // init 'buflisted' |
7 | 2189 if (!(flags & BLN_DUMMY)) |
2190 { | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2191 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2192 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2193 // Tricky: these autocommands may change the buffer list. They could |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2194 // also split the window with re-using the one empty buffer. This may |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2195 // result in unexpectedly losing the empty buffer. |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2196 set_bufref(&bufref, buf); |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
2197 if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2198 && !bufref_valid(&bufref)) |
5816 | 2199 return NULL; |
7 | 2200 if (flags & BLN_LISTED) |
5816 | 2201 { |
9473
bdac1019552f
commit https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
2202 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
2203 && !bufref_valid(&bufref)) |
5816 | 2204 return NULL; |
2205 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2206 #ifdef FEAT_EVAL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2207 if (aborting()) // autocmds may abort script processing |
7 | 2208 return NULL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
2209 #endif |
7 | 2210 } |
2211 | |
2212 return buf; | |
2213 } | |
2214 | |
2215 /* | |
2216 * Free the memory for the options of a buffer. | |
2217 * If "free_p_ff" is TRUE also free 'fileformat', 'buftype' and | |
2218 * 'fileencoding'. | |
2219 */ | |
2220 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2221 free_buf_options( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2222 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2223 int free_p_ff) |
7 | 2224 { |
2225 if (free_p_ff) | |
2226 { | |
2227 clear_string_option(&buf->b_p_fenc); | |
2228 clear_string_option(&buf->b_p_ff); | |
2229 clear_string_option(&buf->b_p_bh); | |
2230 clear_string_option(&buf->b_p_bt); | |
2231 } | |
2232 #ifdef FEAT_FIND_ID | |
2233 clear_string_option(&buf->b_p_def); | |
2234 clear_string_option(&buf->b_p_inc); | |
2235 # ifdef FEAT_EVAL | |
2236 clear_string_option(&buf->b_p_inex); | |
2237 # endif | |
2238 #endif | |
2239 #if defined(FEAT_CINDENT) && defined(FEAT_EVAL) | |
2240 clear_string_option(&buf->b_p_inde); | |
2241 clear_string_option(&buf->b_p_indk); | |
2242 #endif | |
788 | 2243 #if defined(FEAT_BEVAL) && defined(FEAT_EVAL) |
2244 clear_string_option(&buf->b_p_bexpr); | |
2245 #endif | |
2360
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2246 #if defined(FEAT_CRYPT) |
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2247 clear_string_option(&buf->b_p_cm); |
d8e4b27cef80
Change 'cryptmethod' from a number to a string option. Make it global-local.
Bram Moolenaar <bram@vim.org>
parents:
2329
diff
changeset
|
2248 #endif |
10678
c647f01d6dbd
patch 8.0.0229: local 'formatprg' option value leaks
Christian Brabandt <cb@256bit.org>
parents:
10575
diff
changeset
|
2249 clear_string_option(&buf->b_p_fp); |
667 | 2250 #if defined(FEAT_EVAL) |
2251 clear_string_option(&buf->b_p_fex); | |
2252 #endif | |
7 | 2253 #ifdef FEAT_CRYPT |
2254 clear_string_option(&buf->b_p_key); | |
2255 #endif | |
2256 clear_string_option(&buf->b_p_kp); | |
2257 clear_string_option(&buf->b_p_mps); | |
2258 clear_string_option(&buf->b_p_fo); | |
41 | 2259 clear_string_option(&buf->b_p_flp); |
7 | 2260 clear_string_option(&buf->b_p_isk); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2261 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2262 clear_string_option(&buf->b_p_vsts); |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15858
diff
changeset
|
2263 vim_free(buf->b_p_vsts_nopaste); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2264 buf->b_p_vsts_nopaste = NULL; |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15858
diff
changeset
|
2265 vim_free(buf->b_p_vsts_array); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2266 buf->b_p_vsts_array = NULL; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2267 clear_string_option(&buf->b_p_vts); |
15858
3a45b89639fb
patch 8.1.0936: may leak memory when using 'vartabstop'
Bram Moolenaar <Bram@vim.org>
parents:
15794
diff
changeset
|
2268 VIM_CLEAR(buf->b_p_vts_array); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
2269 #endif |
7 | 2270 #ifdef FEAT_KEYMAP |
2271 clear_string_option(&buf->b_p_keymap); | |
13121
3321582cae78
patch 8.0.1435: memory leak in test_arabic
Christian Brabandt <cb@256bit.org>
parents:
13054
diff
changeset
|
2272 keymap_clear(&buf->b_kmap_ga); |
7 | 2273 ga_clear(&buf->b_kmap_ga); |
2274 #endif | |
2275 clear_string_option(&buf->b_p_com); | |
2276 #ifdef FEAT_FOLDING | |
2277 clear_string_option(&buf->b_p_cms); | |
2278 #endif | |
2279 clear_string_option(&buf->b_p_nf); | |
2280 #ifdef FEAT_SYN_HL | |
2281 clear_string_option(&buf->b_p_syn); | |
7687
61354fabf8a2
commit https://github.com/vim/vim/commit/b8060fe862f684b591f9ac679eac5b2594d6c5a0
Christian Brabandt <cb@256bit.org>
parents:
7572
diff
changeset
|
2282 clear_string_option(&buf->b_s.b_syn_isk); |
737 | 2283 #endif |
2284 #ifdef FEAT_SPELL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2285 clear_string_option(&buf->b_s.b_p_spc); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2286 clear_string_option(&buf->b_s.b_p_spf); |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4795
diff
changeset
|
2287 vim_regfree(buf->b_s.b_cap_prog); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2288 buf->b_s.b_cap_prog = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2214
diff
changeset
|
2289 clear_string_option(&buf->b_s.b_p_spl); |
7 | 2290 #endif |
2291 #ifdef FEAT_SEARCHPATH | |
2292 clear_string_option(&buf->b_p_sua); | |
2293 #endif | |
2294 clear_string_option(&buf->b_p_ft); | |
2295 #ifdef FEAT_CINDENT | |
2296 clear_string_option(&buf->b_p_cink); | |
2297 clear_string_option(&buf->b_p_cino); | |
2298 #endif | |
2299 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) | |
2300 clear_string_option(&buf->b_p_cinw); | |
2301 #endif | |
2302 clear_string_option(&buf->b_p_cpt); | |
12 | 2303 #ifdef FEAT_COMPL_FUNC |
2304 clear_string_option(&buf->b_p_cfu); | |
502 | 2305 clear_string_option(&buf->b_p_ofu); |
12 | 2306 #endif |
7 | 2307 #ifdef FEAT_QUICKFIX |
2308 clear_string_option(&buf->b_p_gp); | |
2309 clear_string_option(&buf->b_p_mp); | |
2310 clear_string_option(&buf->b_p_efm); | |
2311 #endif | |
2312 clear_string_option(&buf->b_p_ep); | |
2313 clear_string_option(&buf->b_p_path); | |
2314 clear_string_option(&buf->b_p_tags); | |
7266
6ba7182fb7bd
commit https://github.com/vim/vim/commit/0f6562e9036f889185dff49a75c7fc5ffb28b307
Christian Brabandt <cb@256bit.org>
parents:
7174
diff
changeset
|
2315 clear_string_option(&buf->b_p_tc); |
16447
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
2316 #ifdef FEAT_EVAL |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
2317 clear_string_option(&buf->b_p_tfu); |
54ffc82f38a8
patch 8.1.1228: not possible to process tags with a function
Bram Moolenaar <Bram@vim.org>
parents:
16411
diff
changeset
|
2318 #endif |
7 | 2319 clear_string_option(&buf->b_p_dict); |
2320 clear_string_option(&buf->b_p_tsr); | |
12 | 2321 #ifdef FEAT_TEXTOBJ |
2322 clear_string_option(&buf->b_p_qe); | |
2323 #endif | |
7 | 2324 buf->b_p_ar = -1; |
5446 | 2325 buf->b_p_ul = NO_LOCAL_UNDOLEVEL; |
5712 | 2326 #ifdef FEAT_LISP |
2327 clear_string_option(&buf->b_p_lw); | |
2328 #endif | |
6243 | 2329 clear_string_option(&buf->b_p_bkc); |
11063
e71d3bdf3bc3
patch 8.0.0420: text garbled when the system encoding differs from 'encoding'
Christian Brabandt <cb@256bit.org>
parents:
10954
diff
changeset
|
2330 clear_string_option(&buf->b_p_menc); |
7 | 2331 } |
2332 | |
2333 /* | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2334 * Get alternate file "n". |
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2335 * Set linenr to "lnum" or altfpos.lnum if "lnum" == 0. |
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2336 * Also set cursor column to altfpos.col if 'startofline' is not set. |
7 | 2337 * if (options & GETF_SETMARK) call setpcmark() |
2338 * if (options & GETF_ALT) we are jumping to an alternate file. | |
2339 * if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping | |
2340 * | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2341 * Return FAIL for failure, OK for success. |
7 | 2342 */ |
2343 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2344 buflist_getfile( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2345 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2346 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2347 int options, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2348 int forceit) |
7 | 2349 { |
2350 buf_T *buf; | |
2351 win_T *wp = NULL; | |
2352 pos_T *fpos; | |
2353 colnr_T col; | |
2354 | |
2355 buf = buflist_findnr(n); | |
2356 if (buf == NULL) | |
2357 { | |
2358 if ((options & GETF_ALT) && n == 0) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2359 emsg(_(e_noalt)); |
7 | 2360 else |
15490
98c35d312987
patch 8.1.0753: printf format not checked for semsg()
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
2361 semsg(_("E92: Buffer %d not found"), n); |
7 | 2362 return FAIL; |
2363 } | |
2364 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2365 // if alternate file is the current buffer, nothing to do |
7 | 2366 if (buf == curbuf) |
2367 return OK; | |
2368 | |
633 | 2369 if (text_locked()) |
631 | 2370 { |
633 | 2371 text_locked_msg(); |
7 | 2372 return FAIL; |
631 | 2373 } |
819 | 2374 if (curbuf_locked()) |
2375 return FAIL; | |
7 | 2376 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2377 // altfpos may be changed by getfile(), get it now |
7 | 2378 if (lnum == 0) |
2379 { | |
2380 fpos = buflist_findfpos(buf); | |
2381 lnum = fpos->lnum; | |
2382 col = fpos->col; | |
2383 } | |
2384 else | |
2385 col = 0; | |
2386 | |
2387 if (options & GETF_SWITCH) | |
2388 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2389 // If 'switchbuf' contains "useopen": jump to first window containing |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2390 // "buf" if one exists |
1618 | 2391 if (swb_flags & SWB_USEOPEN) |
7 | 2392 wp = buf_jump_open_win(buf); |
6843 | 2393 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2394 // If 'switchbuf' contains "usetab": jump to first window in any tab |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2395 // page containing "buf" if one exists |
1618 | 2396 if (wp == NULL && (swb_flags & SWB_USETAB)) |
825 | 2397 wp = buf_jump_open_tab(buf); |
6843 | 2398 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2399 // If 'switchbuf' contains "split", "vsplit" or "newtab" and the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2400 // current buffer isn't empty: open new tab or window |
6843 | 2401 if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB)) |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11063
diff
changeset
|
2402 && !BUFEMPTY()) |
7 | 2403 { |
6843 | 2404 if (swb_flags & SWB_NEWTAB) |
1618 | 2405 tabpage_new(); |
6843 | 2406 else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0) |
2407 == FAIL) | |
7 | 2408 return FAIL; |
2583 | 2409 RESET_BINDING(curwin); |
7 | 2410 } |
2411 } | |
2412 | |
2413 ++RedrawingDisabled; | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11447
diff
changeset
|
2414 if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11447
diff
changeset
|
2415 (options & GETF_SETMARK), lnum, forceit))) |
7 | 2416 { |
2417 --RedrawingDisabled; | |
2418 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2419 // cursor is at to BOL and w_cursor.lnum is checked due to getfile() |
7 | 2420 if (!p_sol && col != 0) |
2421 { | |
2422 curwin->w_cursor.col = col; | |
2423 check_cursor_col(); | |
2424 curwin->w_cursor.coladd = 0; | |
2425 curwin->w_set_curswant = TRUE; | |
2426 } | |
2427 return OK; | |
2428 } | |
2429 --RedrawingDisabled; | |
2430 return FAIL; | |
2431 } | |
2432 | |
2433 /* | |
2434 * go to the last know line number for the current buffer | |
2435 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17781
diff
changeset
|
2436 static void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2437 buflist_getfpos(void) |
7 | 2438 { |
2439 pos_T *fpos; | |
2440 | |
2441 fpos = buflist_findfpos(curbuf); | |
2442 | |
2443 curwin->w_cursor.lnum = fpos->lnum; | |
2444 check_cursor_lnum(); | |
2445 | |
2446 if (p_sol) | |
2447 curwin->w_cursor.col = 0; | |
2448 else | |
2449 { | |
2450 curwin->w_cursor.col = fpos->col; | |
2451 check_cursor_col(); | |
2452 curwin->w_cursor.coladd = 0; | |
2453 curwin->w_set_curswant = TRUE; | |
2454 } | |
2455 } | |
2456 | |
42 | 2457 #if defined(FEAT_QUICKFIX) || defined(FEAT_EVAL) || defined(PROTO) |
2458 /* | |
2459 * Find file in buffer list by name (it has to be for the current window). | |
2460 * Returns NULL if not found. | |
2461 */ | |
2462 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2463 buflist_findname_exp(char_u *fname) |
42 | 2464 { |
2465 char_u *ffname; | |
2466 buf_T *buf = NULL; | |
2467 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2468 // First make the name into a full path name |
42 | 2469 ffname = FullName_save(fname, |
2470 #ifdef UNIX | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2471 TRUE // force expansion, get rid of symbolic links |
42 | 2472 #else |
2473 FALSE | |
2474 #endif | |
2475 ); | |
2476 if (ffname != NULL) | |
2477 { | |
2478 buf = buflist_findname(ffname); | |
2479 vim_free(ffname); | |
2480 } | |
2481 return buf; | |
2482 } | |
2483 #endif | |
2484 | |
7 | 2485 /* |
2486 * Find file in buffer list by name (it has to be for the current window). | |
2487 * "ffname" must have a full path. | |
42 | 2488 * Skips dummy buffers. |
2489 * Returns NULL if not found. | |
7 | 2490 */ |
2491 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2492 buflist_findname(char_u *ffname) |
7 | 2493 { |
2494 #ifdef UNIX | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2495 stat_T st; |
7 | 2496 |
2497 if (mch_stat((char *)ffname, &st) < 0) | |
2498 st.st_dev = (dev_T)-1; | |
2499 return buflist_findname_stat(ffname, &st); | |
2500 } | |
2501 | |
2502 /* | |
2503 * Same as buflist_findname(), but pass the stat structure to avoid getting it | |
2504 * twice for the same file. | |
42 | 2505 * Returns NULL if not found. |
7 | 2506 */ |
2507 static buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2508 buflist_findname_stat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2509 char_u *ffname, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
2510 stat_T *stp) |
7 | 2511 { |
2512 #endif | |
2513 buf_T *buf; | |
2514 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2515 // Start at the last buffer, expect to find a match sooner. |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2516 FOR_ALL_BUFS_FROM_LAST(buf) |
42 | 2517 if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname |
7 | 2518 #ifdef UNIX |
2519 , stp | |
2520 #endif | |
2521 )) | |
2522 return buf; | |
2523 return NULL; | |
2524 } | |
2525 | |
2526 /* | |
2527 * Find file in buffer list by a regexp pattern. | |
2528 * Return fnum of the found buffer. | |
2529 * Return < 0 for error. | |
2530 */ | |
2531 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2532 buflist_findpat( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2533 char_u *pattern, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2534 char_u *pattern_end, // pointer to first char after pattern |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2535 int unlisted, // find unlisted buffers |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2536 int diffmode UNUSED, // find diff-mode buffers only |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2537 int curtab_only) // find buffers in current tab only |
7 | 2538 { |
2539 buf_T *buf; | |
2540 int match = -1; | |
2541 int find_listed; | |
2542 char_u *pat; | |
2543 char_u *patend; | |
2544 int attempt; | |
2545 char_u *p; | |
2546 int toggledollar; | |
2547 | |
2548 if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) | |
2549 { | |
2550 if (*pattern == '%') | |
2551 match = curbuf->b_fnum; | |
2552 else | |
2553 match = curwin->w_alt_fnum; | |
2554 #ifdef FEAT_DIFF | |
2555 if (diffmode && !diff_mode_buf(buflist_findnr(match))) | |
2556 match = -1; | |
2557 #endif | |
2558 } | |
2559 | |
2560 /* | |
2561 * Try four ways of matching a listed buffer: | |
2562 * attempt == 0: without '^' or '$' (at any position) | |
1187 | 2563 * attempt == 1: with '^' at start (only at position 0) |
7 | 2564 * attempt == 2: with '$' at end (only match at end) |
2565 * attempt == 3: with '^' at start and '$' at end (only full match) | |
2566 * Repeat this for finding an unlisted buffer if there was no matching | |
2567 * listed buffer. | |
2568 */ | |
2569 else | |
2570 { | |
2571 pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, FALSE); | |
2572 if (pat == NULL) | |
2573 return -1; | |
2574 patend = pat + STRLEN(pat) - 1; | |
2575 toggledollar = (patend > pat && *patend == '$'); | |
2576 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2577 // First try finding a listed buffer. If not found and "unlisted" |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2578 // is TRUE, try finding an unlisted buffer. |
7 | 2579 find_listed = TRUE; |
2580 for (;;) | |
2581 { | |
2582 for (attempt = 0; attempt <= 3; ++attempt) | |
2583 { | |
6375 | 2584 regmatch_T regmatch; |
2585 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2586 // may add '^' and '$' |
7 | 2587 if (toggledollar) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2588 *patend = (attempt < 2) ? NUL : '$'; // add/remove '$' |
7 | 2589 p = pat; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2590 if (*p == '^' && !(attempt & 1)) // add/remove '^' |
7 | 2591 ++p; |
6375 | 2592 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); |
2593 if (regmatch.regprog == NULL) | |
7 | 2594 { |
2595 vim_free(pat); | |
2596 return -1; | |
2597 } | |
2598 | |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2599 FOR_ALL_BUFS_FROM_LAST(buf) |
7 | 2600 if (buf->b_p_bl == find_listed |
2601 #ifdef FEAT_DIFF | |
2602 && (!diffmode || diff_mode_buf(buf)) | |
2603 #endif | |
6375 | 2604 && buflist_match(®match, buf, FALSE) != NULL) |
7 | 2605 { |
4236 | 2606 if (curtab_only) |
2607 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2608 // Ignore the match if the buffer is not open in |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2609 // the current tab. |
4236 | 2610 win_T *wp; |
2611 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2612 FOR_ALL_WINDOWS(wp) |
4236 | 2613 if (wp->w_buffer == buf) |
2614 break; | |
2615 if (wp == NULL) | |
2616 continue; | |
2617 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2618 if (match >= 0) // already found a match |
7 | 2619 { |
2620 match = -2; | |
2621 break; | |
2622 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2623 match = buf->b_fnum; // remember first match |
7 | 2624 } |
2625 | |
6375 | 2626 vim_regfree(regmatch.regprog); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2627 if (match >= 0) // found one match |
7 | 2628 break; |
2629 } | |
2630 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2631 // Only search for unlisted buffers if there was no match with |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2632 // a listed buffer. |
7 | 2633 if (!unlisted || !find_listed || match != -1) |
2634 break; | |
2635 find_listed = FALSE; | |
2636 } | |
2637 | |
2638 vim_free(pat); | |
2639 } | |
2640 | |
2641 if (match == -2) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2642 semsg(_("E93: More than one match for %s"), pattern); |
7 | 2643 else if (match < 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
2644 semsg(_("E94: No matching buffer for %s"), pattern); |
7 | 2645 return match; |
2646 } | |
2647 | |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2648 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2649 typedef struct { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2650 buf_T *buf; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2651 char_u *match; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2652 } bufmatch_T; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2653 #endif |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2654 |
7 | 2655 /* |
2656 * Find all buffer names that match. | |
2657 * For command line expansion of ":buf" and ":sbuf". | |
2658 * Return OK if matches found, FAIL otherwise. | |
2659 */ | |
2660 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2661 ExpandBufnames( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2662 char_u *pat, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2663 int *num_file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2664 char_u ***file, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2665 int options) |
7 | 2666 { |
2667 int count = 0; | |
2668 buf_T *buf; | |
2669 int round; | |
2670 char_u *p; | |
2671 int attempt; | |
170 | 2672 char_u *patc; |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2673 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2674 bufmatch_T *matches = NULL; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2675 #endif |
7 | 2676 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2677 *num_file = 0; // return values in case of FAIL |
7 | 2678 *file = NULL; |
2679 | |
19007
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2680 #ifdef FEAT_DIFF |
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2681 if ((options & BUF_DIFF_FILTER) && !curwin->w_p_diff) |
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2682 return FAIL; |
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2683 #endif |
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2684 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2685 // Make a copy of "pat" and change "^" to "\(^\|[\/]\)". |
170 | 2686 if (*pat == '^') |
2687 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16740
diff
changeset
|
2688 patc = alloc(STRLEN(pat) + 11); |
170 | 2689 if (patc == NULL) |
2690 return FAIL; | |
2691 STRCPY(patc, "\\(^\\|[\\/]\\)"); | |
2692 STRCPY(patc + 11, pat + 1); | |
2693 } | |
2694 else | |
2695 patc = pat; | |
2696 | |
7 | 2697 /* |
170 | 2698 * attempt == 0: try match with '\<', match at start of word |
267 | 2699 * attempt == 1: try match without '\<', match anywhere |
7 | 2700 */ |
267 | 2701 for (attempt = 0; attempt <= 1; ++attempt) |
7 | 2702 { |
6375 | 2703 regmatch_T regmatch; |
2704 | |
267 | 2705 if (attempt > 0 && patc == pat) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2706 break; // there was no anchor, no need to try again |
6375 | 2707 regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); |
2708 if (regmatch.regprog == NULL) | |
7 | 2709 { |
170 | 2710 if (patc != pat) |
2711 vim_free(patc); | |
2712 return FAIL; | |
7 | 2713 } |
2714 | |
2715 /* | |
2716 * round == 1: Count the matches. | |
2717 * round == 2: Build the array to keep the matches. | |
2718 */ | |
2719 for (round = 1; round <= 2; ++round) | |
2720 { | |
2721 count = 0; | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2722 FOR_ALL_BUFFERS(buf) |
7 | 2723 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2724 if (!buf->b_p_bl) // skip unlisted buffers |
7 | 2725 continue; |
18987
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2726 #ifdef FEAT_DIFF |
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2727 if (options & BUF_DIFF_FILTER) |
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2728 // Skip buffers not suitable for |
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2729 // :diffget or :diffput completion. |
19007
0883a37ccf84
patch 8.2.0064: diffmode completion doesn't use per-window setting
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
2730 if (buf == curbuf || !diff_mode_buf(buf)) |
18987
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2731 continue; |
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2732 #endif |
e378907d79bf
patch 8.2.0054: :diffget and :diffput don't have good completion
Bram Moolenaar <Bram@vim.org>
parents:
18949
diff
changeset
|
2733 |
6375 | 2734 p = buflist_match(®match, buf, p_wic); |
7 | 2735 if (p != NULL) |
2736 { | |
2737 if (round == 1) | |
2738 ++count; | |
2739 else | |
2740 { | |
2741 if (options & WILD_HOME_REPLACE) | |
2742 p = home_replace_save(buf, p); | |
2743 else | |
2744 p = vim_strsave(p); | |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2745 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2746 if (matches != NULL) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2747 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2748 matches[count].buf = buf; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2749 matches[count].match = p; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2750 count++; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2751 } |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2752 else |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2753 #endif |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2754 (*file)[count++] = p; |
7 | 2755 } |
2756 } | |
2757 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2758 if (count == 0) // no match found, break here |
7 | 2759 break; |
2760 if (round == 1) | |
2761 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
2762 *file = ALLOC_MULT(char_u *, count); |
7 | 2763 if (*file == NULL) |
2764 { | |
6375 | 2765 vim_regfree(regmatch.regprog); |
170 | 2766 if (patc != pat) |
2767 vim_free(patc); | |
7 | 2768 return FAIL; |
2769 } | |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2770 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2771 if (options & WILD_BUFLASTUSED) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2772 matches = ALLOC_MULT(bufmatch_T, count); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2773 #endif |
7 | 2774 } |
2775 } | |
6375 | 2776 vim_regfree(regmatch.regprog); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2777 if (count) // match(es) found, break here |
7 | 2778 break; |
2779 } | |
2780 | |
170 | 2781 if (patc != pat) |
2782 vim_free(patc); | |
2783 | |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2784 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2785 if (matches != NULL) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2786 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2787 int i; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2788 if (count > 1) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2789 qsort(matches, count, sizeof(bufmatch_T), buf_compare); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2790 // if the current buffer is first in the list, place it at the end |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2791 if (matches[0].buf == curbuf) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2792 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2793 for (i = 1; i < count; i++) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2794 (*file)[i-1] = matches[i].match; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2795 (*file)[count-1] = matches[0].match; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2796 } |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2797 else |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2798 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2799 for (i = 0; i < count; i++) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2800 (*file)[i] = matches[i].match; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2801 } |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2802 vim_free(matches); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2803 } |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2804 #endif |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
2805 |
7 | 2806 *num_file = count; |
2807 return (count == 0 ? FAIL : OK); | |
2808 } | |
2809 | |
2810 /* | |
2811 * Check for a match on the file name for buffer "buf" with regprog "prog". | |
2812 */ | |
2813 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2814 buflist_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2815 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2816 buf_T *buf, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2817 int ignore_case) // when TRUE ignore case, when FALSE use 'fic' |
7 | 2818 { |
2819 char_u *match; | |
2820 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2821 // First try the short file name, then the long file name. |
6375 | 2822 match = fname_match(rmp, buf->b_sfname, ignore_case); |
7 | 2823 if (match == NULL) |
6375 | 2824 match = fname_match(rmp, buf->b_ffname, ignore_case); |
7 | 2825 |
2826 return match; | |
2827 } | |
2828 | |
2829 /* | |
2830 * Try matching the regexp in "prog" with file name "name". | |
2831 * Return "name" when there is a match, NULL when not. | |
2832 */ | |
2833 static char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2834 fname_match( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2835 regmatch_T *rmp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2836 char_u *name, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2837 int ignore_case) // when TRUE ignore case, when FALSE use 'fic' |
7 | 2838 { |
2839 char_u *match = NULL; | |
2840 char_u *p; | |
2841 | |
2842 if (name != NULL) | |
2843 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2844 // Ignore case when 'fileignorecase' or the argument is set. |
6375 | 2845 rmp->rm_ic = p_fic || ignore_case; |
2846 if (vim_regexec(rmp, name, (colnr_T)0)) | |
7 | 2847 match = name; |
2848 else | |
2849 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2850 // Replace $(HOME) with '~' and try matching again. |
7 | 2851 p = home_replace_save(NULL, name); |
6375 | 2852 if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) |
7 | 2853 match = name; |
2854 vim_free(p); | |
2855 } | |
2856 } | |
2857 | |
2858 return match; | |
2859 } | |
2860 | |
2861 /* | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2862 * Find a file in the buffer list by buffer number. |
7 | 2863 */ |
2864 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2865 buflist_findnr(int nr) |
7 | 2866 { |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2867 char_u key[VIM_SIZEOF_INT * 2 + 1]; |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2868 hashitem_T *hi; |
7 | 2869 |
2870 if (nr == 0) | |
2871 nr = curwin->w_alt_fnum; | |
9511
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2872 sprintf((char *)key, "%x", nr); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2873 hi = hash_find(&buf_hashtab, key); |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2874 |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2875 if (!HASHITEM_EMPTY(hi)) |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2876 return (buf_T *)(hi->hi_key |
c2e904cc064f
commit https://github.com/vim/vim/commit/480778b805bd8bdc5d657560230e9c50feda1d0f
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
2877 - ((unsigned)(curbuf->b_key - (char_u *)curbuf))); |
7 | 2878 return NULL; |
2879 } | |
2880 | |
2881 /* | |
2882 * Get name of file 'n' in the buffer list. | |
2883 * When the file has no name an empty string is returned. | |
2884 * home_replace() is used to shorten the file name (used for marks). | |
2885 * Returns a pointer to allocated memory, of NULL when failed. | |
2886 */ | |
2887 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2888 buflist_nr2name( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2889 int n, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2890 int fullname, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2891 int helptail) // for help buffers return tail only |
7 | 2892 { |
2893 buf_T *buf; | |
2894 | |
2895 buf = buflist_findnr(n); | |
2896 if (buf == NULL) | |
2897 return NULL; | |
2898 return home_replace_save(helptail ? buf : NULL, | |
2899 fullname ? buf->b_ffname : buf->b_fname); | |
2900 } | |
2901 | |
2902 /* | |
2903 * Set the "lnum" and "col" for the buffer "buf" and the current window. | |
2904 * When "copy_options" is TRUE save the local window option values. | |
2905 * When "lnum" is 0 only do the options. | |
2906 */ | |
17458
cfdef48743ed
patch 8.1.1727: code for viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17225
diff
changeset
|
2907 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2908 buflist_setfpos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2909 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2910 win_T *win, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2911 linenr_T lnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2912 colnr_T col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2913 int copy_options) |
7 | 2914 { |
2915 wininfo_T *wip; | |
2916 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19816
diff
changeset
|
2917 FOR_ALL_BUF_WININFO(buf, wip) |
7 | 2918 if (wip->wi_win == win) |
2919 break; | |
2920 if (wip == NULL) | |
2921 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2922 // allocate a new entry |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
2923 wip = ALLOC_CLEAR_ONE(wininfo_T); |
7 | 2924 if (wip == NULL) |
2925 return; | |
2926 wip->wi_win = win; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2927 if (lnum == 0) // set lnum even when it's 0 |
7 | 2928 lnum = 1; |
2929 } | |
2930 else | |
2931 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2932 // remove the entry from the list |
7 | 2933 if (wip->wi_prev) |
2934 wip->wi_prev->wi_next = wip->wi_next; | |
2935 else | |
2936 buf->b_wininfo = wip->wi_next; | |
2937 if (wip->wi_next) | |
2938 wip->wi_next->wi_prev = wip->wi_prev; | |
2939 if (copy_options && wip->wi_optset) | |
2940 { | |
2941 clear_winopt(&wip->wi_opt); | |
2942 #ifdef FEAT_FOLDING | |
2943 deleteFoldRecurse(&wip->wi_folds); | |
2944 #endif | |
2945 } | |
2946 } | |
2947 if (lnum != 0) | |
2948 { | |
2949 wip->wi_fpos.lnum = lnum; | |
2950 wip->wi_fpos.col = col; | |
2951 } | |
2952 if (copy_options) | |
2953 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2954 // Save the window-specific option values. |
7 | 2955 copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); |
2956 #ifdef FEAT_FOLDING | |
2957 wip->wi_fold_manual = win->w_fold_manual; | |
2958 cloneFoldGrowArray(&win->w_folds, &wip->wi_folds); | |
2959 #endif | |
2960 wip->wi_optset = TRUE; | |
2961 } | |
2962 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2963 // insert the entry in front of the list |
7 | 2964 wip->wi_next = buf->b_wininfo; |
2965 buf->b_wininfo = wip; | |
2966 wip->wi_prev = NULL; | |
2967 if (wip->wi_next) | |
2968 wip->wi_next->wi_prev = wip; | |
2969 | |
2970 return; | |
2971 } | |
2972 | |
1743 | 2973 #ifdef FEAT_DIFF |
2974 /* | |
2975 * Return TRUE when "wip" has 'diff' set and the diff is only for another tab | |
2976 * page. That's because a diff is local to a tab page. | |
2977 */ | |
2978 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2979 wininfo_other_tab_diff(wininfo_T *wip) |
1743 | 2980 { |
2981 win_T *wp; | |
2982 | |
2983 if (wip->wi_opt.wo_diff) | |
2984 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
2985 FOR_ALL_WINDOWS(wp) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2986 // return FALSE when it's a window in the current tab page, thus |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
2987 // the buffer was in diff mode here |
1743 | 2988 if (wip->wi_win == wp) |
2989 return FALSE; | |
2990 return TRUE; | |
2991 } | |
2992 return FALSE; | |
2993 } | |
2994 #endif | |
2995 | |
7 | 2996 /* |
2997 * Find info for the current window in buffer "buf". | |
2998 * If not found, return the info for the most recently used window. | |
1743 | 2999 * When "skip_diff_buffer" is TRUE avoid windows with 'diff' set that is in |
3000 * another tab page. | |
7 | 3001 * Returns NULL when there isn't any info. |
3002 */ | |
3003 static wininfo_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3004 find_wininfo( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3005 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3006 int skip_diff_buffer UNUSED) |
7 | 3007 { |
3008 wininfo_T *wip; | |
3009 | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19816
diff
changeset
|
3010 FOR_ALL_BUF_WININFO(buf, wip) |
1743 | 3011 if (wip->wi_win == curwin |
3012 #ifdef FEAT_DIFF | |
3013 && (!skip_diff_buffer || !wininfo_other_tab_diff(wip)) | |
3014 #endif | |
3015 ) | |
7 | 3016 break; |
1743 | 3017 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3018 // If no wininfo for curwin, use the first in the list (that doesn't have |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3019 // 'diff' set and is in another tab page). |
1743 | 3020 if (wip == NULL) |
3021 { | |
3022 #ifdef FEAT_DIFF | |
3023 if (skip_diff_buffer) | |
3024 { | |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19816
diff
changeset
|
3025 FOR_ALL_BUF_WININFO(buf, wip) |
1743 | 3026 if (!wininfo_other_tab_diff(wip)) |
3027 break; | |
3028 } | |
3029 else | |
3030 #endif | |
3031 wip = buf->b_wininfo; | |
3032 } | |
7 | 3033 return wip; |
3034 } | |
3035 | |
3036 /* | |
3037 * Reset the local window options to the values last used in this window. | |
3038 * If the buffer wasn't used in this window before, use the values from | |
3039 * the most recently used window. If the values were never set, use the | |
3040 * global values for the window. | |
3041 */ | |
3042 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3043 get_winopts(buf_T *buf) |
7 | 3044 { |
3045 wininfo_T *wip; | |
3046 | |
3047 clear_winopt(&curwin->w_onebuf_opt); | |
3048 #ifdef FEAT_FOLDING | |
3049 clearFolding(curwin); | |
3050 #endif | |
3051 | |
1743 | 3052 wip = find_wininfo(buf, TRUE); |
13931
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3053 if (wip != NULL && wip->wi_win != NULL |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3054 && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) |
7 | 3055 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3056 // The buffer is currently displayed in the window: use the actual |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3057 // option values instead of the saved (possibly outdated) values. |
13931
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3058 win_T *wp = wip->wi_win; |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3059 |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3060 copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt); |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3061 #ifdef FEAT_FOLDING |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3062 curwin->w_fold_manual = wp->w_fold_manual; |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3063 curwin->w_foldinvalid = TRUE; |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3064 cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds); |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3065 #endif |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3066 } |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3067 else if (wip != NULL && wip->wi_optset) |
fc03fabbedc5
patch 8.0.1836: buffer-local window options may not be recent
Christian Brabandt <cb@256bit.org>
parents:
13782
diff
changeset
|
3068 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3069 // the buffer was displayed in the current window earlier |
7 | 3070 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); |
3071 #ifdef FEAT_FOLDING | |
3072 curwin->w_fold_manual = wip->wi_fold_manual; | |
3073 curwin->w_foldinvalid = TRUE; | |
3074 cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds); | |
3075 #endif | |
3076 } | |
3077 else | |
3078 copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); | |
3079 | |
3080 #ifdef FEAT_FOLDING | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3081 // Set 'foldlevel' to 'foldlevelstart' if it's not negative. |
7 | 3082 if (p_fdls >= 0) |
3083 curwin->w_p_fdl = p_fdls; | |
3084 #endif | |
18156
c81370b3ede4
patch 8.1.2073: when editing a buffer 'colorcolumn' may not work
Bram Moolenaar <Bram@vim.org>
parents:
18010
diff
changeset
|
3085 after_copy_winopt(curwin); |
7 | 3086 } |
3087 | |
3088 /* | |
3089 * Find the position (lnum and col) for the buffer 'buf' for the current | |
3090 * window. | |
3091 * Returns a pointer to no_position if no position is found. | |
3092 */ | |
3093 pos_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3094 buflist_findfpos(buf_T *buf) |
7 | 3095 { |
3096 wininfo_T *wip; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15595
diff
changeset
|
3097 static pos_T no_position = {1, 0, 0}; |
7 | 3098 |
1743 | 3099 wip = find_wininfo(buf, FALSE); |
7 | 3100 if (wip != NULL) |
3101 return &(wip->wi_fpos); | |
3102 else | |
3103 return &no_position; | |
3104 } | |
3105 | |
3106 /* | |
3107 * Find the lnum for the buffer 'buf' for the current window. | |
3108 */ | |
3109 linenr_T | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3110 buflist_findlnum(buf_T *buf) |
7 | 3111 { |
3112 return buflist_findfpos(buf)->lnum; | |
3113 } | |
3114 | |
3115 /* | |
11447
698ee9d4fe9f
patch 8.0.0607: after :bwipe + :new bufref might still be valid
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3116 * List all known file names (for :files and :buffers command). |
7 | 3117 */ |
3118 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3119 buflist_list(exarg_T *eap) |
7 | 3120 { |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3121 buf_T *buf = firstbuf; |
7 | 3122 int len; |
3123 int i; | |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3124 int ro_char; |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3125 int changed_char; |
13555
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3126 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3127 int job_running; |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3128 int job_none_open; |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3129 #endif |
7 | 3130 |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3131 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3132 garray_T buflist; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3133 buf_T **buflist_data = NULL, **p; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3134 |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3135 if (vim_strchr(eap->arg, 't')) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3136 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3137 ga_init2(&buflist, sizeof(buf_T *), 50); |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19816
diff
changeset
|
3138 FOR_ALL_BUFFERS(buf) |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3139 { |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3140 if (ga_grow(&buflist, 1) == OK) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3141 ((buf_T **)buflist.ga_data)[buflist.ga_len++] = buf; |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3142 } |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3143 |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3144 qsort(buflist.ga_data, (size_t)buflist.ga_len, |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3145 sizeof(buf_T *), buf_compare); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3146 |
18546
f609865bfc54
patch 8.1.2267: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3147 buflist_data = (buf_T **)buflist.ga_data; |
f609865bfc54
patch 8.1.2267: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3148 buf = *buflist_data; |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3149 } |
18546
f609865bfc54
patch 8.1.2267: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3150 p = buflist_data; |
f609865bfc54
patch 8.1.2267: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3151 |
f609865bfc54
patch 8.1.2267: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
18498
diff
changeset
|
3152 for (; buf != NULL && !got_int; buf = buflist_data != NULL |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3153 ? (++p < buflist_data + buflist.ga_len ? *p : NULL) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3154 : buf->b_next) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3155 #else |
7 | 3156 for (buf = firstbuf; buf != NULL && !got_int; buf = buf->b_next) |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3157 #endif |
7 | 3158 { |
13555
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3159 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3160 job_running = term_job_running(buf->b_term); |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3161 job_none_open = job_running && term_none_open(buf->b_term); |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3162 #endif |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3163 // skip unlisted buffers, unless ! was used |
6945 | 3164 if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) |
3165 || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) | |
3166 || (vim_strchr(eap->arg, '+') | |
3167 && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) | |
3168 || (vim_strchr(eap->arg, 'a') | |
13555
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3169 && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows == 0)) |
6945 | 3170 || (vim_strchr(eap->arg, 'h') |
13555
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3171 && (buf->b_ml.ml_mfp == NULL || buf->b_nwindows != 0)) |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3172 #ifdef FEAT_TERMINAL |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3173 || (vim_strchr(eap->arg, 'R') |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3174 && (!job_running || (job_running && job_none_open))) |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3175 || (vim_strchr(eap->arg, '?') |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3176 && (!job_running || (job_running && !job_none_open))) |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3177 || (vim_strchr(eap->arg, 'F') |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3178 && (job_running || buf->b_term == NULL)) |
78ead137b2ad
patch 8.0.1651: cannot filter :ls output for terminal buffers
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3179 #endif |
6945 | 3180 || (vim_strchr(eap->arg, '-') && buf->b_p_ma) |
3181 || (vim_strchr(eap->arg, '=') && !buf->b_p_ro) | |
3182 || (vim_strchr(eap->arg, 'x') && !(buf->b_flags & BF_READERR)) | |
3183 || (vim_strchr(eap->arg, '%') && buf != curbuf) | |
3184 || (vim_strchr(eap->arg, '#') | |
3185 && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) | |
7 | 3186 continue; |
3187 if (buf_spname(buf) != NULL) | |
3839 | 3188 vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
7 | 3189 else |
3190 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9943
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3191 if (message_filtered(NameBuff)) |
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3192 continue; |
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3193 |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3194 changed_char = (buf->b_flags & BF_READERR) ? 'x' |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3195 : (bufIsChanged(buf) ? '+' : ' '); |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3196 #ifdef FEAT_TERMINAL |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3197 if (term_job_running(buf->b_term)) |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3198 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3199 if (term_none_open(buf->b_term)) |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3200 ro_char = '?'; |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3201 else |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
3202 ro_char = 'R'; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3203 changed_char = ' '; // bufIsChanged() returns TRUE to avoid |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3204 // closing, but it's not actually changed. |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3205 } |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3206 else if (buf->b_term != NULL) |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3207 ro_char = 'F'; |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3208 else |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3209 #endif |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3210 ro_char = !buf->b_p_ma ? '-' : (buf->b_p_ro ? '=' : ' '); |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3211 |
9943
af161c1f530a
commit https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec
Christian Brabandt <cb@256bit.org>
parents:
9911
diff
changeset
|
3212 msg_putchar('\n'); |
302 | 3213 len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"", |
7 | 3214 buf->b_fnum, |
3215 buf->b_p_bl ? ' ' : 'u', | |
3216 buf == curbuf ? '%' : | |
3217 (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '), | |
3218 buf->b_ml.ml_mfp == NULL ? ' ' : | |
3219 (buf->b_nwindows == 0 ? 'h' : 'a'), | |
12110
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3220 ro_char, |
7b3a3af7cefb
patch 8.0.0935: cannot recognize a terminal buffer in :ls output
Christian Brabandt <cb@256bit.org>
parents:
12100
diff
changeset
|
3221 changed_char, |
300 | 3222 NameBuff); |
7572
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
3223 if (len > IOSIZE - 20) |
992fe73d4ee6
commit https://github.com/vim/vim/commit/507edf63df75fe228e0f76b845b58d60266e65d8
Christian Brabandt <cb@256bit.org>
parents:
7266
diff
changeset
|
3224 len = IOSIZE - 20; |
7 | 3225 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3226 // put "line 999" in column 40 or after the file name |
7 | 3227 i = 40 - vim_strsize(IObuff); |
3228 do | |
3229 IObuff[len++] = ' '; | |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
16082
diff
changeset
|
3230 while (--i > 0 && len < IOSIZE - 18); |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3231 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3232 if (vim_strchr(eap->arg, 't') && buf->b_last_used) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3233 add_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3234 else |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3235 #endif |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3236 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3237 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum |
272 | 3238 : (long)buflist_findlnum(buf)); |
7 | 3239 msg_outtrans(IObuff); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3240 out_flush(); // output one line at a time |
7 | 3241 ui_breakcheck(); |
3242 } | |
18463
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3243 |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3244 #ifdef FEAT_VIMINFO |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3245 if (buflist_data) |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3246 ga_clear(&buflist); |
18d7337b6837
patch 8.1.2225: the "last used" info of a buffer is under used
Bram Moolenaar <Bram@vim.org>
parents:
18225
diff
changeset
|
3247 #endif |
7 | 3248 } |
3249 | |
3250 /* | |
3251 * Get file name and line number for file 'fnum'. | |
3252 * Used by DoOneCmd() for translating '%' and '#'. | |
3253 * Used by insert_reg() and cmdline_paste() for '#' register. | |
3254 * Return FAIL if not found, OK for success. | |
3255 */ | |
3256 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3257 buflist_name_nr( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3258 int fnum, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3259 char_u **fname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3260 linenr_T *lnum) |
7 | 3261 { |
3262 buf_T *buf; | |
3263 | |
3264 buf = buflist_findnr(fnum); | |
3265 if (buf == NULL || buf->b_fname == NULL) | |
3266 return FAIL; | |
3267 | |
3268 *fname = buf->b_fname; | |
3269 *lnum = buflist_findlnum(buf); | |
3270 | |
3271 return OK; | |
3272 } | |
3273 | |
3274 /* | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3275 * Set the file name for "buf"' to "ffname_arg", short file name to |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3276 * "sfname_arg". |
7 | 3277 * The file name with the full path is also remembered, for when :cd is used. |
3278 * Returns FAIL for failure (file name already in use by other buffer) | |
3279 * OK otherwise. | |
3280 */ | |
3281 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3282 setfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3283 buf_T *buf, |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3284 char_u *ffname_arg, |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3285 char_u *sfname_arg, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3286 int message) // give message when buffer already exists |
7 | 3287 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3288 char_u *ffname = ffname_arg; |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3289 char_u *sfname = sfname_arg; |
42 | 3290 buf_T *obuf = NULL; |
7 | 3291 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3292 stat_T st; |
7 | 3293 #endif |
3294 | |
3295 if (ffname == NULL || *ffname == NUL) | |
3296 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3297 // Removing the name. |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3298 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3299 VIM_CLEAR(buf->b_sfname); |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3300 else |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3301 buf->b_sfname = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
3302 VIM_CLEAR(buf->b_ffname); |
7 | 3303 #ifdef UNIX |
3304 st.st_dev = (dev_T)-1; | |
3305 #endif | |
3306 } | |
3307 else | |
3308 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3309 fname_expand(buf, &ffname, &sfname); // will allocate ffname |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3310 if (ffname == NULL) // out of memory |
7 | 3311 return FAIL; |
3312 | |
3313 /* | |
3314 * if the file name is already used in another buffer: | |
3315 * - if the buffer is loaded, fail | |
3316 * - if the buffer is not loaded, delete it from the list | |
3317 */ | |
3318 #ifdef UNIX | |
3319 if (mch_stat((char *)ffname, &st) < 0) | |
3320 st.st_dev = (dev_T)-1; | |
42 | 3321 #endif |
3322 if (!(buf->b_flags & BF_DUMMY)) | |
3323 #ifdef UNIX | |
3324 obuf = buflist_findname_stat(ffname, &st); | |
7 | 3325 #else |
42 | 3326 obuf = buflist_findname(ffname); |
7 | 3327 #endif |
3328 if (obuf != NULL && obuf != buf) | |
3329 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3330 if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail |
7 | 3331 { |
3332 if (message) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
3333 emsg(_("E95: Buffer with this name already exists")); |
7 | 3334 vim_free(ffname); |
3335 return FAIL; | |
3336 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3337 // delete from the list |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
3338 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE, FALSE); |
7 | 3339 } |
3340 sfname = vim_strsave(sfname); | |
3341 if (ffname == NULL || sfname == NULL) | |
3342 { | |
3343 vim_free(sfname); | |
3344 vim_free(ffname); | |
3345 return FAIL; | |
3346 } | |
3347 #ifdef USE_FNAME_CASE | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3348 fname_case(sfname, 0); // set correct case for short file name |
7 | 3349 #endif |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3350 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3351 vim_free(buf->b_sfname); |
7 | 3352 vim_free(buf->b_ffname); |
3353 buf->b_ffname = ffname; | |
3354 buf->b_sfname = sfname; | |
3355 } | |
3356 buf->b_fname = buf->b_sfname; | |
3357 #ifdef UNIX | |
3358 if (st.st_dev == (dev_T)-1) | |
1873 | 3359 buf->b_dev_valid = FALSE; |
7 | 3360 else |
3361 { | |
1873 | 3362 buf->b_dev_valid = TRUE; |
7 | 3363 buf->b_dev = st.st_dev; |
3364 buf->b_ino = st.st_ino; | |
3365 } | |
3366 #endif | |
3367 | |
3368 buf->b_shortname = FALSE; | |
3369 | |
3370 buf_name_changed(buf); | |
3371 return OK; | |
3372 } | |
3373 | |
3374 /* | |
41 | 3375 * Crude way of changing the name of a buffer. Use with care! |
3376 * The name should be relative to the current directory. | |
3377 */ | |
3378 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3379 buf_set_name(int fnum, char_u *name) |
41 | 3380 { |
3381 buf_T *buf; | |
3382 | |
3383 buf = buflist_findnr(fnum); | |
3384 if (buf != NULL) | |
3385 { | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3386 if (buf->b_sfname != buf->b_ffname) |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
3387 vim_free(buf->b_sfname); |
41 | 3388 vim_free(buf->b_ffname); |
844 | 3389 buf->b_ffname = vim_strsave(name); |
3390 buf->b_sfname = NULL; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3391 // Allocate ffname and expand into full path. Also resolves .lnk |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3392 // files on Win32. |
844 | 3393 fname_expand(buf, &buf->b_ffname, &buf->b_sfname); |
41 | 3394 buf->b_fname = buf->b_sfname; |
3395 } | |
3396 } | |
3397 | |
3398 /* | |
7 | 3399 * Take care of what needs to be done when the name of buffer "buf" has |
3400 * changed. | |
3401 */ | |
3402 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3403 buf_name_changed(buf_T *buf) |
7 | 3404 { |
3405 /* | |
3406 * If the file name changed, also change the name of the swapfile | |
3407 */ | |
3408 if (buf->b_ml.ml_mfp != NULL) | |
3409 ml_setname(buf); | |
3410 | |
3411 if (curwin->w_buffer == buf) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3412 check_arg_idx(curwin); // check file name for arg list |
7 | 3413 #ifdef FEAT_TITLE |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3414 maketitle(); // set window title |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3415 #endif |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3416 status_redraw_all(); // status lines need to be redrawn |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3417 fmarks_check_names(buf); // check named file marks |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3418 ml_timestamp(buf); // reset timestamp |
7 | 3419 } |
3420 | |
3421 /* | |
3422 * set alternate file name for current window | |
3423 * | |
3424 * Used by do_one_cmd(), do_write() and do_ecmd(). | |
3425 * Return the buffer. | |
3426 */ | |
3427 buf_T * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3428 setaltfname( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3429 char_u *ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3430 char_u *sfname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3431 linenr_T lnum) |
7 | 3432 { |
3433 buf_T *buf; | |
3434 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3435 // Create a buffer. 'buflisted' is not set if it's a new buffer |
7 | 3436 buf = buflist_new(ffname, sfname, lnum, 0); |
22 | 3437 if (buf != NULL && !cmdmod.keepalt) |
7 | 3438 curwin->w_alt_fnum = buf->b_fnum; |
3439 return buf; | |
3440 } | |
3441 | |
3442 /* | |
3443 * Get alternate file name for current window. | |
3444 * Return NULL if there isn't any, and give error message if requested. | |
3445 */ | |
3446 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3447 getaltfname( |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3448 int errmsg) // give error message |
7 | 3449 { |
3450 char_u *fname; | |
3451 linenr_T dummy; | |
3452 | |
3453 if (buflist_name_nr(0, &fname, &dummy) == FAIL) | |
3454 { | |
3455 if (errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
3456 emsg(_(e_noalt)); |
7 | 3457 return NULL; |
3458 } | |
3459 return fname; | |
3460 } | |
3461 | |
3462 /* | |
3463 * Add a file name to the buflist and return its number. | |
3464 * Uses same flags as buflist_new(), except BLN_DUMMY. | |
3465 * | |
3466 * used by qf_init(), main() and doarglist() | |
3467 */ | |
3468 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3469 buflist_add(char_u *fname, int flags) |
7 | 3470 { |
3471 buf_T *buf; | |
3472 | |
3473 buf = buflist_new(fname, NULL, (linenr_T)0, flags); | |
3474 if (buf != NULL) | |
3475 return buf->b_fnum; | |
3476 return 0; | |
3477 } | |
3478 | |
3479 #if defined(BACKSLASH_IN_FILENAME) || defined(PROTO) | |
3480 /* | |
3481 * Adjust slashes in file names. Called after 'shellslash' was set. | |
3482 */ | |
3483 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3484 buflist_slash_adjust(void) |
7 | 3485 { |
3486 buf_T *bp; | |
3487 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
3488 FOR_ALL_BUFFERS(bp) |
7 | 3489 { |
3490 if (bp->b_ffname != NULL) | |
3491 slash_adjust(bp->b_ffname); | |
3492 if (bp->b_sfname != NULL) | |
3493 slash_adjust(bp->b_sfname); | |
3494 } | |
3495 } | |
3496 #endif | |
3497 | |
3498 /* | |
1743 | 3499 * Set alternate cursor position for the current buffer and window "win". |
7 | 3500 * Also save the local window option values. |
3501 */ | |
3502 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3503 buflist_altfpos(win_T *win) |
7 | 3504 { |
1743 | 3505 buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE); |
7 | 3506 } |
3507 | |
3508 /* | |
3509 * Return TRUE if 'ffname' is not the same file as current file. | |
3510 * Fname must have a full path (expanded by mch_FullName()). | |
3511 */ | |
3512 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3513 otherfile(char_u *ffname) |
7 | 3514 { |
3515 return otherfile_buf(curbuf, ffname | |
3516 #ifdef UNIX | |
3517 , NULL | |
3518 #endif | |
3519 ); | |
3520 } | |
3521 | |
3522 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3523 otherfile_buf( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3524 buf_T *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3525 char_u *ffname |
7 | 3526 #ifdef UNIX |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3527 , stat_T *stp |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3528 #endif |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3529 ) |
7 | 3530 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3531 // no name is different |
7 | 3532 if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) |
3533 return TRUE; | |
3534 if (fnamecmp(ffname, buf->b_ffname) == 0) | |
3535 return FALSE; | |
3536 #ifdef UNIX | |
3537 { | |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3538 stat_T st; |
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3539 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3540 // If no stat_T given, get it now |
7 | 3541 if (stp == NULL) |
3542 { | |
1873 | 3543 if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) |
7 | 3544 st.st_dev = (dev_T)-1; |
3545 stp = &st; | |
3546 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3547 // Use dev/ino to check if the files are the same, even when the names |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3548 // are different (possible with links). Still need to compare the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3549 // name above, for when the file doesn't exist yet. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3550 // Problem: The dev/ino changes when a file is deleted (and created |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3551 // again) and remains the same when renamed/moved. We don't want to |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3552 // mch_stat() each buffer each time, that would be too slow. Get the |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3553 // dev/ino again when they appear to match, but not when they appear |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3554 // to be different: Could skip a buffer when it's actually the same |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3555 // file. |
7 | 3556 if (buf_same_ino(buf, stp)) |
3557 { | |
3558 buf_setino(buf); | |
3559 if (buf_same_ino(buf, stp)) | |
3560 return FALSE; | |
3561 } | |
3562 } | |
3563 #endif | |
3564 return TRUE; | |
3565 } | |
3566 | |
3567 #if defined(UNIX) || defined(PROTO) | |
3568 /* | |
3569 * Set inode and device number for a buffer. | |
3570 * Must always be called when b_fname is changed!. | |
3571 */ | |
3572 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3573 buf_setino(buf_T *buf) |
7 | 3574 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3575 stat_T st; |
7 | 3576 |
3577 if (buf->b_fname != NULL && mch_stat((char *)buf->b_fname, &st) >= 0) | |
3578 { | |
1873 | 3579 buf->b_dev_valid = TRUE; |
7 | 3580 buf->b_dev = st.st_dev; |
3581 buf->b_ino = st.st_ino; | |
3582 } | |
3583 else | |
1873 | 3584 buf->b_dev_valid = FALSE; |
7 | 3585 } |
3586 | |
3587 /* | |
3588 * Return TRUE if dev/ino in buffer "buf" matches with "stp". | |
3589 */ | |
3590 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3591 buf_same_ino( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3592 buf_T *buf, |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9228
diff
changeset
|
3593 stat_T *stp) |
7 | 3594 { |
1873 | 3595 return (buf->b_dev_valid |
7 | 3596 && stp->st_dev == buf->b_dev |
3597 && stp->st_ino == buf->b_ino); | |
3598 } | |
3599 #endif | |
3600 | |
667 | 3601 /* |
3602 * Print info about the current buffer. | |
3603 */ | |
7 | 3604 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3605 fileinfo( |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3606 int fullname, // when non-zero print full path |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3607 int shorthelp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3608 int dont_truncate) |
7 | 3609 { |
3610 char_u *name; | |
3611 int n; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3612 char *p; |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3613 char *buffer; |
272 | 3614 size_t len; |
7 | 3615 |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16778
diff
changeset
|
3616 buffer = alloc(IOSIZE); |
7 | 3617 if (buffer == NULL) |
3618 return; | |
3619 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3620 if (fullname > 1) // 2 CTRL-G: include buffer number |
7 | 3621 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3622 vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); |
7 | 3623 p = buffer + STRLEN(buffer); |
3624 } | |
3625 else | |
3626 p = buffer; | |
3627 | |
3628 *p++ = '"'; | |
3629 if (buf_spname(curbuf) != NULL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3630 vim_strncpy((char_u *)p, buf_spname(curbuf), IOSIZE - (p - buffer) - 1); |
7 | 3631 else |
3632 { | |
3633 if (!fullname && curbuf->b_fname != NULL) | |
3634 name = curbuf->b_fname; | |
3635 else | |
3636 name = curbuf->b_ffname; | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3637 home_replace(shorthelp ? curbuf : NULL, name, (char_u *)p, |
7 | 3638 (int)(IOSIZE - (p - buffer)), TRUE); |
3639 } | |
3640 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3641 vim_snprintf_add(buffer, IOSIZE, "\"%s%s%s%s%s%s", |
7 | 3642 curbufIsChanged() ? (shortmess(SHM_MOD) |
3643 ? " [+]" : _(" [Modified]")) : " ", | |
3644 (curbuf->b_flags & BF_NOTEDITED) | |
3645 #ifdef FEAT_QUICKFIX | |
3646 && !bt_dontwrite(curbuf) | |
3647 #endif | |
3648 ? _("[Not edited]") : "", | |
3649 (curbuf->b_flags & BF_NEW) | |
3650 #ifdef FEAT_QUICKFIX | |
3651 && !bt_dontwrite(curbuf) | |
3652 #endif | |
3653 ? _("[New file]") : "", | |
3654 (curbuf->b_flags & BF_READERR) ? _("[Read errors]") : "", | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
3655 curbuf->b_p_ro ? (shortmess(SHM_RO) ? _("[RO]") |
7 | 3656 : _("[readonly]")) : "", |
3657 (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) | |
3658 || curbuf->b_p_ro) ? | |
3659 " " : ""); | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3660 // With 32 bit longs and more than 21,474,836 lines multiplying by 100 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3661 // causes an overflow, thus for large numbers divide instead. |
7 | 3662 if (curwin->w_cursor.lnum > 1000000L) |
3663 n = (int)(((long)curwin->w_cursor.lnum) / | |
3664 ((long)curbuf->b_ml.ml_line_count / 100L)); | |
3665 else | |
3666 n = (int)(((long)curwin->w_cursor.lnum * 100L) / | |
3667 (long)curbuf->b_ml.ml_line_count); | |
3668 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3669 vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); |
7 | 3670 #ifdef FEAT_CMDL_INFO |
3671 else if (p_ru) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3672 // Current line and column are already on the screen -- webb |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3673 vim_snprintf_add(buffer, IOSIZE, |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3674 NGETTEXT("%ld line --%d%%--", "%ld lines --%d%%--", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3675 curbuf->b_ml.ml_line_count), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14509
diff
changeset
|
3676 (long)curbuf->b_ml.ml_line_count, n); |
7 | 3677 #endif |
3678 else | |
3679 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3680 vim_snprintf_add(buffer, IOSIZE, |
7 | 3681 _("line %ld of %ld --%d%%-- col "), |
3682 (long)curwin->w_cursor.lnum, | |
3683 (long)curbuf->b_ml.ml_line_count, | |
3684 n); | |
3685 validate_virtcol(); | |
1869 | 3686 len = STRLEN(buffer); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3687 col_print((char_u *)buffer + len, IOSIZE - len, |
7 | 3688 (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); |
3689 } | |
3690 | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3691 (void)append_arg_number(curwin, (char_u *)buffer, IOSIZE, |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3692 !shortmess(SHM_FILE)); |
7 | 3693 |
3694 if (dont_truncate) | |
3695 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3696 // Temporarily set msg_scroll to avoid the message being truncated. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3697 // First call msg_start() to get the message in the right place. |
7 | 3698 msg_start(); |
3699 n = msg_scroll; | |
3700 msg_scroll = TRUE; | |
3701 msg(buffer); | |
3702 msg_scroll = n; | |
3703 } | |
3704 else | |
3705 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3706 p = (char *)msg_trunc_attr(buffer, FALSE, 0); |
7 | 3707 if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3708 // Need to repeat the message after redrawing when: |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3709 // - When restart_edit is set (otherwise there will be a delay |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3710 // before redrawing). |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3711 // - When the screen was scrolled but there is no wait-return |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3712 // prompt. |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15510
diff
changeset
|
3713 set_keep_msg((char_u *)p, 0); |
7 | 3714 } |
3715 | |
3716 vim_free(buffer); | |
3717 } | |
3718 | |
3719 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3720 col_print( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3721 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3722 size_t buflen, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3723 int col, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3724 int vcol) |
7 | 3725 { |
3726 if (col == vcol) | |
1869 | 3727 vim_snprintf((char *)buf, buflen, "%d", col); |
7 | 3728 else |
1869 | 3729 vim_snprintf((char *)buf, buflen, "%d-%d", col, vcol); |
7 | 3730 } |
3731 | |
3732 #if defined(FEAT_TITLE) || defined(PROTO) | |
3733 static char_u *lasttitle = NULL; | |
3734 static char_u *lasticon = NULL; | |
3735 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3736 /* |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3737 * Put the file name in the title bar and icon of the window. |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3738 */ |
7 | 3739 void |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3740 maketitle(void) |
7 | 3741 { |
3742 char_u *p; | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3743 char_u *title_str = NULL; |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3744 char_u *icon_str = NULL; |
7 | 3745 int maxlen = 0; |
3746 int len; | |
3747 int mustset; | |
3748 char_u buf[IOSIZE]; | |
3749 int off; | |
3750 | |
3751 if (!redrawing()) | |
3752 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3753 // Postpone updating the title when 'lazyredraw' is set. |
7 | 3754 need_maketitle = TRUE; |
3755 return; | |
3756 } | |
3757 | |
3758 need_maketitle = FALSE; | |
2403
ce5a380d5144
Fix: when resetting both 'title' and 'icon' the title would be set after a
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
3759 if (!p_title && !p_icon && lasttitle == NULL && lasticon == NULL) |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3760 return; // nothing to do |
7 | 3761 |
3762 if (p_title) | |
3763 { | |
3764 if (p_titlelen > 0) | |
3765 { | |
3766 maxlen = p_titlelen * Columns / 100; | |
3767 if (maxlen < 10) | |
3768 maxlen = 10; | |
3769 } | |
3770 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3771 title_str = buf; |
7 | 3772 if (*p_titlestring != NUL) |
3773 { | |
3774 #ifdef FEAT_STL_OPT | |
771 | 3775 if (stl_syntax & STL_IN_TITLE) |
3776 { | |
3777 int use_sandbox = FALSE; | |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18886
diff
changeset
|
3778 int called_emsg_before = called_emsg; |
675 | 3779 |
3780 # ifdef FEAT_EVAL | |
771 | 3781 use_sandbox = was_set_insecurely((char_u *)"titlestring", 0); |
675 | 3782 # endif |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3783 build_stl_str_hl(curwin, title_str, sizeof(buf), |
675 | 3784 p_titlestring, use_sandbox, |
681 | 3785 0, maxlen, NULL, NULL); |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18886
diff
changeset
|
3786 if (called_emsg > called_emsg_before) |
771 | 3787 set_string_option_direct((char_u *)"titlestring", -1, |
3788 (char_u *)"", OPT_FREE, SID_ERROR); | |
3789 } | |
7 | 3790 else |
3791 #endif | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3792 title_str = p_titlestring; |
7 | 3793 } |
3794 else | |
3795 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3796 // format: "fname + (path) (1 of 2) - VIM" |
7 | 3797 |
3780 | 3798 #define SPACE_FOR_FNAME (IOSIZE - 100) |
3799 #define SPACE_FOR_DIR (IOSIZE - 20) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3800 #define SPACE_FOR_ARGNR (IOSIZE - 10) // at least room for " - VIM" |
7 | 3801 if (curbuf->b_fname == NULL) |
3780 | 3802 vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME); |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3803 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3804 else if (curbuf->b_term != NULL) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3805 { |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3806 vim_strncpy(buf, term_get_status_text(curbuf->b_term), |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3807 SPACE_FOR_FNAME); |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3808 } |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3809 #endif |
7 | 3810 else |
3811 { | |
3812 p = transstr(gettail(curbuf->b_fname)); | |
3780 | 3813 vim_strncpy(buf, p, SPACE_FOR_FNAME); |
7 | 3814 vim_free(p); |
3815 } | |
3816 | |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3817 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3818 if (curbuf->b_term == NULL) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3819 #endif |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3820 switch (bufIsChanged(curbuf) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3821 + (curbuf->b_p_ro * 2) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3822 + (!curbuf->b_p_ma * 4)) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3823 { |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3824 case 1: STRCAT(buf, " +"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3825 case 2: STRCAT(buf, " ="); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3826 case 3: STRCAT(buf, " =+"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3827 case 4: |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3828 case 6: STRCAT(buf, " -"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3829 case 5: |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3830 case 7: STRCAT(buf, " -+"); break; |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3831 } |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3832 |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3833 if (curbuf->b_fname != NULL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3834 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3835 && curbuf->b_term == NULL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3836 #endif |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3837 ) |
7 | 3838 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3839 // Get path of file, replace home dir with ~ |
7 | 3840 off = (int)STRLEN(buf); |
3841 buf[off++] = ' '; | |
3842 buf[off++] = '('; | |
3843 home_replace(curbuf, curbuf->b_ffname, | |
3780 | 3844 buf + off, SPACE_FOR_DIR - off, TRUE); |
7 | 3845 #ifdef BACKSLASH_IN_FILENAME |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3846 // avoid "c:/name" to be reduced to "c" |
7 | 3847 if (isalpha(buf[off]) && buf[off + 1] == ':') |
3848 off += 2; | |
3849 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3850 // remove the file name |
39 | 3851 p = gettail_sep(buf + off); |
7 | 3852 if (p == buf + off) |
11757
74abb6c84984
patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents:
11690
diff
changeset
|
3853 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3854 // must be a help buffer |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
3855 vim_strncpy(buf + off, (char_u *)_("help"), |
3780 | 3856 (size_t)(SPACE_FOR_DIR - off - 1)); |
11757
74abb6c84984
patch 8.0.0761: options not set properly for a terminal buffer
Christian Brabandt <cb@256bit.org>
parents:
11690
diff
changeset
|
3857 } |
7 | 3858 else |
3859 *p = NUL; | |
39 | 3860 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3861 // Translate unprintable chars and concatenate. Keep some |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3862 // room for the server name. When there is no room (very long |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3863 // file name) use (...). |
3780 | 3864 if (off < SPACE_FOR_DIR) |
3865 { | |
3866 p = transstr(buf + off); | |
3867 vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off)); | |
3868 vim_free(p); | |
3869 } | |
3870 else | |
3871 { | |
3872 vim_strncpy(buf + off, (char_u *)"...", | |
3873 (size_t)(SPACE_FOR_ARGNR - off)); | |
3874 } | |
7 | 3875 STRCAT(buf, ")"); |
3876 } | |
3877 | |
3780 | 3878 append_arg_number(curwin, buf, SPACE_FOR_ARGNR, FALSE); |
7 | 3879 |
3880 #if defined(FEAT_CLIENTSERVER) | |
3881 if (serverName != NULL) | |
3882 { | |
3883 STRCAT(buf, " - "); | |
2768 | 3884 vim_strcat(buf, serverName, IOSIZE); |
7 | 3885 } |
3886 else | |
3887 #endif | |
3888 STRCAT(buf, " - VIM"); | |
3889 | |
3890 if (maxlen > 0) | |
3891 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3892 // make it shorter by removing a bit in the middle |
3277 | 3893 if (vim_strsize(buf) > maxlen) |
3894 trunc_string(buf, buf, maxlen, IOSIZE); | |
7 | 3895 } |
3896 } | |
3897 } | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3898 mustset = value_changed(title_str, &lasttitle); |
7 | 3899 |
3900 if (p_icon) | |
3901 { | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3902 icon_str = buf; |
7 | 3903 if (*p_iconstring != NUL) |
3904 { | |
3905 #ifdef FEAT_STL_OPT | |
771 | 3906 if (stl_syntax & STL_IN_ICON) |
3907 { | |
3908 int use_sandbox = FALSE; | |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18886
diff
changeset
|
3909 int called_emsg_before = called_emsg; |
675 | 3910 |
3911 # ifdef FEAT_EVAL | |
771 | 3912 use_sandbox = was_set_insecurely((char_u *)"iconstring", 0); |
675 | 3913 # endif |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3914 build_stl_str_hl(curwin, icon_str, sizeof(buf), |
675 | 3915 p_iconstring, use_sandbox, |
681 | 3916 0, 0, NULL, NULL); |
18949
5c405689da3e
patch 8.2.0035: saving and restoring called_emsg is clumsy
Bram Moolenaar <Bram@vim.org>
parents:
18886
diff
changeset
|
3917 if (called_emsg > called_emsg_before) |
771 | 3918 set_string_option_direct((char_u *)"iconstring", -1, |
3919 (char_u *)"", OPT_FREE, SID_ERROR); | |
3920 } | |
7 | 3921 else |
3922 #endif | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3923 icon_str = p_iconstring; |
7 | 3924 } |
3925 else | |
3926 { | |
3927 if (buf_spname(curbuf) != NULL) | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3928 p = buf_spname(curbuf); |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3929 else // use file name only in icon |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3930 p = gettail(curbuf->b_ffname); |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3931 *icon_str = NUL; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3932 // Truncate name at 100 bytes. |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3933 len = (int)STRLEN(p); |
7 | 3934 if (len > 100) |
3935 { | |
3936 len -= 100; | |
3937 if (has_mbyte) | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3938 len += (*mb_tail_off)(p, p + len) + 1; |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3939 p += len; |
7 | 3940 } |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3941 STRCPY(icon_str, p); |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3942 trans_characters(icon_str, IOSIZE); |
7 | 3943 } |
3944 } | |
3945 | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3946 mustset |= value_changed(icon_str, &lasticon); |
7 | 3947 |
3948 if (mustset) | |
3949 resettitle(); | |
3950 } | |
3951 | |
3952 /* | |
3953 * Used for title and icon: Check if "str" differs from "*last". Set "*last" | |
3954 * from "str" if it does. | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3955 * Return TRUE if resettitle() is to be called. |
7 | 3956 */ |
3957 static int | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3958 value_changed(char_u *str, char_u **last) |
7 | 3959 { |
3960 if ((str == NULL) != (*last == NULL) | |
3961 || (str != NULL && *last != NULL && STRCMP(str, *last) != 0)) | |
3962 { | |
3963 vim_free(*last); | |
3964 if (str == NULL) | |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3965 { |
7 | 3966 *last = NULL; |
14479
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14453
diff
changeset
|
3967 mch_restore_title( |
3375a8cbb442
patch 8.1.0253: saving and restoring window title does not always work
Christian Brabandt <cb@256bit.org>
parents:
14453
diff
changeset
|
3968 last == &lasttitle ? SAVE_RESTORE_TITLE : SAVE_RESTORE_ICON); |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3969 } |
7 | 3970 else |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3971 { |
7 | 3972 *last = vim_strsave(str); |
14087
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3973 return TRUE; |
1d25a3e8e03c
patch 8.1.0061: window title is wrong after resetting and setting 'title'
Christian Brabandt <cb@256bit.org>
parents:
14037
diff
changeset
|
3974 } |
7 | 3975 } |
3976 return FALSE; | |
3977 } | |
3978 | |
3979 /* | |
3980 * Put current window title back (used after calling a shell) | |
3981 */ | |
3982 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3983 resettitle(void) |
7 | 3984 { |
3985 mch_settitle(lasttitle, lasticon); | |
3986 } | |
358 | 3987 |
3988 # if defined(EXITFREE) || defined(PROTO) | |
3989 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3990 free_titles(void) |
358 | 3991 { |
3992 vim_free(lasttitle); | |
3993 vim_free(lasticon); | |
3994 } | |
3995 # endif | |
3996 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
3997 #endif // FEAT_TITLE |
7 | 3998 |
686 | 3999 #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) |
7 | 4000 /* |
675 | 4001 * Build a string from the status line items in "fmt". |
7 | 4002 * Return length of string in screen cells. |
4003 * | |
675 | 4004 * Normally works for window "wp", except when working for 'tabline' then it |
4005 * is "curwin". | |
4006 * | |
7 | 4007 * Items are drawn interspersed with the text that surrounds it |
4008 * Specials: %-<wid>(xxx%) => group, %= => middle marker, %< => truncation | |
4009 * Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional | |
4010 * | |
4011 * If maxwidth is not zero, the string will be filled at any middle marker | |
4012 * or truncated if too long, fillchar is used for all whitespace. | |
4013 */ | |
4014 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4015 build_stl_str_hl( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4016 win_T *wp, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4017 char_u *out, // buffer to write into != NameBuff |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4018 size_t outlen, // length of out[] |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4019 char_u *fmt, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4020 int use_sandbox UNUSED, // "fmt" was set insecurely, use sandbox |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4021 int fillchar, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4022 int maxwidth, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4023 struct stl_hlrec *hltab, // return: HL attributes (can be NULL) |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4024 struct stl_hlrec *tabtab) // return: tab page nrs (can be NULL) |
7 | 4025 { |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4026 linenr_T lnum; |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4027 size_t len; |
7 | 4028 char_u *p; |
4029 char_u *s; | |
4030 char_u *t; | |
4333 | 4031 int byteval; |
7 | 4032 #ifdef FEAT_EVAL |
12387
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4033 win_T *save_curwin; |
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4034 buf_T *save_curbuf; |
18746
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4035 int save_VIsual_active; |
7 | 4036 #endif |
4037 int empty_line; | |
4038 colnr_T virtcol; | |
4039 long l; | |
4040 long n; | |
4041 int prevchar_isflag; | |
4042 int prevchar_isitem; | |
4043 int itemisflag; | |
4044 int fillable; | |
4045 char_u *str; | |
4046 long num; | |
4047 int width; | |
4048 int itemcnt; | |
4049 int curitem; | |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4050 int group_end_userhl; |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4051 int group_start_userhl; |
7 | 4052 int groupitem[STL_MAX_ITEM]; |
4053 int groupdepth; | |
4054 struct stl_item | |
4055 { | |
4056 char_u *start; | |
4057 int minwid; | |
4058 int maxwid; | |
4059 enum | |
4060 { | |
4061 Normal, | |
4062 Empty, | |
4063 Group, | |
4064 Middle, | |
4065 Highlight, | |
681 | 4066 TabPage, |
7 | 4067 Trunc |
4068 } type; | |
4069 } item[STL_MAX_ITEM]; | |
4070 int minwid; | |
4071 int maxwid; | |
4072 int zeropad; | |
4073 char_u base; | |
4074 char_u opt; | |
4075 #define TMPLEN 70 | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4076 char_u buf_tmp[TMPLEN]; |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4077 char_u win_tmp[TMPLEN]; |
678 | 4078 char_u *usefmt = fmt; |
681 | 4079 struct stl_hlrec *sp; |
12387
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4080 int save_must_redraw = must_redraw; |
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4081 int save_redr_type = curwin->w_redr_type; |
678 | 4082 |
4083 #ifdef FEAT_EVAL | |
4084 /* | |
4085 * When the format starts with "%!" then evaluate it as an expression and | |
4086 * use the result as the actual format string. | |
4087 */ | |
4088 if (fmt[0] == '%' && fmt[1] == '!') | |
4089 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4090 typval_T tv; |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4091 |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4092 tv.v_type = VAR_NUMBER; |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4093 tv.vval.v_number = wp->w_id; |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4094 set_var((char_u *)"g:statusline_winid", &tv, FALSE); |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4095 |
678 | 4096 usefmt = eval_to_string_safe(fmt + 2, NULL, use_sandbox); |
4097 if (usefmt == NULL) | |
943 | 4098 usefmt = fmt; |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4099 |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4100 do_unlet((char_u *)"g:statusline_winid", TRUE); |
678 | 4101 } |
4102 #endif | |
7 | 4103 |
4104 if (fillchar == 0) | |
4105 fillchar = ' '; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4106 // Can't handle a multi-byte fill character yet. |
819 | 4107 else if (mb_char2len(fillchar) > 1) |
4108 fillchar = '-'; | |
4109 | |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4110 // The cursor in windows other than the current one isn't always |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4111 // up-to-date, esp. because of autocommands and timers. |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4112 lnum = wp->w_cursor.lnum; |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4113 if (lnum > wp->w_buffer->b_ml.ml_line_count) |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4114 { |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4115 lnum = wp->w_buffer->b_ml.ml_line_count; |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4116 wp->w_cursor.lnum = lnum; |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4117 } |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4118 |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4119 // Get line & check if empty (cursorpos will show "0-1"). Note that |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4120 // p will become invalid when getting another buffer line. |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4121 p = ml_get_buf(wp->w_buffer, lnum, FALSE); |
4333 | 4122 empty_line = (*p == NUL); |
4123 | |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4124 // Get the byte value now, in case we need it below. This is more efficient |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4125 // than making a copy of the line. |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4126 len = STRLEN(p); |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4127 if (wp->w_cursor.col > (colnr_T)len) |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4128 { |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4129 // Line may have changed since checking the cursor column, or the lnum |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4130 // was adjusted above. |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4131 wp->w_cursor.col = (colnr_T)len; |
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4132 wp->w_cursor.coladd = 0; |
4333 | 4133 byteval = 0; |
15557
c0560da7873e
patch 8.1.0786: ml_get error when updating the status line
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
4134 } |
4333 | 4135 else |
4136 byteval = (*mb_ptr2char)(p + wp->w_cursor.col); | |
7 | 4137 |
4138 groupdepth = 0; | |
4139 p = out; | |
4140 curitem = 0; | |
4141 prevchar_isflag = TRUE; | |
4142 prevchar_isitem = FALSE; | |
678 | 4143 for (s = usefmt; *s; ) |
7 | 4144 { |
2704 | 4145 if (curitem == STL_MAX_ITEM) |
4146 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4147 // There are too many items. Add the error code to the statusline |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4148 // to give the user a hint about what went wrong. |
2704 | 4149 if (p + 6 < out + outlen) |
4150 { | |
4151 mch_memmove(p, " E541", (size_t)5); | |
4152 p += 5; | |
4153 } | |
4154 break; | |
4155 } | |
4156 | |
7 | 4157 if (*s != NUL && *s != '%') |
4158 prevchar_isflag = prevchar_isitem = FALSE; | |
4159 | |
4160 /* | |
4161 * Handle up to the next '%' or the end. | |
4162 */ | |
4163 while (*s != NUL && *s != '%' && p + 1 < out + outlen) | |
4164 *p++ = *s++; | |
4165 if (*s == NUL || p + 1 >= out + outlen) | |
4166 break; | |
4167 | |
4168 /* | |
4169 * Handle one '%' item. | |
4170 */ | |
4171 s++; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4172 if (*s == NUL) // ignore trailing % |
2694 | 4173 break; |
7 | 4174 if (*s == '%') |
4175 { | |
4176 if (p + 1 >= out + outlen) | |
4177 break; | |
4178 *p++ = *s++; | |
4179 prevchar_isflag = prevchar_isitem = FALSE; | |
4180 continue; | |
4181 } | |
4182 if (*s == STL_MIDDLEMARK) | |
4183 { | |
4184 s++; | |
4185 if (groupdepth > 0) | |
4186 continue; | |
4187 item[curitem].type = Middle; | |
4188 item[curitem++].start = p; | |
4189 continue; | |
4190 } | |
4191 if (*s == STL_TRUNCMARK) | |
4192 { | |
4193 s++; | |
4194 item[curitem].type = Trunc; | |
4195 item[curitem++].start = p; | |
4196 continue; | |
4197 } | |
4198 if (*s == ')') | |
4199 { | |
4200 s++; | |
4201 if (groupdepth < 1) | |
4202 continue; | |
4203 groupdepth--; | |
4204 | |
4205 t = item[groupitem[groupdepth]].start; | |
4206 *p = NUL; | |
4207 l = vim_strsize(t); | |
4208 if (curitem > groupitem[groupdepth] + 1 | |
4209 && item[groupitem[groupdepth]].minwid == 0) | |
4210 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4211 // remove group if all items are empty and highlight group |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4212 // doesn't change |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4213 group_start_userhl = group_end_userhl = 0; |
12684
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4214 for (n = groupitem[groupdepth] - 1; n >= 0; n--) |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4215 { |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4216 if (item[n].type == Highlight) |
12684
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4217 { |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4218 group_start_userhl = group_end_userhl = item[n].minwid; |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4219 break; |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4220 } |
185f8dbdcf26
patch 8.0.1220: skipping empty statusline groups is not correct
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
4221 } |
7 | 4222 for (n = groupitem[groupdepth] + 1; n < curitem; n++) |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4223 { |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4224 if (item[n].type == Normal) |
7 | 4225 break; |
12660
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4226 if (item[n].type == Highlight) |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4227 group_end_userhl = item[n].minwid; |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4228 } |
ac6e56d8950e
patch 8.0.1208: 'statusline' drops empty group with highlight change
Christian Brabandt <cb@256bit.org>
parents:
12630
diff
changeset
|
4229 if (n == curitem && group_start_userhl == group_end_userhl) |
7 | 4230 { |
4231 p = t; | |
4232 l = 0; | |
19354
1d3b2ce65ae0
patch 8.2.0235: draw error when an empty group is removed from 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
4233 // do not use the highlighting from the removed group |
1d3b2ce65ae0
patch 8.2.0235: draw error when an empty group is removed from 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
4234 for (n = groupitem[groupdepth] + 1; n < curitem; n++) |
1d3b2ce65ae0
patch 8.2.0235: draw error when an empty group is removed from 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
4235 if (item[n].type == Highlight) |
1d3b2ce65ae0
patch 8.2.0235: draw error when an empty group is removed from 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
4236 item[n].type = Empty; |
7 | 4237 } |
4238 } | |
4239 if (l > item[groupitem[groupdepth]].maxwid) | |
4240 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4241 // truncate, remove n bytes of text at the start |
7 | 4242 if (has_mbyte) |
4243 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4244 // Find the first character that should be included. |
7 | 4245 n = 0; |
4246 while (l >= item[groupitem[groupdepth]].maxwid) | |
4247 { | |
4248 l -= ptr2cells(t + n); | |
474 | 4249 n += (*mb_ptr2len)(t + n); |
7 | 4250 } |
4251 } | |
4252 else | |
835 | 4253 n = (long)(p - t) - item[groupitem[groupdepth]].maxwid + 1; |
7 | 4254 |
4255 *t = '<'; | |
1869 | 4256 mch_memmove(t + 1, t + n, (size_t)(p - (t + n))); |
7 | 4257 p = p - n + 1; |
15595
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15557
diff
changeset
|
4258 |
1ec942f1b648
patch 8.1.0805: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15557
diff
changeset
|
4259 // Fill up space left over by half a double-wide char. |
7 | 4260 while (++l < item[groupitem[groupdepth]].minwid) |
4261 *p++ = fillchar; | |
4262 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4263 // correct the start of the items for the truncation |
7 | 4264 for (l = groupitem[groupdepth] + 1; l < curitem; l++) |
4265 { | |
4266 item[l].start -= n; | |
4267 if (item[l].start < t) | |
4268 item[l].start = t; | |
4269 } | |
4270 } | |
4271 else if (abs(item[groupitem[groupdepth]].minwid) > l) | |
4272 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4273 // fill |
7 | 4274 n = item[groupitem[groupdepth]].minwid; |
4275 if (n < 0) | |
4276 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4277 // fill by appending characters |
7 | 4278 n = 0 - n; |
4279 while (l++ < n && p + 1 < out + outlen) | |
4280 *p++ = fillchar; | |
4281 } | |
4282 else | |
4283 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4284 // fill by inserting characters |
1869 | 4285 mch_memmove(t + n - l, t, (size_t)(p - t)); |
7 | 4286 l = n - l; |
4287 if (p + l >= out + outlen) | |
835 | 4288 l = (long)((out + outlen) - p - 1); |
7 | 4289 p += l; |
4290 for (n = groupitem[groupdepth] + 1; n < curitem; n++) | |
4291 item[n].start += l; | |
4292 for ( ; l > 0; l--) | |
4293 *t++ = fillchar; | |
4294 } | |
4295 } | |
4296 continue; | |
4297 } | |
4298 minwid = 0; | |
4299 maxwid = 9999; | |
4300 zeropad = FALSE; | |
4301 l = 1; | |
4302 if (*s == '0') | |
4303 { | |
4304 s++; | |
4305 zeropad = TRUE; | |
4306 } | |
4307 if (*s == '-') | |
4308 { | |
4309 s++; | |
4310 l = -1; | |
4311 } | |
4312 if (VIM_ISDIGIT(*s)) | |
4313 { | |
4314 minwid = (int)getdigits(&s); | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4315 if (minwid < 0) // overflow |
7 | 4316 minwid = 0; |
4317 } | |
678 | 4318 if (*s == STL_USER_HL) |
7 | 4319 { |
4320 item[curitem].type = Highlight; | |
4321 item[curitem].start = p; | |
4322 item[curitem].minwid = minwid > 9 ? 1 : minwid; | |
4323 s++; | |
4324 curitem++; | |
4325 continue; | |
4326 } | |
681 | 4327 if (*s == STL_TABPAGENR || *s == STL_TABCLOSENR) |
4328 { | |
4329 if (*s == STL_TABCLOSENR) | |
4330 { | |
4331 if (minwid == 0) | |
4332 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4333 // %X ends the close label, go back to the previously |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4334 // define tab label nr. |
681 | 4335 for (n = curitem - 1; n >= 0; --n) |
4336 if (item[n].type == TabPage && item[n].minwid >= 0) | |
4337 { | |
4338 minwid = item[n].minwid; | |
4339 break; | |
4340 } | |
4341 } | |
4342 else | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4343 // close nrs are stored as negative values |
681 | 4344 minwid = - minwid; |
4345 } | |
4346 item[curitem].type = TabPage; | |
4347 item[curitem].start = p; | |
4348 item[curitem].minwid = minwid; | |
4349 s++; | |
4350 curitem++; | |
4351 continue; | |
4352 } | |
7 | 4353 if (*s == '.') |
4354 { | |
4355 s++; | |
4356 if (VIM_ISDIGIT(*s)) | |
4357 { | |
4358 maxwid = (int)getdigits(&s); | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4359 if (maxwid <= 0) // overflow |
7 | 4360 maxwid = 50; |
4361 } | |
4362 } | |
4363 minwid = (minwid > 50 ? 50 : minwid) * l; | |
4364 if (*s == '(') | |
4365 { | |
4366 groupitem[groupdepth++] = curitem; | |
4367 item[curitem].type = Group; | |
4368 item[curitem].start = p; | |
4369 item[curitem].minwid = minwid; | |
4370 item[curitem].maxwid = maxwid; | |
4371 s++; | |
4372 curitem++; | |
4373 continue; | |
4374 } | |
4375 if (vim_strchr(STL_ALL, *s) == NULL) | |
4376 { | |
4377 s++; | |
4378 continue; | |
4379 } | |
4380 opt = *s++; | |
4381 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4382 // OK - now for the real work |
7 | 4383 base = 'D'; |
4384 itemisflag = FALSE; | |
4385 fillable = TRUE; | |
4386 num = -1; | |
4387 str = NULL; | |
4388 switch (opt) | |
4389 { | |
4390 case STL_FILEPATH: | |
4391 case STL_FULLPATH: | |
4392 case STL_FILENAME: | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4393 fillable = FALSE; // don't change ' ' to fillchar |
7 | 4394 if (buf_spname(wp->w_buffer) != NULL) |
3839 | 4395 vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); |
7 | 4396 else |
4397 { | |
4398 t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname | |
667 | 4399 : wp->w_buffer->b_fname; |
7 | 4400 home_replace(wp->w_buffer, t, NameBuff, MAXPATHL, TRUE); |
4401 } | |
4402 trans_characters(NameBuff, MAXPATHL); | |
4403 if (opt != STL_FILENAME) | |
4404 str = NameBuff; | |
4405 else | |
4406 str = gettail(NameBuff); | |
4407 break; | |
4408 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4409 case STL_VIM_EXPR: // '{' |
7 | 4410 itemisflag = TRUE; |
4411 t = p; | |
4412 while (*s != '}' && *s != NUL && p + 1 < out + outlen) | |
4413 *p++ = *s++; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4414 if (*s != '}') // missing '}' or out of space |
7 | 4415 break; |
4416 s++; | |
4417 *p = 0; | |
4418 p = t; | |
4419 | |
4420 #ifdef FEAT_EVAL | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4421 vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4422 "%d", curbuf->b_fnum); |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4423 set_internal_string_var((char_u *)"g:actual_curbuf", buf_tmp); |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4424 vim_snprintf((char *)win_tmp, sizeof(win_tmp), "%d", curwin->w_id); |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4425 set_internal_string_var((char_u *)"g:actual_curwin", win_tmp); |
7 | 4426 |
12387
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4427 save_curbuf = curbuf; |
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4428 save_curwin = curwin; |
18746
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4429 save_VIsual_active = VIsual_active; |
7 | 4430 curwin = wp; |
4431 curbuf = wp->w_buffer; | |
18746
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4432 // Visual mode is only valid in the current window. |
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4433 if (curwin != save_curwin) |
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4434 VIsual_active = FALSE; |
7 | 4435 |
675 | 4436 str = eval_to_string_safe(p, &t, use_sandbox); |
7 | 4437 |
12387
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4438 curwin = save_curwin; |
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4439 curbuf = save_curbuf; |
18746
64eea864dff6
patch 8.1.2363: ml_get error when accessing Visual area in 'statusline'
Bram Moolenaar <Bram@vim.org>
parents:
18642
diff
changeset
|
4440 VIsual_active = save_VIsual_active; |
145 | 4441 do_unlet((char_u *)"g:actual_curbuf", TRUE); |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4442 do_unlet((char_u *)"g:actual_curwin", TRUE); |
7 | 4443 |
4444 if (str != NULL && *str != 0) | |
4445 { | |
4446 if (*skipdigits(str) == NUL) | |
4447 { | |
4448 num = atoi((char *)str); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13170
diff
changeset
|
4449 VIM_CLEAR(str); |
7 | 4450 itemisflag = FALSE; |
4451 } | |
4452 } | |
4453 #endif | |
4454 break; | |
4455 | |
4456 case STL_LINE: | |
4457 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) | |
4458 ? 0L : (long)(wp->w_cursor.lnum); | |
4459 break; | |
4460 | |
4461 case STL_NUMLINES: | |
4462 num = wp->w_buffer->b_ml.ml_line_count; | |
4463 break; | |
4464 | |
4465 case STL_COLUMN: | |
4466 num = !(State & INSERT) && empty_line | |
4467 ? 0 : (int)wp->w_cursor.col + 1; | |
4468 break; | |
4469 | |
4470 case STL_VIRTCOL: | |
4471 case STL_VIRTCOL_ALT: | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4472 // In list mode virtcol needs to be recomputed |
7 | 4473 virtcol = wp->w_virtcol; |
4474 if (wp->w_p_list && lcs_tab1 == NUL) | |
4475 { | |
4476 wp->w_p_list = FALSE; | |
4477 getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
4478 wp->w_p_list = TRUE; | |
4479 } | |
4480 ++virtcol; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4481 // Don't display %V if it's the same as %c. |
7 | 4482 if (opt == STL_VIRTCOL_ALT |
4483 && (virtcol == (colnr_T)(!(State & INSERT) && empty_line | |
4484 ? 0 : (int)wp->w_cursor.col + 1))) | |
4485 break; | |
4486 num = (long)virtcol; | |
4487 break; | |
4488 | |
4489 case STL_PERCENTAGE: | |
4490 num = (int)(((long)wp->w_cursor.lnum * 100L) / | |
4491 (long)wp->w_buffer->b_ml.ml_line_count); | |
4492 break; | |
4493 | |
4494 case STL_ALTPERCENT: | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4495 str = buf_tmp; |
1869 | 4496 get_rel_pos(wp, str, TMPLEN); |
7 | 4497 break; |
4498 | |
4499 case STL_ARGLISTSTAT: | |
4500 fillable = FALSE; | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4501 buf_tmp[0] = 0; |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4502 if (append_arg_number(wp, buf_tmp, (int)sizeof(buf_tmp), FALSE)) |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4503 str = buf_tmp; |
7 | 4504 break; |
4505 | |
4506 case STL_KEYMAP: | |
4507 fillable = FALSE; | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4508 if (get_keymap_str(wp, (char_u *)"<%s>", buf_tmp, TMPLEN)) |
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4509 str = buf_tmp; |
7 | 4510 break; |
4511 case STL_PAGENUM: | |
706 | 4512 #if defined(FEAT_PRINTER) || defined(FEAT_GUI_TABLINE) |
686 | 4513 num = printer_page_num; |
7 | 4514 #else |
4515 num = 0; | |
4516 #endif | |
4517 break; | |
4518 | |
4519 case STL_BUFNO: | |
4520 num = wp->w_buffer->b_fnum; | |
4521 break; | |
4522 | |
4523 case STL_OFFSET_X: | |
4524 base = 'X'; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4525 // FALLTHROUGH |
7 | 4526 case STL_OFFSET: |
4527 #ifdef FEAT_BYTEOFF | |
4528 l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); | |
4529 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? | |
4530 0L : l + 1 + (!(State & INSERT) && empty_line ? | |
4531 0 : (int)wp->w_cursor.col); | |
4532 #endif | |
4533 break; | |
4534 | |
4535 case STL_BYTEVAL_X: | |
4536 base = 'X'; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4537 // FALLTHROUGH |
7 | 4538 case STL_BYTEVAL: |
4333 | 4539 num = byteval; |
7 | 4540 if (num == NL) |
4541 num = 0; | |
4542 else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC) | |
4543 num = NL; | |
4544 break; | |
4545 | |
4546 case STL_ROFLAG: | |
4547 case STL_ROFLAG_ALT: | |
4548 itemisflag = TRUE; | |
4549 if (wp->w_buffer->b_p_ro) | |
4795
8360a59aa04b
updated for version 7.3.1144
Bram Moolenaar <bram@vim.org>
parents:
4354
diff
changeset
|
4550 str = (char_u *)((opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]")); |
7 | 4551 break; |
4552 | |
4553 case STL_HELPFLAG: | |
4554 case STL_HELPFLAG_ALT: | |
4555 itemisflag = TRUE; | |
4556 if (wp->w_buffer->b_help) | |
4557 str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" | |
809 | 4558 : _("[Help]")); |
7 | 4559 break; |
4560 | |
4561 case STL_FILETYPE: | |
4562 if (*wp->w_buffer->b_p_ft != NUL | |
4563 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) | |
4564 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4565 vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), "[%s]", |
272 | 4566 wp->w_buffer->b_p_ft); |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4567 str = buf_tmp; |
7 | 4568 } |
4569 break; | |
4570 | |
4571 case STL_FILETYPE_ALT: | |
4572 itemisflag = TRUE; | |
4573 if (*wp->w_buffer->b_p_ft != NUL | |
4574 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 2) | |
4575 { | |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4576 vim_snprintf((char *)buf_tmp, sizeof(buf_tmp), ",%s", |
272 | 4577 wp->w_buffer->b_p_ft); |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4578 for (t = buf_tmp; *t != 0; t++) |
7 | 4579 *t = TOUPPER_LOC(*t); |
16740
dc85d49349f7
patch 8.1.1372: when evaluating 'statusline' the current window is unknown
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
4580 str = buf_tmp; |
7 | 4581 } |
4582 break; | |
4583 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
4584 #if defined(FEAT_QUICKFIX) |
7 | 4585 case STL_PREVIEWFLAG: |
4586 case STL_PREVIEWFLAG_ALT: | |
4587 itemisflag = TRUE; | |
4588 if (wp->w_p_pvw) | |
4589 str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" | |
4590 : _("[Preview]")); | |
4591 break; | |
2411
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4592 |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4593 case STL_QUICKFIX: |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4594 if (bt_quickfix(wp->w_buffer)) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4595 str = (char_u *)(wp->w_llist_ref |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4596 ? _(msg_loclist) |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4597 : _(msg_qflist)); |
68e394361ca3
Add "q" item for 'statusline'. Add w:quickfix_title. (Lech Lorens)
Bram Moolenaar <bram@vim.org>
parents:
2403
diff
changeset
|
4598 break; |
7 | 4599 #endif |
4600 | |
4601 case STL_MODIFIED: | |
4602 case STL_MODIFIED_ALT: | |
4603 itemisflag = TRUE; | |
4604 switch ((opt == STL_MODIFIED_ALT) | |
4605 + bufIsChanged(wp->w_buffer) * 2 | |
4606 + (!wp->w_buffer->b_p_ma) * 4) | |
4607 { | |
4608 case 2: str = (char_u *)"[+]"; break; | |
4609 case 3: str = (char_u *)",+"; break; | |
4610 case 4: str = (char_u *)"[-]"; break; | |
4611 case 5: str = (char_u *)",-"; break; | |
4612 case 6: str = (char_u *)"[+-]"; break; | |
4613 case 7: str = (char_u *)",+-"; break; | |
4614 } | |
4615 break; | |
678 | 4616 |
4617 case STL_HIGHLIGHT: | |
4618 t = s; | |
4619 while (*s != '#' && *s != NUL) | |
4620 ++s; | |
4621 if (*s == '#') | |
4622 { | |
4623 item[curitem].type = Highlight; | |
4624 item[curitem].start = p; | |
835 | 4625 item[curitem].minwid = -syn_namen2id(t, (int)(s - t)); |
678 | 4626 curitem++; |
4627 } | |
5407 | 4628 if (*s != NUL) |
4629 ++s; | |
678 | 4630 continue; |
7 | 4631 } |
4632 | |
4633 item[curitem].start = p; | |
4634 item[curitem].type = Normal; | |
4635 if (str != NULL && *str) | |
4636 { | |
4637 t = str; | |
4638 if (itemisflag) | |
4639 { | |
4640 if ((t[0] && t[1]) | |
4641 && ((!prevchar_isitem && *t == ',') | |
4642 || (prevchar_isflag && *t == ' '))) | |
4643 t++; | |
4644 prevchar_isflag = TRUE; | |
4645 } | |
4646 l = vim_strsize(t); | |
4647 if (l > 0) | |
4648 prevchar_isitem = TRUE; | |
4649 if (l > maxwid) | |
4650 { | |
4651 while (l >= maxwid) | |
4652 if (has_mbyte) | |
4653 { | |
4654 l -= ptr2cells(t); | |
474 | 4655 t += (*mb_ptr2len)(t); |
7 | 4656 } |
4657 else | |
4658 l -= byte2cells(*t++); | |
4659 if (p + 1 >= out + outlen) | |
4660 break; | |
4661 *p++ = '<'; | |
4662 } | |
4663 if (minwid > 0) | |
4664 { | |
4665 for (; l < minwid && p + 1 < out + outlen; l++) | |
4666 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4667 // Don't put a "-" in front of a digit. |
7 | 4668 if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) |
4669 *p++ = ' '; | |
4670 else | |
4671 *p++ = fillchar; | |
4672 } | |
4673 minwid = 0; | |
4674 } | |
4675 else | |
4676 minwid *= -1; | |
4677 while (*t && p + 1 < out + outlen) | |
4678 { | |
4679 *p++ = *t++; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4680 // Change a space by fillchar, unless fillchar is '-' and a |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4681 // digit follows. |
7 | 4682 if (fillable && p[-1] == ' ' |
4683 && (!VIM_ISDIGIT(*t) || fillchar != '-')) | |
4684 p[-1] = fillchar; | |
4685 } | |
4686 for (; l < minwid && p + 1 < out + outlen; l++) | |
4687 *p++ = fillchar; | |
4688 } | |
4689 else if (num >= 0) | |
4690 { | |
4691 int nbase = (base == 'D' ? 10 : (base == 'O' ? 8 : 16)); | |
4692 char_u nstr[20]; | |
4693 | |
4694 if (p + 20 >= out + outlen) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4695 break; // not sufficient space |
7 | 4696 prevchar_isitem = TRUE; |
4697 t = nstr; | |
4698 if (opt == STL_VIRTCOL_ALT) | |
4699 { | |
4700 *t++ = '-'; | |
4701 minwid--; | |
4702 } | |
4703 *t++ = '%'; | |
4704 if (zeropad) | |
4705 *t++ = '0'; | |
4706 *t++ = '*'; | |
1869 | 4707 *t++ = nbase == 16 ? base : (char_u)(nbase == 8 ? 'o' : 'd'); |
7 | 4708 *t = 0; |
4709 | |
4710 for (n = num, l = 1; n >= nbase; n /= nbase) | |
4711 l++; | |
4712 if (opt == STL_VIRTCOL_ALT) | |
4713 l++; | |
4714 if (l > maxwid) | |
4715 { | |
4716 l += 2; | |
4717 n = l - maxwid; | |
4718 while (l-- > maxwid) | |
4719 num /= nbase; | |
4720 *t++ = '>'; | |
4721 *t++ = '%'; | |
4722 *t = t[-3]; | |
4723 *++t = 0; | |
272 | 4724 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4725 0, num, n); | |
7 | 4726 } |
4727 else | |
272 | 4728 vim_snprintf((char *)p, outlen - (p - out), (char *)nstr, |
4729 minwid, num); | |
7 | 4730 p += STRLEN(p); |
4731 } | |
4732 else | |
4733 item[curitem].type = Empty; | |
4734 | |
4735 if (opt == STL_VIM_EXPR) | |
4736 vim_free(str); | |
4737 | |
4738 if (num >= 0 || (!itemisflag && str && *str)) | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4739 prevchar_isflag = FALSE; // Item not NULL, but not a flag |
7 | 4740 curitem++; |
4741 } | |
4742 *p = NUL; | |
4743 itemcnt = curitem; | |
4744 | |
678 | 4745 #ifdef FEAT_EVAL |
4746 if (usefmt != fmt) | |
4747 vim_free(usefmt); | |
4748 #endif | |
4749 | |
7 | 4750 width = vim_strsize(out); |
4751 if (maxwidth > 0 && width > maxwidth) | |
4752 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4753 // Result is too long, must truncate somewhere. |
7 | 4754 l = 0; |
4755 if (itemcnt == 0) | |
4756 s = out; | |
4757 else | |
4758 { | |
4759 for ( ; l < itemcnt; l++) | |
4760 if (item[l].type == Trunc) | |
4761 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4762 // Truncate at %< item. |
7 | 4763 s = item[l].start; |
4764 break; | |
4765 } | |
4766 if (l == itemcnt) | |
4767 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4768 // No %< item, truncate first item. |
7 | 4769 s = item[0].start; |
4770 l = 0; | |
4771 } | |
4772 } | |
4773 | |
4774 if (width - vim_strsize(s) >= maxwidth) | |
4775 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4776 // Truncation mark is beyond max length |
7 | 4777 if (has_mbyte) |
4778 { | |
4779 s = out; | |
4780 width = 0; | |
4781 for (;;) | |
4782 { | |
4783 width += ptr2cells(s); | |
4784 if (width >= maxwidth) | |
4785 break; | |
474 | 4786 s += (*mb_ptr2len)(s); |
7 | 4787 } |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4788 // Fill up for half a double-wide character. |
7 | 4789 while (++width < maxwidth) |
4790 *s++ = fillchar; | |
4791 } | |
4792 else | |
4793 s = out + maxwidth - 1; | |
4794 for (l = 0; l < itemcnt; l++) | |
4795 if (item[l].start > s) | |
4796 break; | |
4797 itemcnt = l; | |
4798 *s++ = '>'; | |
4799 *s = 0; | |
4800 } | |
4801 else | |
4802 { | |
4803 if (has_mbyte) | |
4804 { | |
4805 n = 0; | |
4806 while (width >= maxwidth) | |
4807 { | |
4808 width -= ptr2cells(s + n); | |
474 | 4809 n += (*mb_ptr2len)(s + n); |
7 | 4810 } |
4811 } | |
4812 else | |
4813 n = width - maxwidth + 1; | |
4814 p = s + n; | |
1618 | 4815 STRMOVE(s + 1, p); |
7 | 4816 *s = '<'; |
4817 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4818 // Fill up for half a double-wide character. |
7 | 4819 while (++width < maxwidth) |
4820 { | |
4821 s = s + STRLEN(s); | |
4822 *s++ = fillchar; | |
4823 *s = NUL; | |
4824 } | |
4825 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4826 --n; // count the '<' |
7 | 4827 for (; l < itemcnt; l++) |
4828 { | |
4829 if (item[l].start - n >= s) | |
4830 item[l].start -= n; | |
4831 else | |
4832 item[l].start = s; | |
4833 } | |
4834 } | |
4835 width = maxwidth; | |
4836 } | |
4837 else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) | |
4838 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4839 // Apply STL_MIDDLE if any |
7 | 4840 for (l = 0; l < itemcnt; l++) |
4841 if (item[l].type == Middle) | |
4842 break; | |
4843 if (l < itemcnt) | |
4844 { | |
4845 p = item[l].start + maxwidth - width; | |
1618 | 4846 STRMOVE(p, item[l].start); |
7 | 4847 for (s = item[l].start; s < p; s++) |
4848 *s = fillchar; | |
4849 for (l++; l < itemcnt; l++) | |
4850 item[l].start += maxwidth - width; | |
4851 width = maxwidth; | |
4852 } | |
4853 } | |
4854 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4855 // Store the info about highlighting. |
681 | 4856 if (hltab != NULL) |
7 | 4857 { |
681 | 4858 sp = hltab; |
7 | 4859 for (l = 0; l < itemcnt; l++) |
4860 { | |
4861 if (item[l].type == Highlight) | |
4862 { | |
681 | 4863 sp->start = item[l].start; |
4864 sp->userhl = item[l].minwid; | |
4865 sp++; | |
7 | 4866 } |
4867 } | |
681 | 4868 sp->start = NULL; |
4869 sp->userhl = 0; | |
4870 } | |
4871 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4872 // Store the info about tab pages labels. |
681 | 4873 if (tabtab != NULL) |
4874 { | |
4875 sp = tabtab; | |
4876 for (l = 0; l < itemcnt; l++) | |
4877 { | |
4878 if (item[l].type == TabPage) | |
4879 { | |
4880 sp->start = item[l].start; | |
4881 sp->userhl = item[l].minwid; | |
4882 sp++; | |
4883 } | |
4884 } | |
4885 sp->start = NULL; | |
4886 sp->userhl = 0; | |
7 | 4887 } |
4888 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4889 // When inside update_screen we do not want redrawing a stausline, ruler, |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4890 // title, etc. to trigger another redraw, it may cause an endless loop. |
12572
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4891 if (updating_screen) |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4892 { |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4893 must_redraw = save_must_redraw; |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4894 curwin->w_redr_type = save_redr_type; |
31737ff54115
patch 8.0.1164: changing StatusLine highlight does not always work
Christian Brabandt <cb@256bit.org>
parents:
12479
diff
changeset
|
4895 } |
12387
1ecdbc207c1e
patch 8.0.1073: may get an endless loop if 'statusline' changes a highlight
Christian Brabandt <cb@256bit.org>
parents:
12267
diff
changeset
|
4896 |
7 | 4897 return width; |
4898 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4899 #endif // FEAT_STL_OPT |
7 | 4900 |
686 | 4901 #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ |
4902 || defined(FEAT_GUI_TABLINE) || defined(PROTO) | |
7 | 4903 /* |
1869 | 4904 * Get relative cursor position in window into "buf[buflen]", in the form 99%, |
4905 * using "Top", "Bot" or "All" when appropriate. | |
7 | 4906 */ |
4907 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4908 get_rel_pos( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4909 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4910 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4911 int buflen) |
7 | 4912 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4913 long above; // number of lines above window |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4914 long below; // number of lines below window |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4915 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4916 if (buflen < 3) // need at least 3 chars for writing |
6466 | 4917 return; |
7 | 4918 above = wp->w_topline - 1; |
4919 #ifdef FEAT_DIFF | |
4920 above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; | |
6975 | 4921 if (wp->w_topline == 1 && wp->w_topfill >= 1) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4922 above = 0; // All buffer lines are displayed and there is an |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4923 // indication of filler lines, that can be considered |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4924 // seeing all lines. |
7 | 4925 #endif |
4926 below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; | |
4927 if (below <= 0) | |
1869 | 4928 vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")), |
4929 (size_t)(buflen - 1)); | |
7 | 4930 else if (above <= 0) |
1869 | 4931 vim_strncpy(buf, (char_u *)_("Top"), (size_t)(buflen - 1)); |
7 | 4932 else |
1869 | 4933 vim_snprintf((char *)buf, (size_t)buflen, "%2d%%", above > 1000000L |
7 | 4934 ? (int)(above / ((above + below) / 100L)) |
4935 : (int)(above * 100L / (above + below))); | |
4936 } | |
4937 #endif | |
4938 | |
4939 /* | |
1869 | 4940 * Append (file 2 of 8) to "buf[buflen]", if editing more than one file. |
7 | 4941 * Return TRUE if it was appended. |
4942 */ | |
1869 | 4943 static int |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4944 append_arg_number( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4945 win_T *wp, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4946 char_u *buf, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4947 int buflen, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4948 int add_file) // Add "file" before the arg number |
7 | 4949 { |
4950 char_u *p; | |
4951 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4952 if (ARGCOUNT <= 1) // nothing to do |
7 | 4953 return FALSE; |
4954 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4955 p = buf + STRLEN(buf); // go to the end of the buffer |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
4956 if (p - buf + 35 >= buflen) // getting too long |
7 | 4957 return FALSE; |
4958 *p++ = ' '; | |
4959 *p++ = '('; | |
4960 if (add_file) | |
4961 { | |
4962 STRCPY(p, "file "); | |
4963 p += 5; | |
4964 } | |
1869 | 4965 vim_snprintf((char *)p, (size_t)(buflen - (p - buf)), |
4966 wp->w_arg_idx_invalid ? "(%d) of %d)" | |
7 | 4967 : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); |
4968 return TRUE; | |
4969 } | |
4970 | |
4971 /* | |
4972 * If fname is not a full path, make it a full path. | |
4973 * Returns pointer to allocated memory (NULL for failure). | |
4974 */ | |
4975 char_u * | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4976 fix_fname(char_u *fname) |
7 | 4977 { |
4978 /* | |
4979 * Force expanding the path always for Unix, because symbolic links may | |
4980 * mess up the full path name, even though it starts with a '/'. | |
4981 * Also expand when there is ".." in the file name, try to remove it, | |
4982 * because "c:/src/../README" is equal to "c:/README". | |
1420 | 4983 * Similarly "c:/src//file" is equal to "c:/src/file". |
7 | 4984 * For MS-Windows also expand names like "longna~1" to "longname". |
4985 */ | |
1082 | 4986 #ifdef UNIX |
7 | 4987 return FullName_save(fname, TRUE); |
4988 #else | |
1420 | 4989 if (!vim_isAbsName(fname) |
4990 || strstr((char *)fname, "..") != NULL | |
4991 || strstr((char *)fname, "//") != NULL | |
4992 # ifdef BACKSLASH_IN_FILENAME | |
4993 || strstr((char *)fname, "\\\\") != NULL | |
4994 # endif | |
8212
05b88224cea1
commit https://github.com/vim/vim/commit/48e330aff911be1c798c88a973af6437a8141fce
Christian Brabandt <cb@256bit.org>
parents:
7817
diff
changeset
|
4995 # if defined(MSWIN) |
7 | 4996 || vim_strchr(fname, '~') != NULL |
1420 | 4997 # endif |
7 | 4998 ) |
4999 return FullName_save(fname, FALSE); | |
5000 | |
5001 fname = vim_strsave(fname); | |
5002 | |
1420 | 5003 # ifdef USE_FNAME_CASE |
15794
0d8291665b59
patch 8.1.0904: USE_LONG_FNAME never defined
Bram Moolenaar <Bram@vim.org>
parents:
15774
diff
changeset
|
5004 if (fname != NULL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5005 fname_case(fname, 0); // set correct case for file name |
1420 | 5006 # endif |
7 | 5007 |
5008 return fname; | |
5009 #endif | |
5010 } | |
5011 | |
5012 /* | |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5013 * Make "*ffname" a full file name, set "*sfname" to "*ffname" if not NULL. |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5014 * "*ffname" becomes a pointer to allocated memory (or NULL). |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5015 * When resolving a link both "*sfname" and "*ffname" will point to the same |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5016 * allocated memory. |
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5017 * The "*ffname" and "*sfname" pointer values on call will not be freed. |
18498
9e6d5a4abb1c
patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
18463
diff
changeset
|
5018 * Note that the resulting "*ffname" pointer should be considered not allocated. |
7 | 5019 */ |
5020 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5021 fname_expand( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5022 buf_T *buf UNUSED, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5023 char_u **ffname, |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5024 char_u **sfname) |
7 | 5025 { |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5026 if (*ffname == NULL) // no file name given, nothing to do |
7 | 5027 return; |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5028 if (*sfname == NULL) // no short file name given, use ffname |
7 | 5029 *sfname = *ffname; |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5030 *ffname = fix_fname(*ffname); // expand to full path |
7 | 5031 |
5032 #ifdef FEAT_SHORTCUT | |
5033 if (!buf->b_p_bin) | |
5034 { | |
844 | 5035 char_u *rfname; |
7 | 5036 |
14917
6f2ce3b311de
patch 8.1.0470: pointer ownership around fname_expand() is unclear
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5037 // If the file name is a shortcut file, use the file it links to. |
15774
c4efa095f323
patch 8.1.0894: MS-Windows: resolve() does not return a reparse point
Bram Moolenaar <Bram@vim.org>
parents:
15740
diff
changeset
|
5038 rfname = mch_resolve_path(*ffname, FALSE); |
844 | 5039 if (rfname != NULL) |
7 | 5040 { |
5041 vim_free(*ffname); | |
5042 *ffname = rfname; | |
5043 *sfname = rfname; | |
5044 } | |
5045 } | |
5046 #endif | |
5047 } | |
5048 | |
5049 /* | |
5050 * Open a window for a number of buffers. | |
5051 */ | |
5052 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5053 ex_buffer_all(exarg_T *eap) |
7 | 5054 { |
5055 buf_T *buf; | |
5056 win_T *wp, *wpnext; | |
5057 int split_ret = OK; | |
5058 int p_ea_save; | |
5059 int open_wins = 0; | |
5060 int r; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5061 int count; // Maximum number of windows to open. |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5062 int all; // When TRUE also load inactive buffers. |
698 | 5063 int had_tab = cmdmod.tab; |
5064 tabpage_T *tpnext; | |
7 | 5065 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5066 if (eap->addr_count == 0) // make as many windows as possible |
7 | 5067 count = 9999; |
5068 else | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5069 count = eap->line2; // make as many windows as specified |
7 | 5070 if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) |
5071 all = FALSE; | |
5072 else | |
5073 all = TRUE; | |
5074 | |
5075 setpcmark(); | |
5076 | |
5077 #ifdef FEAT_GUI | |
5078 need_mouse_correct = TRUE; | |
5079 #endif | |
5080 | |
5081 /* | |
5082 * Close superfluous windows (two windows for the same buffer). | |
5083 * Also close windows that are not full-width. | |
5084 */ | |
698 | 5085 if (had_tab > 0) |
4354 | 5086 goto_tabpage_tp(first_tabpage, TRUE, TRUE); |
698 | 5087 for (;;) |
7 | 5088 { |
698 | 5089 tpnext = curtab->tp_next; |
5090 for (wp = firstwin; wp != NULL; wp = wpnext) | |
7 | 5091 { |
698 | 5092 wpnext = wp->w_next; |
706 | 5093 if ((wp->w_buffer->b_nwindows > 1 |
698 | 5094 || ((cmdmod.split & WSP_VERT) |
5095 ? wp->w_height + wp->w_status_height < Rows - p_ch | |
706 | 5096 - tabline_height() |
698 | 5097 : wp->w_width != Columns) |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
5098 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5099 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) |
698 | 5100 { |
5101 win_close(wp, FALSE); | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5102 wpnext = firstwin; // just in case an autocommand does |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5103 // something strange with windows |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5104 tpnext = first_tabpage; // start all over... |
698 | 5105 open_wins = 0; |
5106 } | |
5107 else | |
5108 ++open_wins; | |
7 | 5109 } |
698 | 5110 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5111 // Without the ":tab" modifier only do the current tab page. |
698 | 5112 if (had_tab == 0 || tpnext == NULL) |
5113 break; | |
4354 | 5114 goto_tabpage_tp(tpnext, TRUE, TRUE); |
7 | 5115 } |
5116 | |
5117 /* | |
5118 * Go through the buffer list. When a buffer doesn't have a window yet, | |
5119 * open one. Otherwise move the window to the right position. | |
5120 * Watch out for autocommands that delete buffers or windows! | |
5121 */ | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5122 // Don't execute Win/Buf Enter/Leave autocommands here. |
7 | 5123 ++autocmd_no_enter; |
5124 win_enter(lastwin, FALSE); | |
5125 ++autocmd_no_leave; | |
5126 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) | |
5127 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5128 // Check if this buffer needs a window |
7 | 5129 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) |
5130 continue; | |
5131 | |
701 | 5132 if (had_tab != 0) |
5133 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5134 // With the ":tab" modifier don't move the window. |
701 | 5135 if (buf->b_nwindows > 0) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5136 wp = lastwin; // buffer has a window, skip it |
701 | 5137 else |
5138 wp = NULL; | |
5139 } | |
5140 else | |
5141 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5142 // Check if this buffer already has a window |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9645
diff
changeset
|
5143 FOR_ALL_WINDOWS(wp) |
701 | 5144 if (wp->w_buffer == buf) |
5145 break; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5146 // If the buffer already has a window, move it |
701 | 5147 if (wp != NULL) |
5148 win_move_after(wp, curwin); | |
5149 } | |
5150 | |
5151 if (wp == NULL && split_ret == OK) | |
7 | 5152 { |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5153 bufref_T bufref; |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5154 |
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5155 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5156 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5157 // Split the window and put the buffer in it |
7 | 5158 p_ea_save = p_ea; |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5159 p_ea = TRUE; // use space from all windows |
7 | 5160 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); |
5161 ++open_wins; | |
5162 p_ea = p_ea_save; | |
5163 if (split_ret == FAIL) | |
5164 continue; | |
5165 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5166 // Open the buffer in this window. |
7 | 5167 swap_exists_action = SEA_DIALOG; |
5168 set_curbuf(buf, DOBUF_GOTO); | |
9475
4d8f7f8da90c
commit https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6
Christian Brabandt <cb@256bit.org>
parents:
9473
diff
changeset
|
5169 if (!bufref_valid(&bufref)) |
20 | 5170 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5171 // autocommands deleted the buffer!!! |
20 | 5172 swap_exists_action = SEA_NONE; |
7 | 5173 break; |
5174 } | |
5175 if (swap_exists_action == SEA_QUIT) | |
5176 { | |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5177 #if defined(FEAT_EVAL) |
24 | 5178 cleanup_T cs; |
5179 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5180 // Reset the error/interrupt/exception state here so that |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5181 // aborting() returns FALSE when closing a window. |
24 | 5182 enter_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5183 #endif |
24 | 5184 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5185 // User selected Quit at ATTENTION prompt; close this window. |
7 | 5186 win_close(curwin, TRUE); |
5187 --open_wins; | |
5188 swap_exists_action = SEA_NONE; | |
602 | 5189 swap_exists_did_quit = TRUE; |
24 | 5190 |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5191 #if defined(FEAT_EVAL) |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5192 // Restore the error/interrupt/exception state if not |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5193 // discarded by a new aborting error, interrupt, or uncaught |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5194 // exception. |
24 | 5195 leave_cleanup(&cs); |
16453
4e9bea9b8025
patch 8.1.1231: asking about existing swap file unnecessarily
Bram Moolenaar <Bram@vim.org>
parents:
16447
diff
changeset
|
5196 #endif |
7 | 5197 } |
5198 else | |
5199 handle_swap_exists(NULL); | |
5200 } | |
5201 | |
5202 ui_breakcheck(); | |
5203 if (got_int) | |
5204 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5205 (void)vgetc(); // only break the file loading, not the rest |
7 | 5206 break; |
5207 } | |
20 | 5208 #ifdef FEAT_EVAL |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5209 // Autocommands deleted the buffer or aborted script processing!!! |
20 | 5210 if (aborting()) |
5211 break; | |
5212 #endif | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5213 // When ":tab" was used open a new tab for a new window repeatedly. |
698 | 5214 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) |
5215 cmdmod.tab = 9999; | |
7 | 5216 } |
5217 --autocmd_no_enter; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5218 win_enter(firstwin, FALSE); // back to first window |
7 | 5219 --autocmd_no_leave; |
5220 | |
5221 /* | |
5222 * Close superfluous windows. | |
5223 */ | |
5224 for (wp = lastwin; open_wins > count; ) | |
5225 { | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11917
diff
changeset
|
5226 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) |
7 | 5227 || autowrite(wp->w_buffer, FALSE) == OK); |
5228 if (!win_valid(wp)) | |
5229 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5230 // BufWrite Autocommands made the window invalid, start over |
7 | 5231 wp = lastwin; |
5232 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5233 else if (r) |
7 | 5234 { |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11917
diff
changeset
|
5235 win_close(wp, !buf_hide(wp->w_buffer)); |
7 | 5236 --open_wins; |
5237 wp = lastwin; | |
5238 } | |
5239 else | |
5240 { | |
5241 wp = wp->w_prev; | |
5242 if (wp == NULL) | |
5243 break; | |
5244 } | |
5245 } | |
5246 } | |
5247 | |
5248 | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7687
diff
changeset
|
5249 static int chk_modeline(linenr_T, int); |
717 | 5250 |
7 | 5251 /* |
5252 * do_modelines() - process mode lines for the current file | |
5253 * | |
717 | 5254 * "flags" can be: |
5255 * OPT_WINONLY only set options local to window | |
5256 * OPT_NOWIN don't set options local to window | |
5257 * | |
7 | 5258 * Returns immediately if the "ml" option isn't set. |
5259 */ | |
5260 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5261 do_modelines(int flags) |
7 | 5262 { |
23 | 5263 linenr_T lnum; |
5264 int nmlines; | |
5265 static int entered = 0; | |
7 | 5266 |
5267 if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) | |
5268 return; | |
5269 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5270 // Disallow recursive entry here. Can happen when executing a modeline |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5271 // triggers an autocommand, which reloads modelines with a ":do". |
7 | 5272 if (entered) |
5273 return; | |
5274 | |
5275 ++entered; | |
5276 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines; | |
5277 ++lnum) | |
717 | 5278 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5279 nmlines = 0; |
5280 | |
5281 for (lnum = curbuf->b_ml.ml_line_count; lnum > 0 && lnum > nmlines | |
5282 && lnum > curbuf->b_ml.ml_line_count - nmlines; --lnum) | |
717 | 5283 if (chk_modeline(lnum, flags) == FAIL) |
7 | 5284 nmlines = 0; |
5285 --entered; | |
5286 } | |
5287 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5288 #include "version.h" // for version number |
7 | 5289 |
5290 /* | |
5291 * chk_modeline() - check a single line for a mode string | |
5292 * Return FAIL if an error encountered. | |
5293 */ | |
5294 static int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5295 chk_modeline( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5296 linenr_T lnum, |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5297 int flags) // Same as for do_modelines(). |
7 | 5298 { |
5299 char_u *s; | |
5300 char_u *e; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5301 char_u *linecopy; // local copy of any modeline found |
7 | 5302 int prev; |
5303 int vers; | |
5304 int end; | |
5305 int retval = OK; | |
5306 #ifdef FEAT_EVAL | |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14658
diff
changeset
|
5307 sctx_T save_current_sctx; |
7 | 5308 #endif |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
5309 ESTACK_CHECK_DECLARATION |
7 | 5310 |
5311 prev = -1; | |
5312 for (s = ml_get(lnum); *s != NUL; ++s) | |
5313 { | |
5314 if (prev == -1 || vim_isspace(prev)) | |
5315 { | |
5316 if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) | |
5317 || STRNCMP(s, "vi:", (size_t)3) == 0) | |
5318 break; | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5319 // Accept both "vim" and "Vim". |
5010
b614332f7df2
updated for version 7.3.1249
Bram Moolenaar <bram@vim.org>
parents:
4936
diff
changeset
|
5320 if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') |
7 | 5321 { |
5322 if (s[3] == '<' || s[3] == '=' || s[3] == '>') | |
5323 e = s + 4; | |
5324 else | |
5325 e = s + 3; | |
5326 vers = getdigits(&e); | |
5327 if (*e == ':' | |
5043
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5328 && (s[0] != 'V' |
53c1b30632df
updated for version 7.3.1265
Bram Moolenaar <bram@vim.org>
parents:
5010
diff
changeset
|
5329 || STRNCMP(skipwhite(e + 1), "set", 3) == 0) |
7 | 5330 && (s[3] == ':' |
5331 || (VIM_VERSION_100 >= vers && isdigit(s[3])) | |
5332 || (VIM_VERSION_100 < vers && s[3] == '<') | |
5333 || (VIM_VERSION_100 > vers && s[3] == '>') | |
5334 || (VIM_VERSION_100 == vers && s[3] == '='))) | |
5335 break; | |
5336 } | |
5337 } | |
5338 prev = *s; | |
5339 } | |
5340 | |
5341 if (*s) | |
5342 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5343 do // skip over "ex:", "vi:" or "vim:" |
7 | 5344 ++s; |
5345 while (s[-1] != ':'); | |
5346 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5347 s = linecopy = vim_strsave(s); // copy the line, it will change |
7 | 5348 if (linecopy == NULL) |
5349 return FAIL; | |
5350 | |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
5351 // prepare for emsg() |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
5352 estack_push(ETYPE_MODELINE, (char_u *)"modelines", lnum); |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
5353 ESTACK_CHECK_SETUP |
7 | 5354 |
5355 end = FALSE; | |
5356 while (end == FALSE) | |
5357 { | |
5358 s = skipwhite(s); | |
5359 if (*s == NUL) | |
5360 break; | |
5361 | |
5362 /* | |
5363 * Find end of set command: ':' or end of line. | |
5364 * Skip over "\:", replacing it with ":". | |
5365 */ | |
5366 for (e = s; *e != ':' && *e != NUL; ++e) | |
5367 if (e[0] == '\\' && e[1] == ':') | |
1618 | 5368 STRMOVE(e, e + 1); |
7 | 5369 if (*e == NUL) |
5370 end = TRUE; | |
5371 | |
5372 /* | |
5373 * If there is a "set" command, require a terminating ':' and | |
5374 * ignore the stuff after the ':'. | |
5375 * "vi:set opt opt opt: foo" -- foo not interpreted | |
5376 * "vi:opt opt opt: foo" -- foo interpreted | |
5377 * Accept "se" for compatibility with Elvis. | |
5378 */ | |
5379 if (STRNCMP(s, "set ", (size_t)4) == 0 | |
5380 || STRNCMP(s, "se ", (size_t)3) == 0) | |
5381 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5382 if (*e != ':') // no terminating ':'? |
7 | 5383 break; |
5384 end = TRUE; | |
5385 s = vim_strchr(s, ' ') + 1; | |
5386 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5387 *e = NUL; // truncate the set command |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5388 |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5389 if (*s != NUL) // skip over an empty "::" |
7 | 5390 { |
15207
6ab9c18708c4
patch 8.1.0613: when executing an insecure function the secure flag is stuck
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
5391 int secure_save = secure; |
7 | 5392 #ifdef FEAT_EVAL |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14658
diff
changeset
|
5393 save_current_sctx = current_sctx; |
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14658
diff
changeset
|
5394 current_sctx.sc_sid = SID_MODELINE; |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
14917
diff
changeset
|
5395 current_sctx.sc_seq = 0; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
5396 current_sctx.sc_lnum = lnum; |
16223
abb67309c1ca
patch 8.1.1116: cannot enforce a Vim script style
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
5397 current_sctx.sc_version = 1; |
7 | 5398 #endif |
15054
2d6e930c7613
patch 8.1.0538: evaluating a modeline might invoke using a shell command
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
5399 // Make sure no risky things are executed as a side effect. |
16082
2699db3e4d9d
patch 8.1.1046: the "secure" variable is used inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
5400 secure = 1; |
15054
2d6e930c7613
patch 8.1.0538: evaluating a modeline might invoke using a shell command
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
5401 |
717 | 5402 retval = do_set(s, OPT_MODELINE | OPT_LOCAL | flags); |
15054
2d6e930c7613
patch 8.1.0538: evaluating a modeline might invoke using a shell command
Bram Moolenaar <Bram@vim.org>
parents:
15008
diff
changeset
|
5403 |
15207
6ab9c18708c4
patch 8.1.0613: when executing an insecure function the secure flag is stuck
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
5404 secure = secure_save; |
7 | 5405 #ifdef FEAT_EVAL |
14700
0a3b9ecf7cb8
patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents:
14658
diff
changeset
|
5406 current_sctx = save_current_sctx; |
7 | 5407 #endif |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5408 if (retval == FAIL) // stop if error found |
7 | 5409 break; |
5410 } | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5411 s = e + 1; // advance to next part |
7 | 5412 } |
5413 | |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19044
diff
changeset
|
5414 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18987
diff
changeset
|
5415 estack_pop(); |
7 | 5416 vim_free(linecopy); |
5417 } | |
5418 return retval; | |
5419 } | |
5420 | |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5421 /* |
14433
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5422 * Return TRUE if "buf" is a normal buffer, 'buftype' is empty. |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5423 */ |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5424 int |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5425 bt_normal(buf_T *buf) |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5426 { |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5427 return buf != NULL && buf->b_p_bt[0] == NUL; |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5428 } |
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5429 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5430 #if defined(FEAT_QUICKFIX) || defined(PROTO) |
14433
4a94173743d9
patch 8.1.0230: directly checking 'buftype' value
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
5431 /* |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5432 * Return TRUE if "buf" is the quickfix buffer. |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5433 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5434 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5435 bt_quickfix(buf_T *buf) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5436 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5437 return buf != NULL && buf->b_p_bt[0] == 'q'; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5438 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5439 #endif |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5440 |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5441 #if defined(FEAT_TERMINAL) || defined(PROTO) |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5442 /* |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5443 * Return TRUE if "buf" is a terminal buffer. |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5444 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5445 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5446 bt_terminal(buf_T *buf) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5447 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5448 return buf != NULL && buf->b_p_bt[0] == 't'; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5449 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5450 #endif |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5451 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5452 /* |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5453 * Return TRUE if "buf" is a help buffer. |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5454 */ |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5455 int |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5456 bt_help(buf_T *buf) |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5457 { |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5458 return buf != NULL && buf->b_help; |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5459 } |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5460 |
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11788
diff
changeset
|
5461 /* |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5462 * Return TRUE if "buf" is a prompt buffer. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5463 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5464 int |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5465 bt_prompt(buf_T *buf) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5466 { |
16778
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5467 return buf != NULL && buf->b_p_bt[0] == 'p' && buf->b_p_bt[1] == 'r'; |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5468 } |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5469 |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5470 /* |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5471 * Return TRUE if "buf" is a buffer for a popup window. |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5472 */ |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5473 int |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5474 bt_popup(buf_T *buf) |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5475 { |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5476 return buf != NULL && buf->b_p_bt != NULL |
eda4d65f232c
patch 8.1.1391: no popup window support
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
5477 && buf->b_p_bt[0] == 'p' && buf->b_p_bt[1] == 'o'; |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5478 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5479 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5480 /* |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5481 * Return TRUE if "buf" is a "nofile", "acwrite", "terminal" or "prompt" |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5482 * buffer. This means the buffer name is not a file name. |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5483 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5484 int |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5485 bt_nofilename(buf_T *buf) |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5486 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5487 return buf != NULL && ((buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f') |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5488 || buf->b_p_bt[0] == 'a' |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5489 || buf->b_p_bt[0] == 't' |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5490 || buf->b_p_bt[0] == 'p'); |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5491 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5492 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5493 /* |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5494 * Return TRUE if "buf" has 'buftype' set to "nofile". |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5495 */ |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5496 int |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5497 bt_nofile(buf_T *buf) |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5498 { |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5499 return buf != NULL && buf->b_p_bt[0] == 'n' && buf->b_p_bt[2] == 'f'; |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5500 } |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5501 |
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5502 /* |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5503 * Return TRUE if "buf" is a "nowrite", "nofile", "terminal" or "prompt" |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14087
diff
changeset
|
5504 * buffer. |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5505 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5506 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5507 bt_dontwrite(buf_T *buf) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5508 { |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5509 return buf != NULL && (buf->b_p_bt[0] == 'n' |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5510 || buf->b_p_bt[0] == 't' |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
13931
diff
changeset
|
5511 || buf->b_p_bt[0] == 'p'); |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5512 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5513 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5514 #if defined(FEAT_QUICKFIX) || defined(PROTO) |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5515 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5516 bt_dontwrite_msg(buf_T *buf) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5517 { |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5518 if (bt_dontwrite(buf)) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5519 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15330
diff
changeset
|
5520 emsg(_("E382: Cannot write, 'buftype' option is set")); |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5521 return TRUE; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5522 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5523 return FALSE; |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5524 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5525 #endif |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5526 |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5527 /* |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5528 * Return TRUE if the buffer should be hidden, according to 'hidden', ":hide" |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5529 * and 'bufhidden'. |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5530 */ |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5531 int |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5532 buf_hide(buf_T *buf) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5533 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5534 // 'bufhidden' overrules 'hidden' and ":hide", check it first |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5535 switch (buf->b_p_bh[0]) |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5536 { |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5537 case 'u': // "unload" |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5538 case 'w': // "wipe" |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5539 case 'd': return FALSE; // "delete" |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5540 case 'h': return TRUE; // "hide" |
11788
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5541 } |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5542 return (p_hid || cmdmod.hide); |
77bf0346687e
patch 8.0.0776: function prototypes missing without the quickfix feature
Christian Brabandt <cb@256bit.org>
parents:
11772
diff
changeset
|
5543 } |
7 | 5544 |
5545 /* | |
5546 * Return special buffer name. | |
5547 * Returns NULL when the buffer has a normal file name. | |
5548 */ | |
3839 | 5549 char_u * |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5550 buf_spname(buf_T *buf) |
7 | 5551 { |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12387
diff
changeset
|
5552 #if defined(FEAT_QUICKFIX) |
7 | 5553 if (bt_quickfix(buf)) |
643 | 5554 { |
5555 /* | |
15740
2fe4a503c5ad
patch 8.1.0877: new buffer used every time the quickfix window is opened
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
5556 * Differentiate between the quickfix and location list buffers using |
2fe4a503c5ad
patch 8.1.0877: new buffer used every time the quickfix window is opened
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
5557 * the buffer number stored in the global quickfix stack. |
643 | 5558 */ |
15740
2fe4a503c5ad
patch 8.1.0877: new buffer used every time the quickfix window is opened
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
5559 if (buf->b_fnum == qf_stack_get_bufnr()) |
2fe4a503c5ad
patch 8.1.0877: new buffer used every time the quickfix window is opened
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
5560 return (char_u *)_(msg_qflist); |
2fe4a503c5ad
patch 8.1.0877: new buffer used every time the quickfix window is opened
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
5561 else |
3839 | 5562 return (char_u *)_(msg_loclist); |
643 | 5563 } |
7 | 5564 #endif |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5565 |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5566 // There is no _file_ when 'buftype' is "nofile", b_sfname |
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5567 // contains the name as specified by the user. |
17095
10e0d7d96cb0
patch 8.1.1547: functionality of bt_nofile() is confusing
Bram Moolenaar <Bram@vim.org>
parents:
16996
diff
changeset
|
5568 if (bt_nofilename(buf)) |
7 | 5569 { |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5570 #ifdef FEAT_TERMINAL |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5571 if (buf->b_term != NULL) |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5572 return term_get_status_text(buf->b_term); |
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5573 #endif |
12267
e3bde71afff0
patch 8.0.1013: terminal window behaves different from a buffer with changes
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
5574 if (buf->b_fname != NULL) |
e3bde71afff0
patch 8.0.1013: terminal window behaves different from a buffer with changes
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
5575 return buf->b_fname; |
14037
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
5576 #ifdef FEAT_JOB_CHANNEL |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
5577 if (bt_prompt(buf)) |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
5578 return (char_u *)_("[Prompt]"); |
afce2005fdc8
patch 8.1.0036: not restoring Insert mode if leaving prompt buffer with mouse
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
5579 #endif |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18757
diff
changeset
|
5580 #ifdef FEAT_PROP_POPUP |
16859
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5581 if (bt_popup(buf)) |
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5582 return (char_u *)_("[Popup]"); |
0154363d3b98
patch 8.1.1431: popup window listed as "Scratch"
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
5583 #endif |
3839 | 5584 return (char_u *)_("[Scratch]"); |
7 | 5585 } |
11772
f33b9375ba03
patch 8.0.0768: terminal window status shows "[Scratch]"
Christian Brabandt <cb@256bit.org>
parents:
11757
diff
changeset
|
5586 |
7 | 5587 if (buf->b_fname == NULL) |
3839 | 5588 return (char_u *)_("[No Name]"); |
7 | 5589 return NULL; |
5590 } | |
5591 | |
5592 /* | |
5593 * Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed. | |
5594 */ | |
5595 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5596 set_buflisted(int on) |
7 | 5597 { |
5598 if (on != curbuf->b_p_bl) | |
5599 { | |
5600 curbuf->b_p_bl = on; | |
5601 if (on) | |
5602 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); | |
5603 else | |
5604 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | |
5605 } | |
5606 } | |
5607 | |
5608 /* | |
5609 * Read the file for "buf" again and check if the contents changed. | |
5610 * Return TRUE if it changed or this could not be checked. | |
5611 */ | |
5612 int | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5613 buf_contents_changed(buf_T *buf) |
7 | 5614 { |
5615 buf_T *newbuf; | |
5616 int differ = TRUE; | |
5617 linenr_T lnum; | |
5618 aco_save_T aco; | |
5619 exarg_T ea; | |
5620 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5621 // Allocate a buffer without putting it in the buffer list. |
7 | 5622 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); |
5623 if (newbuf == NULL) | |
5624 return TRUE; | |
5625 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5626 // Force the 'fileencoding' and 'fileformat' to be equal. |
7 | 5627 if (prep_exarg(&ea, buf) == FAIL) |
5628 { | |
5629 wipe_buffer(newbuf, FALSE); | |
5630 return TRUE; | |
5631 } | |
5632 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5633 // set curwin/curbuf to buf and save a few things |
7 | 5634 aucmd_prepbuf(&aco, newbuf); |
5635 | |
625 | 5636 if (ml_open(curbuf) == OK |
7 | 5637 && readfile(buf->b_ffname, buf->b_fname, |
5638 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, | |
5639 &ea, READ_NEW | READ_DUMMY) == OK) | |
5640 { | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5641 // compare the two files line by line |
7 | 5642 if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) |
5643 { | |
5644 differ = FALSE; | |
5645 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
5646 if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) | |
5647 { | |
5648 differ = TRUE; | |
5649 break; | |
5650 } | |
5651 } | |
5652 } | |
5653 vim_free(ea.cmd); | |
5654 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5655 // restore curwin/curbuf and a few other things |
7 | 5656 aucmd_restbuf(&aco); |
5657 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5658 if (curbuf != newbuf) // safety check |
7 | 5659 wipe_buffer(newbuf, FALSE); |
5660 | |
5661 return differ; | |
5662 } | |
5663 | |
5664 /* | |
5665 * Wipe out a buffer and decrement the last buffer number if it was used for | |
5666 * this buffer. Call this to wipe out a temp buffer that does not contain any | |
5667 * marks. | |
5668 */ | |
5669 void | |
7817
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5670 wipe_buffer( |
83861277e6a3
commit https://github.com/vim/vim/commit/7454a06e2642d2b37afad1c5e71cec68081ca4ff
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5671 buf_T *buf, |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
5672 int aucmd) // When TRUE trigger autocommands. |
7 | 5673 { |
5674 if (buf->b_fnum == top_file_num - 1) | |
5675 --top_file_num; | |
5676 | |
18757
c469e1930456
patch 8.1.2368: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18746
diff
changeset
|
5677 if (!aucmd) // Don't trigger BufDelete autocommands here. |
1410 | 5678 block_autocmds(); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5679 |
18886
050f5eaa9e50
patch 8.2.0004: get E685 and E931 if buffer reload is interrupted
Bram Moolenaar <Bram@vim.org>
parents:
18864
diff
changeset
|
5680 close_buffer(NULL, buf, DOBUF_WIPE, FALSE, TRUE); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
5681 |
7 | 5682 if (!aucmd) |
1410 | 5683 unblock_autocmds(); |
7 | 5684 } |